An interpreted, interactive, object-oriented programming language
CentOS Sources
2017-08-01 71084d584ff953f5463757ec6536406320560b4d
commit | author | age
6e8c2f 1 diff -up Python-2.7.3/Tools/gdb/libpython.py.fix-fake-repr-in-gdb-hooks Python-2.7.3/Tools/gdb/libpython.py
CB 2 --- Python-2.7.3/Tools/gdb/libpython.py.fix-fake-repr-in-gdb-hooks    2013-02-19 17:21:33.541181366 -0500
3 +++ Python-2.7.3/Tools/gdb/libpython.py    2013-02-19 17:21:42.090180782 -0500
4 @@ -105,6 +105,24 @@ class TruncatedStringIO(object):
5      def getvalue(self):
6          return self._val
7  
8 +class FakeProxy(object):
9 +    """
10 +    Class representing a non-descript PyObject* value in the inferior
11 +    process for when we don't have a custom scraper, intended to have
12 +    a sane repr().
13 +    """
14 +    def __init__(self, tp_name, address):
15 +        self.tp_name = tp_name
16 +        self.address = address
17 +
18 +    def __repr__(self):
19 +        # For the NULL pointer, we have no way of knowing a type, so
20 +        # special-case it as per
21 +        # http://bugs.python.org/issue8032#msg100882
22 +        if self.address == 0:
23 +            return '0x0'
24 +        return '<%s at remote 0x%x>' % (self.tp_name, self.address)
25 +
26  class PyObjectPtr(object):
27      """
28      Class wrapping a gdb.Value that's a either a (PyObject*) within the
29 @@ -232,28 +250,8 @@ class PyObjectPtr(object):
30          visiting object graphs with loops).  Analogous to Py_ReprEnter and
31          Py_ReprLeave
32          '''
33 -
34 -        class FakeRepr(object):
35 -            """
36 -            Class representing a non-descript PyObject* value in the inferior
37 -            process for when we don't have a custom scraper, intended to have
38 -            a sane repr().
39 -            """
40 -
41 -            def __init__(self, tp_name, address):
42 -                self.tp_name = tp_name
43 -                self.address = address
44 -
45 -            def __repr__(self):
46 -                # For the NULL pointer, we have no way of knowing a type, so
47 -                # special-case it as per
48 -                # http://bugs.python.org/issue8032#msg100882
49 -                if self.address == 0:
50 -                    return '0x0'
51 -                return '<%s at remote 0x%x>' % (self.tp_name, self.address)
52 -
53 -        return FakeRepr(self.safe_tp_name(),
54 -                        long(self._gdbval))
55 +        return FakeProxy(self.safe_tp_name(),
56 +                         long(self._gdbval))
57  
58      def write_repr(self, out, visited):
59          '''
60 @@ -384,7 +382,7 @@ def _write_instance_repr(out, visited, n
61              if not first:
62                  out.write(', ')
63              first = False
64 -            out.write(pyop_arg.proxyval(visited))
65 +            out.write(str(pyop_arg.proxyval(visited)))
66              out.write('=')
67              pyop_val.write_repr(out, visited)
68          out.write(')')
69 @@ -785,6 +783,8 @@ class PyNoneStructPtr(PyObjectPtr):
70      def proxyval(self, visited):
71          return None
72  
73 +class CantReadFilename(ValueError):
74 +    pass
75  
76  class PyFrameObjectPtr(PyObjectPtr):
77      _typename = 'PyFrameObject'
78 @@ -861,7 +861,10 @@ class PyFrameObjectPtr(PyObjectPtr):
79          '''Get the path of the current Python source file, as a string'''
80          if self.is_optimized_out():
81              return '(frame information optimized out)'
82 -        return self.co_filename.proxyval(set())
83 +        value = self.co_filename.proxyval(set())
84 +        if isinstance(value, FakeProxy):
85 +            raise CantReadFilename('unable to extract filename)')
86 +        return value
87  
88      def current_line_num(self):
89          '''Get current line number as an integer (1-based)
90 @@ -907,7 +910,7 @@ class PyFrameObjectPtr(PyObjectPtr):
91                  out.write(', ')
92              first = False
93  
94 -            out.write(pyop_name.proxyval(visited))
95 +            out.write(str(pyop_name.proxyval(visited)))
96              out.write('=')
97              pyop_value.write_repr(out, visited)
98  
99 @@ -1252,8 +1255,11 @@ class Frame(object):
100              if pyop:
101                  sys.stdout.write('#%i %s\n' % (self.get_index(), pyop.get_truncated_repr(MAX_OUTPUT_LEN)))
102                  if not pyop.is_optimized_out():
103 -                    line = pyop.current_line()
104 -                    sys.stdout.write('    %s\n' % line.strip())
105 +                    try:
106 +                        line = pyop.current_line()
107 +                        sys.stdout.write('    %s\n' % line.strip())
108 +                    except CantReadFilename:
109 +                        sys.stdout.write('    %s\n' % '(unable to read filename)')
110              else:
111                  sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
112          else:
113 @@ -1303,7 +1309,11 @@ class PyList(gdb.Command):
114              print 'Unable to read information on python frame'
115              return
116  
117 -        filename = pyop.filename()
118 +        try:
119 +            filename = pyop.filename()
120 +        except CantReadFilename:
121 +            print "Unable to extract filename from python frame"
122 +            return
123          lineno = pyop.current_line_num()
124  
125          if start is None: