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

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