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

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