annotate Tools/gdb/libpython.py @ 74078:1cc8e9565339 2.7

Issue #13628: python-gdb.py is now able to retrieve more frames in the Python traceback if Python is optimized. * delay the lookup of the size_t type, it is not available at startup * The second argument of the PyFrameObjectPtr constructor is optional, as done in other constructors * iter_builtins() and iter_globals() methods of PyFrameObjectPtr returns an empty tuple instead of None if Python is optimized * Fix py-bt to handle correctly "optimized" frames * Frame.get_pyop() tries to get the frame pointer from PyEval_EvalCodeEx() if the pointer is optimized out in PyEval_EvalFrameEx()
author Victor Stinner <victor.stinner@haypocalc.com>
date Mon, 19 Dec 2011 13:59:58 +0100
parents 1322266f9611
children 33b156e118c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 #!/usr/bin/python
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
4 to be extended with Python code e.g. for library-specific data visualizations,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
5 such as for the C++ STL types. Documentation on this API can be seen at:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
6 http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
7
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
9 This python module deals with the case when the process being debugged (the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
10 "inferior process" in gdb parlance) is itself python, or more specifically,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
11 linked against libpython. In this situation, almost every item of data is a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12 (PyObject*), and having the debugger merely print their addresses is not very
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
13 enlightening.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
14
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
15 This module embeds knowledge about the implementation details of libpython so
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16 that we can emit useful visualizations e.g. a string, a list, a dict, a frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
17 giving file/line information and the state of local variables
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
18
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 In particular, given a gdb.Value corresponding to a PyObject* in the inferior
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
20 process, we can generate a "proxy value" within the gdb process. For example,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
21 given a PyObject* in the inferior process that is in fact a PyListObject*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22 holding three PyObject* that turn out to be PyStringObject* instances, we can
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
23 generate a proxy value within the gdb process that is a list of strings:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
24 ["foo", "bar", "baz"]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
26 Doing so can be expensive for complicated graphs of objects, and could take
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 some time, so we also have a "write_repr" method that writes a representation
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
28 of the data to a file-like object. This allows us to stop the traversal by
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 having the file-like object raise an exception if it gets too much data.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
30
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
31 With both "proxyval" and "write_repr" we keep track of the set of all addresses
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
32 visited so far in the traversal, to avoid infinite recursion due to cycles in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
33 the graph of object references.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
35 We try to defer gdb.lookup_type() invocations for python types until as late as
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
36 possible: for a dynamically linked python binary, when the process starts in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
37 the debugger, the libpython.so hasn't been dynamically loaded yet, so none of
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
38 the type names are known to the debugger
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
39
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
40 The module also extends gdb with some python-specific commands.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
41 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
42 from __future__ import with_statement
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
43 import gdb
63014
18bdc43ce5ed Merged revisions 82872,82874 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61770
diff changeset
44 import sys
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
45
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
46 # Look up the gdb.Type for some standard types:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
47 _type_char_ptr = gdb.lookup_type('char').pointer() # char*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
48 _type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
49 _type_void_ptr = gdb.lookup_type('void').pointer() # void*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
50
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
51 SIZEOF_VOID_P = _type_void_ptr.sizeof
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
52
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
53
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
54 Py_TPFLAGS_HEAPTYPE = (1L << 9)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
55
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
56 Py_TPFLAGS_INT_SUBCLASS = (1L << 23)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
57 Py_TPFLAGS_LONG_SUBCLASS = (1L << 24)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
58 Py_TPFLAGS_LIST_SUBCLASS = (1L << 25)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
59 Py_TPFLAGS_TUPLE_SUBCLASS = (1L << 26)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
60 Py_TPFLAGS_STRING_SUBCLASS = (1L << 27)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
61 Py_TPFLAGS_UNICODE_SUBCLASS = (1L << 28)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
62 Py_TPFLAGS_DICT_SUBCLASS = (1L << 29)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
63 Py_TPFLAGS_BASE_EXC_SUBCLASS = (1L << 30)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
64 Py_TPFLAGS_TYPE_SUBCLASS = (1L << 31)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
65
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
66
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
67 MAX_OUTPUT_LEN=1024
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
68
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
69 class NullPyObjectPtr(RuntimeError):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
70 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
71
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
72
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
73 def safety_limit(val):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
74 # Given a integer value from the process being debugged, limit it to some
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
75 # safety threshold so that arbitrary breakage within said process doesn't
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
76 # break the gdb process too much (e.g. sizes of iterations, sizes of lists)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
77 return min(val, 1000)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
78
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
79
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
80 def safe_range(val):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
81 # As per range, but don't trust the value too much: cap it to a safety
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
82 # threshold in case the data was corrupted
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
83 return xrange(safety_limit(val))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
84
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
85
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
86 class StringTruncated(RuntimeError):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
87 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
88
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
89 class TruncatedStringIO(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
90 '''Similar to cStringIO, but can truncate the output by raising a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
91 StringTruncated exception'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
92 def __init__(self, maxlen=None):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
93 self._val = ''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
94 self.maxlen = maxlen
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
95
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
96 def write(self, data):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
97 if self.maxlen:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
98 if len(data) + len(self._val) > self.maxlen:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
99 # Truncation:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
100 self._val += data[0:self.maxlen - len(self._val)]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
101 raise StringTruncated()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
102
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
103 self._val += data
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
104
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
105 def getvalue(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
106 return self._val
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
107
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
108 class PyObjectPtr(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
109 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
110 Class wrapping a gdb.Value that's a either a (PyObject*) within the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
111 inferior process, or some subclass pointer e.g. (PyStringObject*)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
112
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
113 There will be a subclass for every refined PyObject type that we care
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
114 about.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
115
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
116 Note that at every stage the underlying pointer could be NULL, point
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
117 to corrupt data, etc; this is the debugger, after all.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
118 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
119 _typename = 'PyObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
120
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
121 def __init__(self, gdbval, cast_to=None):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
122 if cast_to:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
123 self._gdbval = gdbval.cast(cast_to)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
124 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
125 self._gdbval = gdbval
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
126
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
127 def field(self, name):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
128 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
129 Get the gdb.Value for the given field within the PyObject, coping with
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
130 some python 2 versus python 3 differences.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
131
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
132 Various libpython types are defined using the "PyObject_HEAD" and
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
133 "PyObject_VAR_HEAD" macros.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
134
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
135 In Python 2, this these are defined so that "ob_type" and (for a var
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
136 object) "ob_size" are fields of the type in question.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
137
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
138 In Python 3, this is defined as an embedded PyVarObject type thus:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
139 PyVarObject ob_base;
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
140 so that the "ob_size" field is located insize the "ob_base" field, and
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
141 the "ob_type" is most easily accessed by casting back to a (PyObject*).
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
142 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
143 if self.is_null():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
144 raise NullPyObjectPtr(self)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
145
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
146 if name == 'ob_type':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
147 pyo_ptr = self._gdbval.cast(PyObjectPtr.get_gdb_type())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
148 return pyo_ptr.dereference()[name]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
149
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
150 if name == 'ob_size':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
151 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
152 # Python 2:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
153 return self._gdbval.dereference()[name]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
154 except RuntimeError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
155 # Python 3:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
156 return self._gdbval.dereference()['ob_base'][name]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
157
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
158 # General case: look it up inside the object:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
159 return self._gdbval.dereference()[name]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
160
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
161 def pyop_field(self, name):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
162 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
163 Get a PyObjectPtr for the given PyObject* field within this PyObject,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
164 coping with some python 2 versus python 3 differences.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
165 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
166 return PyObjectPtr.from_pyobject_ptr(self.field(name))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
167
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
168 def write_field_repr(self, name, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
169 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
170 Extract the PyObject* field named "name", and write its representation
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
171 to file-like object "out"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
172 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
173 field_obj = self.pyop_field(name)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
174 field_obj.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
175
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
176 def get_truncated_repr(self, maxlen):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
177 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
178 Get a repr-like string for the data, but truncate it at "maxlen" bytes
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
179 (ending the object graph traversal as soon as you do)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
180 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
181 out = TruncatedStringIO(maxlen)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
182 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
183 self.write_repr(out, set())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
184 except StringTruncated:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
185 # Truncation occurred:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
186 return out.getvalue() + '...(truncated)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
187
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
188 # No truncation occurred:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
189 return out.getvalue()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
190
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
191 def type(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
192 return PyTypeObjectPtr(self.field('ob_type'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
193
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
194 def is_null(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
195 return 0 == long(self._gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
196
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
197 def is_optimized_out(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
198 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
199 Is the value of the underlying PyObject* visible to the debugger?
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
200
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
201 This can vary with the precise version of the compiler used to build
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
202 Python, and the precise version of gdb.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
203
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
204 See e.g. https://bugzilla.redhat.com/show_bug.cgi?id=556975 with
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
205 PyEval_EvalFrameEx's "f"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
206 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
207 return self._gdbval.is_optimized_out
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
208
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
209 def safe_tp_name(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
210 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
211 return self.type().field('tp_name').string()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
212 except NullPyObjectPtr:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
213 # NULL tp_name?
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
214 return 'unknown'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
215 except RuntimeError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
216 # Can't even read the object at all?
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
217 return 'unknown'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
218
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
219 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
220 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
221 Scrape a value from the inferior process, and try to represent it
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
222 within the gdb process, whilst (hopefully) avoiding crashes when
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
223 the remote data is corrupt.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
224
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
225 Derived classes will override this.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
226
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
227 For example, a PyIntObject* with ob_ival 42 in the inferior process
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
228 should result in an int(42) in this process.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
229
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
230 visited: a set of all gdb.Value pyobject pointers already visited
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
231 whilst generating this value (to guard against infinite recursion when
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
232 visiting object graphs with loops). Analogous to Py_ReprEnter and
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
233 Py_ReprLeave
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
234 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
235
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
236 class FakeRepr(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
237 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
238 Class representing a non-descript PyObject* value in the inferior
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
239 process for when we don't have a custom scraper, intended to have
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
240 a sane repr().
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
241 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
242
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
243 def __init__(self, tp_name, address):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
244 self.tp_name = tp_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
245 self.address = address
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
246
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
247 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
248 # For the NULL pointer, we have no way of knowing a type, so
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
249 # special-case it as per
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
250 # http://bugs.python.org/issue8032#msg100882
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
251 if self.address == 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
252 return '0x0'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
253 return '<%s at remote 0x%x>' % (self.tp_name, self.address)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
254
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
255 return FakeRepr(self.safe_tp_name(),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
256 long(self._gdbval))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
257
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
258 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
259 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
260 Write a string representation of the value scraped from the inferior
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
261 process to "out", a file-like object.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
262 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
263 # Default implementation: generate a proxy value and write its repr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
264 # However, this could involve a lot of work for complicated objects,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
265 # so for derived classes we specialize this
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
266 return out.write(repr(self.proxyval(visited)))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
267
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
268 @classmethod
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
269 def subclass_from_type(cls, t):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
270 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
271 Given a PyTypeObjectPtr instance wrapping a gdb.Value that's a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
272 (PyTypeObject*), determine the corresponding subclass of PyObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
273 to use
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
274
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
275 Ideally, we would look up the symbols for the global types, but that
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
276 isn't working yet:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
277 (gdb) python print gdb.lookup_symbol('PyList_Type')[0].value
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
278 Traceback (most recent call last):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
279 File "<string>", line 1, in <module>
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
280 NotImplementedError: Symbol type not yet supported in Python scripts.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
281 Error while executing Python code.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
282
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
283 For now, we use tp_flags, after doing some string comparisons on the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
284 tp_name for some special-cases that don't seem to be visible through
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
285 flags
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
286 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
287 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
288 tp_name = t.field('tp_name').string()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
289 tp_flags = int(t.field('tp_flags'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
290 except RuntimeError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
291 # Handle any kind of error e.g. NULL ptrs by simply using the base
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
292 # class
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
293 return cls
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
294
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
295 #print 'tp_flags = 0x%08x' % tp_flags
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
296 #print 'tp_name = %r' % tp_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
297
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
298 name_map = {'bool': PyBoolObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
299 'classobj': PyClassObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
300 'instance': PyInstanceObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
301 'NoneType': PyNoneStructPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
302 'frame': PyFrameObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
303 'set' : PySetObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
304 'frozenset' : PySetObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
305 'builtin_function_or_method' : PyCFunctionObjectPtr,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
306 }
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
307 if tp_name in name_map:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
308 return name_map[tp_name]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
309
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
310 if tp_flags & Py_TPFLAGS_HEAPTYPE:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
311 return HeapTypeObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
312
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
313 if tp_flags & Py_TPFLAGS_INT_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
314 return PyIntObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
315 if tp_flags & Py_TPFLAGS_LONG_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
316 return PyLongObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
317 if tp_flags & Py_TPFLAGS_LIST_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
318 return PyListObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
319 if tp_flags & Py_TPFLAGS_TUPLE_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
320 return PyTupleObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
321 if tp_flags & Py_TPFLAGS_STRING_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
322 return PyStringObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
323 if tp_flags & Py_TPFLAGS_UNICODE_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
324 return PyUnicodeObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
325 if tp_flags & Py_TPFLAGS_DICT_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
326 return PyDictObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
327 if tp_flags & Py_TPFLAGS_BASE_EXC_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
328 return PyBaseExceptionObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
329 #if tp_flags & Py_TPFLAGS_TYPE_SUBCLASS:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
330 # return PyTypeObjectPtr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
331
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
332 # Use the base class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
333 return cls
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
334
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
335 @classmethod
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
336 def from_pyobject_ptr(cls, gdbval):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
337 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
338 Try to locate the appropriate derived class dynamically, and cast
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
339 the pointer accordingly.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
340 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
341 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
342 p = PyObjectPtr(gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
343 cls = cls.subclass_from_type(p.type())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
344 return cls(gdbval, cast_to=cls.get_gdb_type())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
345 except RuntimeError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
346 # Handle any kind of error e.g. NULL ptrs by simply using the base
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
347 # class
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
348 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
349 return cls(gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
350
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
351 @classmethod
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
352 def get_gdb_type(cls):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
353 return gdb.lookup_type(cls._typename).pointer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
354
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
355 def as_address(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
356 return long(self._gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
357
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
358
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
359 class ProxyAlreadyVisited(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
360 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
361 Placeholder proxy to use when protecting against infinite recursion due to
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
362 loops in the object graph.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
363
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
364 Analogous to the values emitted by the users of Py_ReprEnter and Py_ReprLeave
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
365 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
366 def __init__(self, rep):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
367 self._rep = rep
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
368
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
369 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
370 return self._rep
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
371
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
372
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
373 def _write_instance_repr(out, visited, name, pyop_attrdict, address):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
374 '''Shared code for use by old-style and new-style classes:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
375 write a representation to file-like object "out"'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
376 out.write('<')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
377 out.write(name)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
378
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
379 # Write dictionary of instance attributes:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
380 if isinstance(pyop_attrdict, PyDictObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
381 out.write('(')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
382 first = True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
383 for pyop_arg, pyop_val in pyop_attrdict.iteritems():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
384 if not first:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
385 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
386 first = False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
387 out.write(pyop_arg.proxyval(visited))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
388 out.write('=')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
389 pyop_val.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
390 out.write(')')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
391 out.write(' at remote 0x%x>' % address)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
392
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
393
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
394 class InstanceProxy(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
395
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
396 def __init__(self, cl_name, attrdict, address):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
397 self.cl_name = cl_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
398 self.attrdict = attrdict
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
399 self.address = address
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
400
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
401 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
402 if isinstance(self.attrdict, dict):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
403 kwargs = ', '.join(["%s=%r" % (arg, val)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
404 for arg, val in self.attrdict.iteritems()])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
405 return '<%s(%s) at remote 0x%x>' % (self.cl_name,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
406 kwargs, self.address)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
407 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
408 return '<%s at remote 0x%x>' % (self.cl_name,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
409 self.address)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
410
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
411 def _PyObject_VAR_SIZE(typeobj, nitems):
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
412 if _PyObject_VAR_SIZE._type_size_t is None:
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
413 _PyObject_VAR_SIZE._type_size_t = gdb.lookup_type('size_t')
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
414
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
415 return ( ( typeobj.field('tp_basicsize') +
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
416 nitems * typeobj.field('tp_itemsize') +
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
417 (SIZEOF_VOID_P - 1)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
418 ) & ~(SIZEOF_VOID_P - 1)
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
419 ).cast(_PyObject_VAR_SIZE._type_size_t)
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
420 _PyObject_VAR_SIZE._type_size_t = None
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
421
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
422 class HeapTypeObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
423 _typename = 'PyObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
424
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
425 def get_attr_dict(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
426 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
427 Get the PyDictObject ptr representing the attribute dictionary
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
428 (or None if there's a problem)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
429 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
430 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
431 typeobj = self.type()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
432 dictoffset = int_from_int(typeobj.field('tp_dictoffset'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
433 if dictoffset != 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
434 if dictoffset < 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
435 type_PyVarObject_ptr = gdb.lookup_type('PyVarObject').pointer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
436 tsize = int_from_int(self._gdbval.cast(type_PyVarObject_ptr)['ob_size'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
437 if tsize < 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
438 tsize = -tsize
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
439 size = _PyObject_VAR_SIZE(typeobj, tsize)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
440 dictoffset += size
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
441 assert dictoffset > 0
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
442 assert dictoffset % SIZEOF_VOID_P == 0
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
443
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
444 dictptr = self._gdbval.cast(_type_char_ptr) + dictoffset
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
445 PyObjectPtrPtr = PyObjectPtr.get_gdb_type().pointer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
446 dictptr = dictptr.cast(PyObjectPtrPtr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
447 return PyObjectPtr.from_pyobject_ptr(dictptr.dereference())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
448 except RuntimeError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
449 # Corrupt data somewhere; fail safe
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
450 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
451
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
452 # Not found, or some kind of error:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
453 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
454
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
455 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
456 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
457 Support for new-style classes.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
458
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
459 Currently we just locate the dictionary using a transliteration to
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
460 python of _PyObject_GetDictPtr, ignoring descriptors
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
461 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
462 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
463 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
464 return ProxyAlreadyVisited('<...>')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
465 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
466
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
467 pyop_attr_dict = self.get_attr_dict()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
468 if pyop_attr_dict:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
469 attr_dict = pyop_attr_dict.proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
470 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
471 attr_dict = {}
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
472 tp_name = self.safe_tp_name()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
473
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
474 # New-style class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
475 return InstanceProxy(tp_name, attr_dict, long(self._gdbval))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
476
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
477 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
478 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
479 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
480 out.write('<...>')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
481 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
482 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
483
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
484 pyop_attrdict = self.get_attr_dict()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
485 _write_instance_repr(out, visited,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
486 self.safe_tp_name(), pyop_attrdict, self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
487
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
488 class ProxyException(Exception):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
489 def __init__(self, tp_name, args):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
490 self.tp_name = tp_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
491 self.args = args
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
492
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
493 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
494 return '%s%r' % (self.tp_name, self.args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
495
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
496 class PyBaseExceptionObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
497 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
498 Class wrapping a gdb.Value that's a PyBaseExceptionObject* i.e. an exception
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
499 within the process being debugged.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
500 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
501 _typename = 'PyBaseExceptionObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
502
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
503 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
504 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
505 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
506 return ProxyAlreadyVisited('(...)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
507 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
508 arg_proxy = self.pyop_field('args').proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
509 return ProxyException(self.safe_tp_name(),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
510 arg_proxy)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
511
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
512 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
513 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
514 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
515 out.write('(...)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
516 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
517 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
518
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
519 out.write(self.safe_tp_name())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
520 self.write_field_repr('args', out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
521
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
522 class PyBoolObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
523 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
524 Class wrapping a gdb.Value that's a PyBoolObject* i.e. one of the two
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
525 <bool> instances (Py_True/Py_False) within the process being debugged.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
526 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
527 _typename = 'PyBoolObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
528
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
529 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
530 if int_from_int(self.field('ob_ival')):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
531 return True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
532 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
533 return False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
534
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
535
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
536 class PyClassObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
537 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
538 Class wrapping a gdb.Value that's a PyClassObject* i.e. a <classobj>
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
539 instance within the process being debugged.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
540 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
541 _typename = 'PyClassObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
542
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
543
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
544 class BuiltInFunctionProxy(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
545 def __init__(self, ml_name):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
546 self.ml_name = ml_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
547
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
548 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
549 return "<built-in function %s>" % self.ml_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
550
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
551 class BuiltInMethodProxy(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
552 def __init__(self, ml_name, pyop_m_self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
553 self.ml_name = ml_name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
554 self.pyop_m_self = pyop_m_self
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
555
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
556 def __repr__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
557 return ('<built-in method %s of %s object at remote 0x%x>'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
558 % (self.ml_name,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
559 self.pyop_m_self.safe_tp_name(),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
560 self.pyop_m_self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
561 )
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
562
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
563 class PyCFunctionObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
564 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
565 Class wrapping a gdb.Value that's a PyCFunctionObject*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
566 (see Include/methodobject.h and Objects/methodobject.c)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
567 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
568 _typename = 'PyCFunctionObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
569
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
570 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
571 m_ml = self.field('m_ml') # m_ml is a (PyMethodDef*)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
572 ml_name = m_ml['ml_name'].string()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
573
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
574 pyop_m_self = self.pyop_field('m_self')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
575 if pyop_m_self.is_null():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
576 return BuiltInFunctionProxy(ml_name)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
577 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
578 return BuiltInMethodProxy(ml_name, pyop_m_self)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
579
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
580
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
581 class PyCodeObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
582 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
583 Class wrapping a gdb.Value that's a PyCodeObject* i.e. a <code> instance
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
584 within the process being debugged.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
585 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
586 _typename = 'PyCodeObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
587
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
588 def addr2line(self, addrq):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
589 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
590 Get the line number for a given bytecode offset
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
591
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
592 Analogous to PyCode_Addr2Line; translated from pseudocode in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
593 Objects/lnotab_notes.txt
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
594 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
595 co_lnotab = self.pyop_field('co_lnotab').proxyval(set())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
596
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
597 # Initialize lineno to co_firstlineno as per PyCode_Addr2Line
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
598 # not 0, as lnotab_notes.txt has it:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
599 lineno = int_from_int(self.field('co_firstlineno'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
600
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
601 addr = 0
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
602 for addr_incr, line_incr in zip(co_lnotab[::2], co_lnotab[1::2]):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
603 addr += ord(addr_incr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
604 if addr > addrq:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
605 return lineno
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
606 lineno += ord(line_incr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
607 return lineno
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
608
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
609
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
610 class PyDictObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
611 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
612 Class wrapping a gdb.Value that's a PyDictObject* i.e. a dict instance
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
613 within the process being debugged.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
614 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
615 _typename = 'PyDictObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
616
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
617 def iteritems(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
618 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
619 Yields a sequence of (PyObjectPtr key, PyObjectPtr value) pairs,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
620 analagous to dict.iteritems()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
621 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
622 for i in safe_range(self.field('ma_mask') + 1):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
623 ep = self.field('ma_table') + i
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
624 pyop_value = PyObjectPtr.from_pyobject_ptr(ep['me_value'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
625 if not pyop_value.is_null():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
626 pyop_key = PyObjectPtr.from_pyobject_ptr(ep['me_key'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
627 yield (pyop_key, pyop_value)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
628
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
629 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
630 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
631 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
632 return ProxyAlreadyVisited('{...}')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
633 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
634
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
635 result = {}
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
636 for pyop_key, pyop_value in self.iteritems():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
637 proxy_key = pyop_key.proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
638 proxy_value = pyop_value.proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
639 result[proxy_key] = proxy_value
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
640 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
641
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
642 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
643 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
644 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
645 out.write('{...}')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
646 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
647 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
648
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
649 out.write('{')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
650 first = True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
651 for pyop_key, pyop_value in self.iteritems():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
652 if not first:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
653 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
654 first = False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
655 pyop_key.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
656 out.write(': ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
657 pyop_value.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
658 out.write('}')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
659
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
660 class PyInstanceObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
661 _typename = 'PyInstanceObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
662
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
663 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
664 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
665 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
666 return ProxyAlreadyVisited('<...>')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
667 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
668
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
669 # Get name of class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
670 in_class = self.pyop_field('in_class')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
671 cl_name = in_class.pyop_field('cl_name').proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
672
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
673 # Get dictionary of instance attributes:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
674 in_dict = self.pyop_field('in_dict').proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
675
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
676 # Old-style class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
677 return InstanceProxy(cl_name, in_dict, long(self._gdbval))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
678
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
679 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
680 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
681 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
682 out.write('<...>')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
683 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
684 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
685
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
686 # Old-style class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
687
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
688 # Get name of class:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
689 in_class = self.pyop_field('in_class')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
690 cl_name = in_class.pyop_field('cl_name').proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
691
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
692 # Get dictionary of instance attributes:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
693 pyop_in_dict = self.pyop_field('in_dict')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
694
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
695 _write_instance_repr(out, visited,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
696 cl_name, pyop_in_dict, self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
697
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
698 class PyIntObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
699 _typename = 'PyIntObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
700
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
701 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
702 result = int_from_int(self.field('ob_ival'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
703 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
704
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
705 class PyListObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
706 _typename = 'PyListObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
707
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
708 def __getitem__(self, i):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
709 # Get the gdb.Value for the (PyObject*) with the given index:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
710 field_ob_item = self.field('ob_item')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
711 return field_ob_item[i]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
712
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
713 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
714 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
715 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
716 return ProxyAlreadyVisited('[...]')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
717 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
718
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
719 result = [PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
720 for i in safe_range(int_from_int(self.field('ob_size')))]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
721 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
722
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
723 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
724 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
725 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
726 out.write('[...]')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
727 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
728 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
729
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
730 out.write('[')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
731 for i in safe_range(int_from_int(self.field('ob_size'))):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
732 if i > 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
733 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
734 element = PyObjectPtr.from_pyobject_ptr(self[i])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
735 element.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
736 out.write(']')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
737
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
738 class PyLongObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
739 _typename = 'PyLongObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
740
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
741 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
742 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
743 Python's Include/longobjrep.h has this declaration:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
744 struct _longobject {
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
745 PyObject_VAR_HEAD
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
746 digit ob_digit[1];
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
747 };
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
748
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
749 with this description:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
750 The absolute value of a number is equal to
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
751 SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
752 Negative numbers are represented with ob_size < 0;
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
753 zero is represented by ob_size == 0.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
754
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
755 where SHIFT can be either:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
756 #define PyLong_SHIFT 30
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
757 #define PyLong_SHIFT 15
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
758 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
759 ob_size = long(self.field('ob_size'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
760 if ob_size == 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
761 return 0L
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
762
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
763 ob_digit = self.field('ob_digit')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
764
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
765 if gdb.lookup_type('digit').sizeof == 2:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
766 SHIFT = 15L
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
767 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
768 SHIFT = 30L
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
769
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
770 digits = [long(ob_digit[i]) * 2**(SHIFT*i)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
771 for i in safe_range(abs(ob_size))]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
772 result = sum(digits)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
773 if ob_size < 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
774 result = -result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
775 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
776
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
777
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
778 class PyNoneStructPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
779 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
780 Class wrapping a gdb.Value that's a PyObject* pointing to the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
781 singleton (we hope) _Py_NoneStruct with ob_type PyNone_Type
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
782 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
783 _typename = 'PyObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
784
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
785 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
786 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
787
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
788
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
789 class PyFrameObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
790 _typename = 'PyFrameObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
791
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
792 def __init__(self, gdbval, cast_to=None):
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
793 PyObjectPtr.__init__(self, gdbval, cast_to)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
794
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
795 if not self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
796 self.co = PyCodeObjectPtr.from_pyobject_ptr(self.field('f_code'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
797 self.co_name = self.co.pyop_field('co_name')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
798 self.co_filename = self.co.pyop_field('co_filename')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
799
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
800 self.f_lineno = int_from_int(self.field('f_lineno'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
801 self.f_lasti = int_from_int(self.field('f_lasti'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
802 self.co_nlocals = int_from_int(self.co.field('co_nlocals'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
803 self.co_varnames = PyTupleObjectPtr.from_pyobject_ptr(self.co.field('co_varnames'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
804
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
805 def iter_locals(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
806 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
807 Yield a sequence of (name,value) pairs of PyObjectPtr instances, for
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
808 the local variables of this frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
809 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
810 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
811 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
812
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
813 f_localsplus = self.field('f_localsplus')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
814 for i in safe_range(self.co_nlocals):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
815 pyop_value = PyObjectPtr.from_pyobject_ptr(f_localsplus[i])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
816 if not pyop_value.is_null():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
817 pyop_name = PyObjectPtr.from_pyobject_ptr(self.co_varnames[i])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
818 yield (pyop_name, pyop_value)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
819
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
820 def iter_globals(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
821 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
822 Yield a sequence of (name,value) pairs of PyObjectPtr instances, for
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
823 the global variables of this frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
824 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
825 if self.is_optimized_out():
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
826 return ()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
827
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
828 pyop_globals = self.pyop_field('f_globals')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
829 return pyop_globals.iteritems()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
830
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
831 def iter_builtins(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
832 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
833 Yield a sequence of (name,value) pairs of PyObjectPtr instances, for
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
834 the builtin variables
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
835 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
836 if self.is_optimized_out():
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
837 return ()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
838
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
839 pyop_builtins = self.pyop_field('f_builtins')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
840 return pyop_builtins.iteritems()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
841
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
842 def get_var_by_name(self, name):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
843 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
844 Look for the named local variable, returning a (PyObjectPtr, scope) pair
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
845 where scope is a string 'local', 'global', 'builtin'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
846
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
847 If not found, return (None, None)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
848 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
849 for pyop_name, pyop_value in self.iter_locals():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
850 if name == pyop_name.proxyval(set()):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
851 return pyop_value, 'local'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
852 for pyop_name, pyop_value in self.iter_globals():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
853 if name == pyop_name.proxyval(set()):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
854 return pyop_value, 'global'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
855 for pyop_name, pyop_value in self.iter_builtins():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
856 if name == pyop_name.proxyval(set()):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
857 return pyop_value, 'builtin'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
858 return None, None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
859
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
860 def filename(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
861 '''Get the path of the current Python source file, as a string'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
862 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
863 return '(frame information optimized out)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
864 return self.co_filename.proxyval(set())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
865
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
866 def current_line_num(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
867 '''Get current line number as an integer (1-based)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
868
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
869 Translated from PyFrame_GetLineNumber and PyCode_Addr2Line
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
870
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
871 See Objects/lnotab_notes.txt
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
872 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
873 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
874 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
875 f_trace = self.field('f_trace')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
876 if long(f_trace) != 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
877 # we have a non-NULL f_trace:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
878 return self.f_lineno
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
879 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
880 #try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
881 return self.co.addr2line(self.f_lasti)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
882 #except ValueError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
883 # return self.f_lineno
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
884
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
885 def current_line(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
886 '''Get the text of the current source line as a string, with a trailing
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
887 newline character'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
888 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
889 return '(frame information optimized out)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
890 with open(self.filename(), 'r') as f:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
891 all_lines = f.readlines()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
892 # Convert from 1-based current_line_num to 0-based list offset:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
893 return all_lines[self.current_line_num()-1]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
894
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
895 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
896 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
897 out.write('(frame information optimized out)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
898 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
899 out.write('Frame 0x%x, for file %s, line %i, in %s ('
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
900 % (self.as_address(),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
901 self.co_filename,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
902 self.current_line_num(),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
903 self.co_name))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
904 first = True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
905 for pyop_name, pyop_value in self.iter_locals():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
906 if not first:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
907 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
908 first = False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
909
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
910 out.write(pyop_name.proxyval(visited))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
911 out.write('=')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
912 pyop_value.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
913
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
914 out.write(')')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
915
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
916 class PySetObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
917 _typename = 'PySetObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
918
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
919 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
920 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
921 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
922 return ProxyAlreadyVisited('%s(...)' % self.safe_tp_name())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
923 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
924
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
925 members = []
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
926 table = self.field('table')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
927 for i in safe_range(self.field('mask')+1):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
928 setentry = table[i]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
929 key = setentry['key']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
930 if key != 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
931 key_proxy = PyObjectPtr.from_pyobject_ptr(key).proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
932 if key_proxy != '<dummy key>':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
933 members.append(key_proxy)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
934 if self.safe_tp_name() == 'frozenset':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
935 return frozenset(members)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
936 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
937 return set(members)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
938
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
939 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
940 out.write(self.safe_tp_name())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
941
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
942 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
943 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
944 out.write('(...)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
945 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
946 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
947
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
948 out.write('([')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
949 first = True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
950 table = self.field('table')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
951 for i in safe_range(self.field('mask')+1):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
952 setentry = table[i]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
953 key = setentry['key']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
954 if key != 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
955 pyop_key = PyObjectPtr.from_pyobject_ptr(key)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
956 key_proxy = pyop_key.proxyval(visited) # FIXME!
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
957 if key_proxy != '<dummy key>':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
958 if not first:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
959 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
960 first = False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
961 pyop_key.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
962 out.write('])')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
963
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
964
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
965 class PyStringObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
966 _typename = 'PyStringObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
967
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
968 def __str__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
969 field_ob_size = self.field('ob_size')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
970 field_ob_sval = self.field('ob_sval')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
971 char_ptr = field_ob_sval.address.cast(_type_unsigned_char_ptr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
972 return ''.join([chr(char_ptr[i]) for i in safe_range(field_ob_size)])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
973
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
974 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
975 return str(self)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
976
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
977 class PyTupleObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
978 _typename = 'PyTupleObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
979
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
980 def __getitem__(self, i):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
981 # Get the gdb.Value for the (PyObject*) with the given index:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
982 field_ob_item = self.field('ob_item')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
983 return field_ob_item[i]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
984
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
985 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
986 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
987 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
988 return ProxyAlreadyVisited('(...)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
989 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
990
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
991 result = tuple([PyObjectPtr.from_pyobject_ptr(self[i]).proxyval(visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
992 for i in safe_range(int_from_int(self.field('ob_size')))])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
993 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
994
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
995 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
996 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
997 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
998 out.write('(...)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
999 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1000 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1001
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1002 out.write('(')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1003 for i in safe_range(int_from_int(self.field('ob_size'))):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1004 if i > 0:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1005 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1006 element = PyObjectPtr.from_pyobject_ptr(self[i])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1007 element.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1008 if self.field('ob_size') == 1:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1009 out.write(',)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1010 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1011 out.write(')')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1012
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1013 class PyTypeObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1014 _typename = 'PyTypeObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1015
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1016
64572
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1017 if sys.maxunicode >= 0x10000:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1018 _unichr = unichr
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1019 else:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1020 # Needed for proper surrogate support if sizeof(Py_UNICODE) is 2 in gdb
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1021 def _unichr(x):
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1022 if x < 0x10000:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1023 return unichr(x)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1024 x -= 0x10000
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1025 ch1 = 0xD800 | (x >> 10)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1026 ch2 = 0xDC00 | (x & 0x3FF)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1027 return unichr(ch1) + unichr(ch2)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1028
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1029 class PyUnicodeObjectPtr(PyObjectPtr):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1030 _typename = 'PyUnicodeObject'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1031
61770
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1032 def char_width(self):
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1033 _type_Py_UNICODE = gdb.lookup_type('Py_UNICODE')
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1034 return _type_Py_UNICODE.sizeof
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1035
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1036 def proxyval(self, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1037 # From unicodeobject.h:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1038 # Py_ssize_t length; /* Length of raw Unicode data in buffer */
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1039 # Py_UNICODE *str; /* Raw Unicode buffer */
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1040 field_length = long(self.field('length'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1041 field_str = self.field('str')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1042
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1043 # Gather a list of ints from the Py_UNICODE array; these are either
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1044 # UCS-2 or UCS-4 code points:
64572
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1045 if self.char_width() > 2:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1046 Py_UNICODEs = [int(field_str[i]) for i in safe_range(field_length)]
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1047 else:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1048 # A more elaborate routine if sizeof(Py_UNICODE) is 2 in the
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1049 # inferior process: we must join surrogate pairs.
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1050 Py_UNICODEs = []
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1051 i = 0
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1052 limit = safety_limit(field_length)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1053 while i < limit:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1054 ucs = int(field_str[i])
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1055 i += 1
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1056 if ucs < 0xD800 or ucs >= 0xDC00 or i == field_length:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1057 Py_UNICODEs.append(ucs)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1058 continue
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1059 # This could be a surrogate pair.
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1060 ucs2 = int(field_str[i])
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1061 if ucs2 < 0xDC00 or ucs2 > 0xDFFF:
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1062 continue
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1063 code = (ucs & 0x03FF) << 10
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1064 code |= ucs2 & 0x03FF
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1065 code += 0x00010000
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1066 Py_UNICODEs.append(code)
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1067 i += 1
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1068
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1069 # Convert the int code points to unicode characters, and generate a
64572
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1070 # local unicode instance.
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1071 # This splits surrogate pairs if sizeof(Py_UNICODE) is 2 here (in gdb).
1322266f9611 Merged revisions 84635-84636 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 63014
diff changeset
1072 result = u''.join([_unichr(ucs) for ucs in Py_UNICODEs])
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1073 return result
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1074
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1075
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1076 def int_from_int(gdbval):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1077 return int(str(gdbval))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1078
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1079
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1080 def stringify(val):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1081 # TODO: repr() puts everything on one line; pformat can be nicer, but
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1082 # can lead to v.long results; this function isolates the choice
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1083 if True:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1084 return repr(val)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1085 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1086 from pprint import pformat
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1087 return pformat(val)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1088
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1089
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1090 class PyObjectPtrPrinter:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1091 "Prints a (PyObject*)"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1092
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1093 def __init__ (self, gdbval):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1094 self.gdbval = gdbval
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1095
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1096 def to_string (self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1097 pyop = PyObjectPtr.from_pyobject_ptr(self.gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1098 if True:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1099 return pyop.get_truncated_repr(MAX_OUTPUT_LEN)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1100 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1101 # Generate full proxy value then stringify it.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1102 # Doing so could be expensive
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1103 proxyval = pyop.proxyval(set())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1104 return stringify(proxyval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1105
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1106 def pretty_printer_lookup(gdbval):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1107 type = gdbval.type.unqualified()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1108 if type.code == gdb.TYPE_CODE_PTR:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1109 type = type.target().unqualified()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1110 t = str(type)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1111 if t in ("PyObject", "PyFrameObject"):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1112 return PyObjectPtrPrinter(gdbval)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1113
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1114 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1115 During development, I've been manually invoking the code in this way:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1116 (gdb) python
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1117
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1118 import sys
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1119 sys.path.append('/home/david/coding/python-gdb')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1120 import libpython
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1121 end
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1122
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1123 then reloading it after each edit like this:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1124 (gdb) python reload(libpython)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1126 The following code should ensure that the prettyprinter is registered
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1127 if the code is autoloaded by gdb when visiting libpython.so, provided
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1128 that this python file is installed to the same path as the library (or its
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1129 .debug file) plus a "-gdb.py" suffix, e.g:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1130 /usr/lib/libpython2.6.so.1.0-gdb.py
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1131 /usr/lib/debug/usr/lib/libpython2.6.so.1.0.debug-gdb.py
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1132 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1133 def register (obj):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1134 if obj == None:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1135 obj = gdb
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1136
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1137 # Wire up the pretty-printer
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1138 obj.pretty_printers.append(pretty_printer_lookup)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1139
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1140 register (gdb.current_objfile ())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1141
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1142
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1143
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1144 # Unfortunately, the exact API exposed by the gdb module varies somewhat
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1145 # from build to build
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1146 # See http://bugs.python.org/issue8279?#msg102276
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1147
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1148 class Frame(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1149 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1150 Wrapper for gdb.Frame, adding various methods
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1151 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1152 def __init__(self, gdbframe):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1153 self._gdbframe = gdbframe
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1154
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1155 def older(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1156 older = self._gdbframe.older()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1157 if older:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1158 return Frame(older)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1159 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1160 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1161
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1162 def newer(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1163 newer = self._gdbframe.newer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1164 if newer:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1165 return Frame(newer)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1166 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1167 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1168
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1169 def select(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1170 '''If supported, select this frame and return True; return False if unsupported
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1171
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1172 Not all builds have a gdb.Frame.select method; seems to be present on Fedora 12
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1173 onwards, but absent on Ubuntu buildbot'''
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1174 if not hasattr(self._gdbframe, 'select'):
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1175 print ('Unable to select frame: '
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1176 'this build of gdb does not expose a gdb.Frame.select method')
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1177 return False
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1178 self._gdbframe.select()
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1179 return True
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1180
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1181 def get_index(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1182 '''Calculate index of frame, starting at 0 for the newest frame within
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1183 this thread'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1184 index = 0
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1185 # Go down until you reach the newest frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1186 iter_frame = self
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1187 while iter_frame.newer():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1188 index += 1
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1189 iter_frame = iter_frame.newer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1190 return index
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1191
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1192 def is_evalframeex(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1193 '''Is this a PyEval_EvalFrameEx frame?'''
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1194 if self._gdbframe.name() == 'PyEval_EvalFrameEx':
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1195 '''
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1196 I believe we also need to filter on the inline
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1197 struct frame_id.inline_depth, only regarding frames with
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1198 an inline depth of 0 as actually being this function
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1199
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1200 So we reject those with type gdb.INLINE_FRAME
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1201 '''
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1202 if self._gdbframe.type() == gdb.NORMAL_FRAME:
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1203 # We have a PyEval_EvalFrameEx frame:
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1204 return True
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1205
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1206 return False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1207
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1208 def get_pyop(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1209 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1210 f = self._gdbframe.read_var('f')
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1211 frame = PyFrameObjectPtr.from_pyobject_ptr(f)
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1212 if not frame.is_optimized_out():
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1213 return frame
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1214 # gdb is unable to get the "f" argument of PyEval_EvalFrameEx()
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1215 # because it was "optimized out". Try to get "f" from the frame
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1216 # of the caller, PyEval_EvalCodeEx().
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1217 orig_frame = frame
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1218 caller = self._gdbframe.older()
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1219 if caller:
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1220 f = caller.read_var('f')
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1221 frame = PyFrameObjectPtr.from_pyobject_ptr(f)
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1222 if not frame.is_optimized_out():
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1223 return frame
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1224 return orig_frame
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1225 except ValueError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1226 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1227
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1228 @classmethod
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1229 def get_selected_frame(cls):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1230 _gdbframe = gdb.selected_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1231 if _gdbframe:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1232 return Frame(_gdbframe)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1233 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1234
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1235 @classmethod
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1236 def get_selected_python_frame(cls):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1237 '''Try to obtain the Frame for the python code in the selected frame,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1238 or None'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1239 frame = cls.get_selected_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1240
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1241 while frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1242 if frame.is_evalframeex():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1243 return frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1244 frame = frame.older()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1245
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1246 # Not found:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1247 return None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1248
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1249 def print_summary(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1250 if self.is_evalframeex():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1251 pyop = self.get_pyop()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1252 if pyop:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1253 sys.stdout.write('#%i %s\n' % (self.get_index(), pyop.get_truncated_repr(MAX_OUTPUT_LEN)))
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1254 if not pyop.is_optimized_out():
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1255 line = pyop.current_line()
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1256 sys.stdout.write(' %s\n' % line.strip())
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1257 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1258 sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1259 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1260 sys.stdout.write('#%i\n' % self.get_index())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1261
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1262 class PyList(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1263 '''List the current Python source code, if any
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1264
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1265 Use
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1266 py-list START
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1267 to list at a different line number within the python source.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1268
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1269 Use
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1270 py-list START, END
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1271 to list a specific range of lines within the python source.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1272 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1273
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1274 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1275 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1276 "py-list",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1277 gdb.COMMAND_FILES,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1278 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1279
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1280
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1281 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1282 import re
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1283
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1284 start = None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1285 end = None
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1286
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1287 m = re.match(r'\s*(\d+)\s*', args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1288 if m:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1289 start = int(m.group(0))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1290 end = start + 10
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1291
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1292 m = re.match(r'\s*(\d+)\s*,\s*(\d+)\s*', args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1293 if m:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1294 start, end = map(int, m.groups())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1295
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1296 frame = Frame.get_selected_python_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1297 if not frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1298 print 'Unable to locate python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1299 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1300
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1301 pyop = frame.get_pyop()
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64572
diff changeset
1302 if not pyop or pyop.is_optimized_out():
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1303 print 'Unable to read information on python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1304 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1305
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1306 filename = pyop.filename()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1307 lineno = pyop.current_line_num()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1308
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1309 if start is None:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1310 start = lineno - 5
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1311 end = lineno + 5
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1312
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1313 if start<1:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1314 start = 1
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1315
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1316 with open(filename, 'r') as f:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1317 all_lines = f.readlines()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1318 # start and end are 1-based, all_lines is 0-based;
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1319 # so [start-1:end] as a python slice gives us [start, end] as a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1320 # closed interval
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1321 for i, line in enumerate(all_lines[start-1:end]):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1322 linestr = str(i+start)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1323 # Highlight current line:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1324 if i + start == lineno:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1325 linestr = '>' + linestr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1326 sys.stdout.write('%4s %s' % (linestr, line))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1327
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1328
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1329 # ...and register the command:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1330 PyList()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1331
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1332 def move_in_stack(move_up):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1333 '''Move up or down the stack (for the py-up/py-down command)'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1334 frame = Frame.get_selected_python_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1335 while frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1336 if move_up:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1337 iter_frame = frame.older()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1338 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1339 iter_frame = frame.newer()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1340
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1341 if not iter_frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1342 break
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1343
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1344 if iter_frame.is_evalframeex():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1345 # Result:
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1346 if iter_frame.select():
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1347 iter_frame.print_summary()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1348 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1349
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1350 frame = iter_frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1351
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1352 if move_up:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1353 print 'Unable to find an older python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1354 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1355 print 'Unable to find a newer python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1356
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1357 class PyUp(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1358 'Select and print the python stack frame that called this one (if any)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1359 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1360 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1361 "py-up",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1362 gdb.COMMAND_STACK,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1363 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1364
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1365
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1366 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1367 move_in_stack(move_up=True)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1368
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1369 class PyDown(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1370 'Select and print the python stack frame called by this one (if any)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1371 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1372 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1373 "py-down",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1374 gdb.COMMAND_STACK,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1375 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1376
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1377
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1378 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1379 move_in_stack(move_up=False)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1380
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1381 # Not all builds of gdb have gdb.Frame.select
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1382 if hasattr(gdb.Frame, 'select'):
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1383 PyUp()
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1384 PyDown()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1385
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1386 class PyBacktrace(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1387 'Display the current python frame and all the frames within its call stack (if any)'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1388 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1389 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1390 "py-bt",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1391 gdb.COMMAND_STACK,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1392 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1393
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1394
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1395 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1396 frame = Frame.get_selected_python_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1397 while frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1398 if frame.is_evalframeex():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1399 frame.print_summary()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1400 frame = frame.older()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1401
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1402 PyBacktrace()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1403
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1404 class PyPrint(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1405 'Look up the given python variable name, and print it'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1406 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1407 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1408 "py-print",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1409 gdb.COMMAND_DATA,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1410 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1411
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1412
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1413 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1414 name = str(args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1415
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1416 frame = Frame.get_selected_python_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1417 if not frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1418 print 'Unable to locate python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1419 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1420
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1421 pyop_frame = frame.get_pyop()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1422 if not pyop_frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1423 print 'Unable to read information on python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1424 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1425
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1426 pyop_var, scope = pyop_frame.get_var_by_name(name)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1427
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1428 if pyop_var:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1429 print ('%s %r = %s'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1430 % (scope,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1431 name,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1432 pyop_var.get_truncated_repr(MAX_OUTPUT_LEN)))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1433 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1434 print '%r not found' % name
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1435
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1436 PyPrint()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1437
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1438 class PyLocals(gdb.Command):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1439 'Look up the given python variable name, and print it'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1440 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1441 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1442 "py-locals",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1443 gdb.COMMAND_DATA,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1444 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1445
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1446
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1447 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1448 name = str(args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1449
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1450 frame = Frame.get_selected_python_frame()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1451 if not frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1452 print 'Unable to locate python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1453 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1454
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1455 pyop_frame = frame.get_pyop()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1456 if not pyop_frame:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1457 print 'Unable to read information on python frame'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1458 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1459
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1460 for pyop_name, pyop_value in pyop_frame.iter_locals():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1461 print ('%s = %s'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1462 % (pyop_name.proxyval(set()),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1463 pyop_value.get_truncated_repr(MAX_OUTPUT_LEN)))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1464
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1465 PyLocals()