Blame SOURCES/00166-fix-fake-repr-in-gdb-hooks.patch

6e8c2f
diff -up Python-2.7.3/Tools/gdb/libpython.py.fix-fake-repr-in-gdb-hooks Python-2.7.3/Tools/gdb/libpython.py
6e8c2f
--- Python-2.7.3/Tools/gdb/libpython.py.fix-fake-repr-in-gdb-hooks	2013-02-19 17:21:33.541181366 -0500
6e8c2f
+++ Python-2.7.3/Tools/gdb/libpython.py	2013-02-19 17:21:42.090180782 -0500
6e8c2f
@@ -105,6 +105,24 @@ class TruncatedStringIO(object):
6e8c2f
     def getvalue(self):
6e8c2f
         return self._val
6e8c2f
 
6e8c2f
+class FakeProxy(object):
6e8c2f
+    """
6e8c2f
+    Class representing a non-descript PyObject* value in the inferior
6e8c2f
+    process for when we don't have a custom scraper, intended to have
6e8c2f
+    a sane repr().
6e8c2f
+    """
6e8c2f
+    def __init__(self, tp_name, address):
6e8c2f
+        self.tp_name = tp_name
6e8c2f
+        self.address = address
6e8c2f
+
6e8c2f
+    def __repr__(self):
6e8c2f
+        # For the NULL pointer, we have no way of knowing a type, so
6e8c2f
+        # special-case it as per
6e8c2f
+        # http://bugs.python.org/issue8032#msg100882
6e8c2f
+        if self.address == 0:
6e8c2f
+            return '0x0'
6e8c2f
+        return '<%s at remote 0x%x>' % (self.tp_name, self.address)
6e8c2f
+
6e8c2f
 class PyObjectPtr(object):
6e8c2f
     """
6e8c2f
     Class wrapping a gdb.Value that's a either a (PyObject*) within the
6e8c2f
@@ -232,28 +250,8 @@ class PyObjectPtr(object):
6e8c2f
         visiting object graphs with loops).  Analogous to Py_ReprEnter and
6e8c2f
         Py_ReprLeave
6e8c2f
         '''
6e8c2f
-
6e8c2f
-        class FakeRepr(object):
6e8c2f
-            """
6e8c2f
-            Class representing a non-descript PyObject* value in the inferior
6e8c2f
-            process for when we don't have a custom scraper, intended to have
6e8c2f
-            a sane repr().
6e8c2f
-            """
6e8c2f
-
6e8c2f
-            def __init__(self, tp_name, address):
6e8c2f
-                self.tp_name = tp_name
6e8c2f
-                self.address = address
6e8c2f
-
6e8c2f
-            def __repr__(self):
6e8c2f
-                # For the NULL pointer, we have no way of knowing a type, so
6e8c2f
-                # special-case it as per
6e8c2f
-                # http://bugs.python.org/issue8032#msg100882
6e8c2f
-                if self.address == 0:
6e8c2f
-                    return '0x0'
6e8c2f
-                return '<%s at remote 0x%x>' % (self.tp_name, self.address)
6e8c2f
-
6e8c2f
-        return FakeRepr(self.safe_tp_name(),
6e8c2f
-                        long(self._gdbval))
6e8c2f
+        return FakeProxy(self.safe_tp_name(),
6e8c2f
+                         long(self._gdbval))
6e8c2f
 
6e8c2f
     def write_repr(self, out, visited):
6e8c2f
         '''
6e8c2f
@@ -384,7 +382,7 @@ def _write_instance_repr(out, visited, n
6e8c2f
             if not first:
6e8c2f
                 out.write(', ')
6e8c2f
             first = False
6e8c2f
-            out.write(pyop_arg.proxyval(visited))
6e8c2f
+            out.write(str(pyop_arg.proxyval(visited)))
6e8c2f
             out.write('=')
6e8c2f
             pyop_val.write_repr(out, visited)
6e8c2f
         out.write(')')
6e8c2f
@@ -785,6 +783,8 @@ class PyNoneStructPtr(PyObjectPtr):
6e8c2f
     def proxyval(self, visited):
6e8c2f
         return None
6e8c2f
 
6e8c2f
+class CantReadFilename(ValueError):
6e8c2f
+    pass
6e8c2f
 
6e8c2f
 class PyFrameObjectPtr(PyObjectPtr):
6e8c2f
     _typename = 'PyFrameObject'
6e8c2f
@@ -861,7 +861,10 @@ class PyFrameObjectPtr(PyObjectPtr):
6e8c2f
         '''Get the path of the current Python source file, as a string'''
6e8c2f
         if self.is_optimized_out():
6e8c2f
             return '(frame information optimized out)'
6e8c2f
-        return self.co_filename.proxyval(set())
6e8c2f
+        value = self.co_filename.proxyval(set())
6e8c2f
+        if isinstance(value, FakeProxy):
6e8c2f
+            raise CantReadFilename('unable to extract filename)')
6e8c2f
+        return value
6e8c2f
 
6e8c2f
     def current_line_num(self):
6e8c2f
         '''Get current line number as an integer (1-based)
6e8c2f
@@ -907,7 +910,7 @@ class PyFrameObjectPtr(PyObjectPtr):
6e8c2f
                 out.write(', ')
6e8c2f
             first = False
6e8c2f
 
6e8c2f
-            out.write(pyop_name.proxyval(visited))
6e8c2f
+            out.write(str(pyop_name.proxyval(visited)))
6e8c2f
             out.write('=')
6e8c2f
             pyop_value.write_repr(out, visited)
6e8c2f
 
6e8c2f
@@ -1252,8 +1255,11 @@ class Frame(object):
6e8c2f
             if pyop:
6e8c2f
                 sys.stdout.write('#%i %s\n' % (self.get_index(), pyop.get_truncated_repr(MAX_OUTPUT_LEN)))
6e8c2f
                 if not pyop.is_optimized_out():
6e8c2f
-                    line = pyop.current_line()
6e8c2f
-                    sys.stdout.write('    %s\n' % line.strip())
6e8c2f
+                    try:
6e8c2f
+                        line = pyop.current_line()
6e8c2f
+                        sys.stdout.write('    %s\n' % line.strip())
6e8c2f
+                    except CantReadFilename:
6e8c2f
+                        sys.stdout.write('    %s\n' % '(unable to read filename)')
6e8c2f
             else:
6e8c2f
                 sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
6e8c2f
         else:
6e8c2f
@@ -1303,7 +1309,11 @@ class PyList(gdb.Command):
6e8c2f
             print 'Unable to read information on python frame'
6e8c2f
             return
6e8c2f
 
6e8c2f
-        filename = pyop.filename()
6e8c2f
+        try:
6e8c2f
+            filename = pyop.filename()
6e8c2f
+        except CantReadFilename:
6e8c2f
+            print "Unable to extract filename from python frame"
6e8c2f
+            return
6e8c2f
         lineno = pyop.current_line_num()
6e8c2f
 
6e8c2f
         if start is None: