Mercurial > cpython-lru_cache-weakref
annotate Tools/gdb/libpython.py @ 60664:d7d5c76545fb legacy-trunk
Issue #8279: Fix test_gdb failures.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 17 Apr 2010 22:40:40 +0000 |
| parents | 6de3de3ab71f |
| children | 86d08cb6ba5c |
| 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 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
44 |
|
6de3de3ab71f
Issue #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 # 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
|
46 _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
|
47 _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
|
48 _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
|
49 _type_size_t = gdb.lookup_type('size_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
|
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): |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
412 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
|
413 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
|
414 (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
|
415 ) & ~(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
|
416 ).cast(_type_size_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
|
417 |
|
6de3de3ab71f
Issue #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 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
|
419 _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
|
420 |
|
6de3de3ab71f
Issue #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 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
|
422 ''' |
|
6de3de3ab71f
Issue #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 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
|
424 (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
|
425 ''' |
|
6de3de3ab71f
Issue #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 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 |
|
6de3de3ab71f
Issue #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 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 # 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
|
446 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
|
447 |
|
6de3de3ab71f
Issue #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 # 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
|
449 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
|
450 |
|
6de3de3ab71f
Issue #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 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
|
452 ''' |
|
6de3de3ab71f
Issue #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 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
|
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 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
|
456 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
|
457 ''' |
|
6de3de3ab71f
Issue #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 # 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
|
459 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
|
460 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
|
461 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
|
462 |
|
6de3de3ab71f
Issue #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 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
|
464 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
|
465 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
|
466 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
|
467 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 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
|
469 |
|
6de3de3ab71f
Issue #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 # 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
|
471 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
|
472 |
|
6de3de3ab71f
Issue #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 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
|
474 # 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 |
|
6de3de3ab71f
Issue #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 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
|
481 _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
|
482 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
|
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 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
|
485 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
|
486 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
|
487 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
|
488 |
|
6de3de3ab71f
Issue #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 __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
|
490 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
|
491 |
|
6de3de3ab71f
Issue #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 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
|
493 """ |
|
6de3de3ab71f
Issue #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 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
|
495 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
|
496 """ |
|
6de3de3ab71f
Issue #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 _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
|
498 |
|
6de3de3ab71f
Issue #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 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
|
500 # 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 |
|
6de3de3ab71f
Issue #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 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
|
509 # 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 |
|
6de3de3ab71f
Issue #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(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
|
516 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
|
517 |
|
6de3de3ab71f
Issue #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 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
|
519 """ |
|
6de3de3ab71f
Issue #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 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
|
521 <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
|
522 """ |
|
6de3de3ab71f
Issue #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 _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
|
524 |
|
6de3de3ab71f
Issue #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 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
533 """ |
|
6de3de3ab71f
Issue #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 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
|
535 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
|
536 """ |
|
6de3de3ab71f
Issue #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 _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
|
538 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
541 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
|
542 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
|
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 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
|
545 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
|
546 |
|
6de3de3ab71f
Issue #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 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
|
548 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
|
549 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
|
550 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
|
551 |
|
6de3de3ab71f
Issue #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 __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
|
553 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
|
554 % (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
|
555 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
|
556 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
|
557 ) |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
560 """ |
|
6de3de3ab71f
Issue #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 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
|
562 (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
|
563 """ |
|
6de3de3ab71f
Issue #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 _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
|
565 |
|
6de3de3ab71f
Issue #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 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
|
567 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
|
568 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
|
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 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
578 """ |
|
6de3de3ab71f
Issue #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 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
|
580 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
|
581 """ |
|
6de3de3ab71f
Issue #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 _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
|
583 |
|
6de3de3ab71f
Issue #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 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
|
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 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
|
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 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
|
589 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
|
590 ''' |
|
6de3de3ab71f
Issue #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 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
|
592 |
|
6de3de3ab71f
Issue #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 # 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
|
594 # 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
|
595 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
|
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 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
607 """ |
|
6de3de3ab71f
Issue #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 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
|
609 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
|
610 """ |
|
6de3de3ab71f
Issue #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 _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
|
612 |
|
6de3de3ab71f
Issue #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 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
|
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 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
|
616 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
|
617 ''' |
|
6de3de3ab71f
Issue #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 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
|
619 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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 |
|
6de3de3ab71f
Issue #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 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
|
626 # 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
|
627 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
|
628 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
|
629 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
|
630 |
|
6de3de3ab71f
Issue #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 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 |
|
6de3de3ab71f
Issue #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 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
|
639 # 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 |
|
6de3de3ab71f
Issue #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 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
|
647 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
|
648 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
|
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 = 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 |
|
6de3de3ab71f
Issue #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 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
|
657 _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
|
658 |
|
6de3de3ab71f
Issue #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 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
|
660 # 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
|
661 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
|
662 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
|
663 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
|
664 |
|
6de3de3ab71f
Issue #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 # 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
|
666 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
|
667 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
|
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 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
|
670 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
|
671 |
|
6de3de3ab71f
Issue #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 # 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
|
673 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
|
674 |
|
6de3de3ab71f
Issue #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 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
|
676 # 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 |
|
6de3de3ab71f
Issue #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 # 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
|
683 |
|
6de3de3ab71f
Issue #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 # 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
|
685 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
|
686 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
|
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 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
|
689 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
|
690 |
|
6de3de3ab71f
Issue #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 _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
|
692 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
|
693 |
|
6de3de3ab71f
Issue #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 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
|
695 _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
|
696 |
|
6de3de3ab71f
Issue #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 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
|
698 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
|
699 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
|
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 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
|
702 _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
|
703 |
|
6de3de3ab71f
Issue #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 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
|
705 # 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
|
706 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
|
707 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
|
708 |
|
6de3de3ab71f
Issue #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 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
|
710 # 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
|
711 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
|
712 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
|
713 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
|
714 |
|
6de3de3ab71f
Issue #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 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
|
716 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
|
717 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
|
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 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
|
720 # 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 |
|
6de3de3ab71f
Issue #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 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
|
728 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
|
729 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
|
730 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
|
731 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
|
732 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
|
733 |
|
6de3de3ab71f
Issue #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 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
|
735 _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
|
736 |
|
6de3de3ab71f
Issue #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 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
|
738 ''' |
|
6de3de3ab71f
Issue #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 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
|
740 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
|
741 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
|
742 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
|
743 }; |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 |
|
6de3de3ab71f
Issue #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 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
|
752 #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
|
753 #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
|
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 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
|
756 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
|
757 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
|
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_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
|
760 |
|
6de3de3ab71f
Issue #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 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
|
762 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
|
763 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
|
764 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
|
765 |
|
6de3de3ab71f
Issue #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 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
775 """ |
|
6de3de3ab71f
Issue #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 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
|
777 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
|
778 """ |
|
6de3de3ab71f
Issue #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 _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
|
780 |
|
6de3de3ab71f
Issue #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 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
|
782 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
|
783 |
|
6de3de3ab71f
Issue #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 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
|
786 _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
|
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 def __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
|
789 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
|
790 |
|
6de3de3ab71f
Issue #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 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
|
792 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
|
793 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
|
794 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
|
795 |
|
6de3de3ab71f
Issue #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.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
|
797 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
|
798 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
|
799 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
|
800 |
|
6de3de3ab71f
Issue #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 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
|
802 ''' |
|
6de3de3ab71f
Issue #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 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
|
804 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
|
805 ''' |
|
6de3de3ab71f
Issue #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 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
|
807 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
|
808 |
|
6de3de3ab71f
Issue #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 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 |
|
6de3de3ab71f
Issue #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 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
|
817 ''' |
|
6de3de3ab71f
Issue #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 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
|
819 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
|
820 ''' |
|
6de3de3ab71f
Issue #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 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
|
822 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
|
823 |
|
6de3de3ab71f
Issue #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 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
|
825 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
|
826 |
|
6de3de3ab71f
Issue #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 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
|
828 ''' |
|
6de3de3ab71f
Issue #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 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
|
830 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
|
831 ''' |
|
6de3de3ab71f
Issue #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 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
|
833 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
|
834 |
|
6de3de3ab71f
Issue #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 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
|
836 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
|
837 |
|
6de3de3ab71f
Issue #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 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
|
839 ''' |
|
6de3de3ab71f
Issue #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 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
|
841 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
|
842 |
|
6de3de3ab71f
Issue #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 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
|
844 ''' |
|
6de3de3ab71f
Issue #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 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
|
846 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
|
847 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
|
848 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 |
|
6de3de3ab71f
Issue #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 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
|
857 '''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
|
858 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
|
859 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
|
860 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
|
861 |
|
6de3de3ab71f
Issue #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 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
|
863 '''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
|
864 |
|
6de3de3ab71f
Issue #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 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
|
866 |
|
6de3de3ab71f
Issue #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 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
|
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 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
|
870 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
|
871 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
|
872 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
|
873 # 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
|
874 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
|
875 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
|
876 #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
|
877 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
|
878 #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
|
879 # 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
|
880 |
|
6de3de3ab71f
Issue #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 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
|
882 '''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
|
883 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
|
884 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
|
885 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
|
886 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
|
887 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
|
888 # 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
|
889 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
|
890 |
|
6de3de3ab71f
Issue #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 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
|
892 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
|
893 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
|
894 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
|
895 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
|
896 % (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
|
897 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
|
898 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 |
|
6de3de3ab71f
Issue #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 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
|
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 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
|
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(')') |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
913 _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
|
914 |
|
6de3de3ab71f
Issue #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 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
|
916 # 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
|
917 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
|
918 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
|
919 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
|
920 |
|
6de3de3ab71f
Issue #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 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 |
|
6de3de3ab71f
Issue #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 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
|
936 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
|
937 |
|
6de3de3ab71f
Issue #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 # 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
|
939 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
|
940 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
|
941 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
|
942 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
|
943 |
|
6de3de3ab71f
Issue #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 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
962 _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
|
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 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 |
|
6de3de3ab71f
Issue #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 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
|
971 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
|
972 |
|
6de3de3ab71f
Issue #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 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
|
974 _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
|
975 |
|
6de3de3ab71f
Issue #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 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
|
977 # 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
|
978 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
|
979 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
|
980 |
|
6de3de3ab71f
Issue #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 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
|
982 # 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
|
983 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
|
984 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
|
985 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
|
986 |
|
6de3de3ab71f
Issue #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 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
|
988 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
|
989 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
|
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 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
|
992 # 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 |
|
6de3de3ab71f
Issue #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 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
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 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
|
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 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
|
1007 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
|
1008 |
|
6de3de3ab71f
Issue #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 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
|
1010 _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
|
1011 |
|
6de3de3ab71f
Issue #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 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
|
1014 _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
|
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 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
|
1017 # 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
|
1018 # 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
|
1019 # 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
|
1020 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
|
1021 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
|
1022 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1023 # 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
|
1024 # UCS-2 or UCS-4 code points: |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1025 Py_UNICODEs = [int(field_str[i]) for i in safe_range(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
|
1026 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1027 # Convert the int code points to unicode characters, and generate 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
|
1028 # local unicode 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
|
1029 result = u''.join([unichr(ucs) for ucs in Py_UNICODEs]) |
|
6de3de3ab71f
Issue #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 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
|
1031 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1032 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1033 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
|
1034 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
|
1035 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1038 # 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
|
1039 # 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
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1046 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1047 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
|
1048 "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
|
1049 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1050 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
|
1051 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
|
1052 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 # 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
|
1059 # 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
|
1060 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
|
1061 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
|
1062 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 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
|
1070 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1071 """ |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1072 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
|
1073 (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
|
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 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
|
1076 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
|
1077 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
|
1078 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
|
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 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
|
1081 (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
|
1082 |
|
6de3de3ab71f
Issue #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 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
|
1084 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
|
1085 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
|
1086 .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
|
1087 /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
|
1088 /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
|
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 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
|
1091 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
|
1092 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
|
1093 |
|
6de3de3ab71f
Issue #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 # 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
|
1095 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
|
1096 |
|
6de3de3ab71f
Issue #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 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
|
1098 |
|
6de3de3ab71f
Issue #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 |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1100 |
|
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1101 # 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
|
1102 # from build to build |
|
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1103 # 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
|
1104 |
|
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
|
1105 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
|
1106 ''' |
|
6de3de3ab71f
Issue #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 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
|
1108 ''' |
|
6de3de3ab71f
Issue #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 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
|
1110 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
|
1111 |
|
6de3de3ab71f
Issue #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 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
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 |
|
6de3de3ab71f
Issue #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 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
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 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
|
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 def select(self): |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1127 '''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
|
1128 |
|
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1129 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
|
1130 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
|
1131 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
|
1132 print ('Unable to select frame: ' |
|
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1133 '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
|
1134 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
|
1135 self._gdbframe.select() |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1136 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
|
1137 |
|
6de3de3ab71f
Issue #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 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
|
1139 '''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
|
1140 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
|
1141 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
|
1142 # 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
|
1143 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
|
1144 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
|
1145 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
|
1146 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
|
1147 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
|
1148 |
|
6de3de3ab71f
Issue #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 def is_evalframeex(self): |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1150 '''Is this a PyEval_EvalFrameEx 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
|
1151 if self._gdbframe.function(): |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1152 if self._gdbframe.name() == 'PyEval_EvalFrameEx': |
|
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
|
1153 ''' |
|
6de3de3ab71f
Issue #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 I believe we also need to filter on the inline |
|
6de3de3ab71f
Issue #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 struct frame_id.inline_depth, only regarding frames 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
|
1156 an inline depth of 0 as actually being this function |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 So we reject those with type gdb.INLINE_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
|
1159 ''' |
|
6de3de3ab71f
Issue #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 if self._gdbframe.type() == gdb.NORMAL_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
|
1161 # We have a PyEval_EvalFrameEx 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
|
1162 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
|
1163 |
|
6de3de3ab71f
Issue #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 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
|
1165 |
|
6de3de3ab71f
Issue #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 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
|
1167 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
|
1168 f = self._gdbframe.read_var('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
|
1169 return PyFrameObjectPtr.from_pyobject_ptr(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
|
1170 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
|
1171 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
|
1172 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1173 @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
|
1174 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
|
1175 _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
|
1176 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
|
1177 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
|
1178 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
|
1179 |
|
6de3de3ab71f
Issue #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 @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
|
1181 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
|
1182 '''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
|
1183 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
|
1184 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
|
1185 |
|
6de3de3ab71f
Issue #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 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
|
1187 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
|
1188 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
|
1189 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
|
1190 |
|
6de3de3ab71f
Issue #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 # 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
|
1192 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
|
1193 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 sys.stdout.write('#%i %s\n' % (self.get_index(), 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
|
1199 sys.stdout.write(pyop.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
|
1200 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
|
1201 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
|
1202 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
|
1203 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
|
1204 |
|
6de3de3ab71f
Issue #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 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
|
1206 '''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
|
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 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
|
1209 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
|
1210 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
|
1211 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1212 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
|
1213 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
|
1214 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
|
1215 ''' |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1216 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1217 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
|
1218 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
|
1219 "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
|
1220 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
|
1221 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
|
1222 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1223 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1224 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
|
1225 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
|
1226 |
|
6de3de3ab71f
Issue #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 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
|
1228 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
|
1229 |
|
6de3de3ab71f
Issue #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 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
|
1231 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
|
1232 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
|
1233 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
|
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 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
|
1236 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
|
1237 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
|
1238 |
|
6de3de3ab71f
Issue #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 = 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
|
1240 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
|
1241 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
|
1242 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
|
1243 |
|
6de3de3ab71f
Issue #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 pyop = 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
|
1245 if not 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
|
1246 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
|
1247 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
|
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 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
|
1250 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
|
1251 |
|
6de3de3ab71f
Issue #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 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
|
1253 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
|
1254 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
|
1255 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1256 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
|
1257 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
|
1258 |
|
6de3de3ab71f
Issue #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 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
|
1260 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
|
1261 # 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
|
1262 # 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
|
1263 # 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
|
1264 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
|
1265 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
|
1266 # 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
|
1267 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
|
1268 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
|
1269 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
|
1270 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 # ...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
|
1273 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
|
1274 |
|
6de3de3ab71f
Issue #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 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
|
1276 '''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
|
1277 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
|
1278 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
|
1279 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
|
1280 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
|
1281 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
|
1282 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
|
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 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
|
1285 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
|
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 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
|
1288 # Result: |
|
60664
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1289 if iter_frame.select(): |
|
d7d5c76545fb
Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents:
60125
diff
changeset
|
1290 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
|
1291 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
|
1292 |
|
6de3de3ab71f
Issue #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 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
|
1294 |
|
6de3de3ab71f
Issue #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 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
|
1296 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
|
1297 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
|
1298 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
|
1299 |
|
6de3de3ab71f
Issue #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 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
|
1301 '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
|
1302 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
|
1303 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
|
1304 "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
|
1305 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
|
1306 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
|
1307 |
|
6de3de3ab71f
Issue #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 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
|
1310 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
|
1311 |
|
6de3de3ab71f
Issue #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 PyUp() |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1315 '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
|
1316 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
|
1317 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
|
1318 "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
|
1319 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
|
1320 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
|
1321 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1324 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
|
1325 |
|
6de3de3ab71f
Issue #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 PyDown() |
|
6de3de3ab71f
Issue #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 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
|
1329 '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
|
1330 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
|
1331 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
|
1332 "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
|
1333 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
|
1334 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
|
1335 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1338 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
|
1339 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
|
1340 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
|
1341 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
|
1342 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
|
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 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
|
1345 |
|
6de3de3ab71f
Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1346 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
|
1347 '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
|
1348 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
|
1349 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
|
1350 "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
|
1351 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
|
1352 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
|
1353 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1356 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
|
1357 |
|
6de3de3ab71f
Issue #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 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
|
1359 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
|
1360 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
|
1361 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
|
1362 |
|
6de3de3ab71f
Issue #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 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
|
1364 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
|
1365 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
|
1366 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
|
1367 |
|
6de3de3ab71f
Issue #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 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
|
1369 |
|
6de3de3ab71f
Issue #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 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
|
1371 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
|
1372 % (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
|
1373 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
|
1374 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
|
1375 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
|
1376 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
|
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 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
|
1379 |
|
6de3de3ab71f
Issue #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 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
|
1381 '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
|
1382 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
|
1383 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
|
1384 "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
|
1385 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
|
1386 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
|
1387 |
|
6de3de3ab71f
Issue #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 |
|
6de3de3ab71f
Issue #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 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
|
1390 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
|
1391 |
|
6de3de3ab71f
Issue #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 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
|
1393 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
|
1394 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
|
1395 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
|
1396 |
|
6de3de3ab71f
Issue #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 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
|
1398 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
|
1399 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
|
1400 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
|
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 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
|
1403 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
|
1404 % (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
|
1405 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
|
1406 |
|
6de3de3ab71f
Issue #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 PyLocals() |
