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

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