annotate Tools/gdb/libpython.py @ 63014:18bdc43ce5ed 2.7

Merged revisions 82872,82874 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82872 | georg.brandl | 2010-07-14 10:53:18 +0200 (Mi, 14 Jul 2010) | 1 line Remove XXX from text. ........ r82874 | georg.brandl | 2010-07-14 10:54:40 +0200 (Mi, 14 Jul 2010) | 1 line #9235: fix missing import of sys. ........
author Georg Brandl <georg@python.org>
date Wed, 14 Jul 2010 08:55:55 +0000
parents 5d6b76890f17
children 1322266f9611
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 #!/usr/bin/python
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
4 to be extended with Python code e.g. for library-specific data visualizations,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
5 such as for the C++ STL types. Documentation on this API can be seen at:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
6 http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
7
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
9 This python module deals with the case when the process being debugged (the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
10 "inferior process" in gdb parlance) is itself python, or more specifically,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
11 linked against libpython. In this situation, almost every item of data is a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12 (PyObject*), and having the debugger merely print their addresses is not very
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
13 enlightening.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
14
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
15 This module embeds knowledge about the implementation details of libpython so
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16 that we can emit useful visualizations e.g. a string, a list, a dict, a frame
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
17 giving file/line information and the state of local variables
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
18
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 In particular, given a gdb.Value corresponding to a PyObject* in the inferior
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
20 process, we can generate a "proxy value" within the gdb process. For example,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
21 given a PyObject* in the inferior process that is in fact a PyListObject*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22 holding three PyObject* that turn out to be PyStringObject* instances, we can
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
23 generate a proxy value within the gdb process that is a list of strings:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
24 ["foo", "bar", "baz"]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
26 Doing so can be expensive for complicated graphs of objects, and could take
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 some time, so we also have a "write_repr" method that writes a representation
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
28 of the data to a file-like object. This allows us to stop the traversal by
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 having the file-like object raise an exception if it gets too much data.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
30
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
31 With both "proxyval" and "write_repr" we keep track of the set of all addresses
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
32 visited so far in the traversal, to avoid infinite recursion due to cycles in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
33 the graph of object references.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
35 We try to defer gdb.lookup_type() invocations for python types until as late as
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
36 possible: for a dynamically linked python binary, when the process starts in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
37 the debugger, the libpython.so hasn't been dynamically loaded yet, so none of
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
38 the type names are known to the debugger
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
39
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
40 The module also extends gdb with some python-specific commands.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
41 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
42 from __future__ import with_statement
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
43 import gdb
63014
18bdc43ce5ed Merged revisions 82872,82874 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61770
diff changeset
44 import sys
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
45
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
46 # Look up the gdb.Type for some standard types:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
47 _type_char_ptr = gdb.lookup_type('char').pointer() # char*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
48 _type_unsigned_char_ptr = gdb.lookup_type('unsigned char').pointer() # unsigned char*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
49 _type_void_ptr = gdb.lookup_type('void').pointer() # void*
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
50 _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
51
6de3de3ab71f Issue #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 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
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
6de3de3ab71f Issue #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 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
56
6de3de3ab71f Issue #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_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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
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
6de3de3ab71f Issue #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 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
69
6de3de3ab71f Issue #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 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
71 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
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
6de3de3ab71f Issue #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 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
75 # 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
76 # 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
77 # 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
78 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
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
6de3de3ab71f Issue #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 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
82 # 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
83 # 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
84 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
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
6de3de3ab71f Issue #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 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
88 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
89
6de3de3ab71f Issue #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 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
91 '''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
92 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
93 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
94 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
95 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
96
6de3de3ab71f Issue #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 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
98 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
99 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
100 # 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
101 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
102 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
103
6de3de3ab71f Issue #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 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
105
6de3de3ab71f Issue #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 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
107 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
108
6de3de3ab71f Issue #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 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
110 """
6de3de3ab71f Issue #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 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
112 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
113
6de3de3ab71f Issue #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 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
115 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
116
6de3de3ab71f Issue #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 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
118 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
119 """
6de3de3ab71f Issue #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 _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
121
6de3de3ab71f Issue #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 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
123 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
124 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
125 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
126 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
127
6de3de3ab71f Issue #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 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
129 '''
6de3de3ab71f Issue #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 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
131 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
132
6de3de3ab71f Issue #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 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
134 "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
135
6de3de3ab71f Issue #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 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
137 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
138
6de3de3ab71f Issue #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 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
140 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
141 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
142 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
143 '''
6de3de3ab71f Issue #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 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
145 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
146
6de3de3ab71f Issue #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 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
148 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
149 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
150
6de3de3ab71f Issue #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 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
152 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
153 # 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
154 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
155 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
156 # 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
157 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
158
6de3de3ab71f Issue #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 # 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
160 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
161
6de3de3ab71f Issue #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 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
163 '''
6de3de3ab71f Issue #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 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
165 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
166 '''
6de3de3ab71f Issue #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 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
168
6de3de3ab71f Issue #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 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
170 '''
6de3de3ab71f Issue #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 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
172 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
173 '''
6de3de3ab71f Issue #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 = 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
175 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
176
6de3de3ab71f Issue #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 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
178 '''
6de3de3ab71f Issue #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 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
180 (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
181 '''
6de3de3ab71f Issue #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 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
183 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
184 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
185 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
186 # 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
187 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
188
6de3de3ab71f Issue #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 # 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
190 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
191
6de3de3ab71f Issue #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 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
193 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
194
6de3de3ab71f Issue #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 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
196 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
197
6de3de3ab71f Issue #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 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
199 '''
6de3de3ab71f Issue #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 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
201
6de3de3ab71f Issue #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 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
203 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
204
6de3de3ab71f Issue #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 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
206 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
207 '''
6de3de3ab71f Issue #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 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
209
6de3de3ab71f Issue #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 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
211 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
212 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
213 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
214 # 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
215 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
216 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
217 # 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
218 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
219
6de3de3ab71f Issue #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 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
221 '''
6de3de3ab71f Issue #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 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
223 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
224 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
225
6de3de3ab71f Issue #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 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
227
6de3de3ab71f Issue #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 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
229 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
230
6de3de3ab71f Issue #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 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
232 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
233 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
234 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
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
6de3de3ab71f Issue #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 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
238 """
6de3de3ab71f Issue #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 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
240 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
241 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
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
6de3de3ab71f Issue #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 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
245 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
246 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
247
6de3de3ab71f Issue #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 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
249 # 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
250 # 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
251 # 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
252 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
253 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
254 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
255
6de3de3ab71f Issue #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 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
257 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
258
6de3de3ab71f Issue #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 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
260 '''
6de3de3ab71f Issue #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 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
262 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
263 '''
6de3de3ab71f Issue #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 # 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
265 # 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
266 # 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
267 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
268
6de3de3ab71f Issue #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 @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
270 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
271 '''
6de3de3ab71f Issue #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 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
273 (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
274 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
275
6de3de3ab71f Issue #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 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
277 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
278 (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
279 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
280 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
281 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
282 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
283
6de3de3ab71f Issue #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 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
285 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
286 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
287 '''
6de3de3ab71f Issue #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 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
289 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
290 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
291 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
292 # 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
293 # 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
294 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
295
6de3de3ab71f Issue #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_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
297 #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
298
6de3de3ab71f Issue #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 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
300 '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
301 '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
302 '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
303 '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
304 '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
305 '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
306 '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
307 }
6de3de3ab71f Issue #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 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
309 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
310
6de3de3ab71f Issue #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 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
312 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
313
6de3de3ab71f Issue #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 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 #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
331 # 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
332
6de3de3ab71f Issue #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 # 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
334 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
335
6de3de3ab71f Issue #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 @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
337 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
338 '''
6de3de3ab71f Issue #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 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
340 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
341 '''
6de3de3ab71f Issue #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 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
343 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
344 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
345 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
346 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
347 # 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
348 # 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
349 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
350 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
351
6de3de3ab71f Issue #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 @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
353 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
354 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
355
6de3de3ab71f Issue #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 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
357 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
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
6de3de3ab71f Issue #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 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
361 '''
6de3de3ab71f Issue #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 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
363 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
364
6de3de3ab71f Issue #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 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
366 '''
6de3de3ab71f Issue #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 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
368 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
369
6de3de3ab71f Issue #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 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
371 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
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
6de3de3ab71f Issue #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 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
375 '''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
376 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
377 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
378 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
379
6de3de3ab71f Issue #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 # 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
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
6de3de3ab71f Issue #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 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
396
6de3de3ab71f Issue #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 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
398 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
399 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
400 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
401
6de3de3ab71f Issue #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 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
403 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
404 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
405 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
406 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
407 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
408 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
409 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
410 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
411
6de3de3ab71f Issue #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 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
413 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
414 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
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 ) & ~(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
417 ).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
418
6de3de3ab71f Issue #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 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
420 _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
421
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
422 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
423 '''
6de3de3ab71f Issue #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 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
425 (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
426 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
427 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
428 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
429 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
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 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440
6de3de3ab71f Issue #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 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
442 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
443 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
444 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
445 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
446 # 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
447 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
448
6de3de3ab71f Issue #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 # 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
450 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
451
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
452 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
453 '''
6de3de3ab71f Issue #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 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
455
6de3de3ab71f Issue #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 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
457 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
458 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
459 # 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
460 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
461 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
462 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
463
6de3de3ab71f Issue #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 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
465 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
466 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
467 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
468 attr_dict = {}
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
469 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
470
6de3de3ab71f Issue #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 # 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
472 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
473
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
474 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
475 # 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
476 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
477 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
478 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
479 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
480
6de3de3ab71f Issue #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 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
482 _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
483 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
484
6de3de3ab71f Issue #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 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
486 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
487 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
488 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
489
6de3de3ab71f Issue #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 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
491 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
492
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
493 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
494 """
6de3de3ab71f Issue #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 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
496 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
497 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
498 _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
499
6de3de3ab71f Issue #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 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
501 # 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
502 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
503 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
504 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
505 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
506 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
507 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
508
6de3de3ab71f Issue #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 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
510 # 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
511 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
512 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
513 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
514 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
515
6de3de3ab71f Issue #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 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
517 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
518
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
519 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
520 """
6de3de3ab71f Issue #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 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
522 <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
523 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
524 _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
525
6de3de3ab71f Issue #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 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
527 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
528 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
529 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
530 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
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
6de3de3ab71f Issue #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 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
534 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
535 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
536 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
537 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
538 _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
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
6de3de3ab71f Issue #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 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
542 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
543 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
544
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
545 def __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
546 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
547
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
548 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
549 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
550 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
551 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
552
6de3de3ab71f Issue #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 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
554 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
555 % (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
556 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
557 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
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
6de3de3ab71f Issue #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 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
561 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
562 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
563 (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
564 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
565 _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
566
6de3de3ab71f Issue #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 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
568 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
569 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
570
6de3de3ab71f Issue #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 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
572 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
573 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
574 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
575 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
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
6de3de3ab71f Issue #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 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
579 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
580 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
581 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
582 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
583 _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
584
6de3de3ab71f Issue #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 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
586 '''
6de3de3ab71f Issue #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 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
588
6de3de3ab71f Issue #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 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
590 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
591 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
592 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
593
6de3de3ab71f Issue #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 # 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
595 # 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
596 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
597
6de3de3ab71f Issue #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 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
599 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
600 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
601 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
602 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
603 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
604 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
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
6de3de3ab71f Issue #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 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
608 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
609 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
610 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
611 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
612 _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
613
6de3de3ab71f Issue #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 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
615 '''
6de3de3ab71f Issue #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 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
617 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
618 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
619 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
620 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
621 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
622 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
623 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
624 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
625
6de3de3ab71f Issue #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 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
627 # 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
628 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
629 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
630 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
631
6de3de3ab71f Issue #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 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
633 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
634 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
635 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
636 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
637 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
638
6de3de3ab71f Issue #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 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
640 # 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
641 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
642 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
643 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
644 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
645
6de3de3ab71f Issue #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 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
647 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
648 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
649 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
650 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
651 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
652 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
653 out.write(': ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
654 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
655 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
656
6de3de3ab71f Issue #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 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
658 _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
659
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
660 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
661 # 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
662 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
663 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
664 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
665
6de3de3ab71f Issue #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 # 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
667 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
668 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
669
6de3de3ab71f Issue #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 # 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
671 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
672
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
673 # 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
674 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
675
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
676 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
677 # 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
678 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
679 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
680 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
681 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
682
6de3de3ab71f Issue #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 # 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
684
6de3de3ab71f Issue #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 # 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
686 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
687 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
688
6de3de3ab71f Issue #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 # 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
690 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
691
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
692 _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
693 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
694
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
695 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
696 _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
697
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
698 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
699 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
700 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
701
6de3de3ab71f Issue #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 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
703 _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
704
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
705 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
706 # 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
707 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
708 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
709
6de3de3ab71f Issue #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 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
711 # 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
712 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
713 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
714 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
715
6de3de3ab71f Issue #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 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
717 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
718 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
719
6de3de3ab71f Issue #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 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
721 # 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
722 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
723 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
724 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
725 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
726
6de3de3ab71f Issue #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 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
728 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
729 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
730 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
731 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
732 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
733 out.write(']')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
734
6de3de3ab71f Issue #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 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
736 _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
737
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
738 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
739 '''
6de3de3ab71f Issue #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 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
741 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
742 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
743 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
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
6de3de3ab71f Issue #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 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
747 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
748 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
749 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
750 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
751
6de3de3ab71f Issue #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 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
753 #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
754 #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
755 '''
6de3de3ab71f Issue #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 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
757 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
758 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
759
6de3de3ab71f Issue #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 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
761
6de3de3ab71f Issue #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 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
763 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
764 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
765 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
766
6de3de3ab71f Issue #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 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
768 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
769 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
770 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
771 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
772 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
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
6de3de3ab71f Issue #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 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
776 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
777 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
778 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
779 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
780 _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
781
6de3de3ab71f Issue #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 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
783 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
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
6de3de3ab71f Issue #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 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
787 _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
788
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
789 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
790 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
791
6de3de3ab71f Issue #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 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
793 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
794 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
795 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
796
6de3de3ab71f Issue #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_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
798 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
799 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
800 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
801
6de3de3ab71f Issue #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 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
803 '''
6de3de3ab71f Issue #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 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
805 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
806 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
807 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
808 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
809
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
810 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
811 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
812 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
813 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
814 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
815 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
816
6de3de3ab71f Issue #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 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
818 '''
6de3de3ab71f Issue #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 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
820 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
821 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
822 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
823 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
824
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
825 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
826 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
827
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
828 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
829 '''
6de3de3ab71f Issue #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 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
831 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
832 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
833 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
834 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
835
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
836 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
837 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
838
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
839 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
840 '''
6de3de3ab71f Issue #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 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
842 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
843
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
844 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
845 '''
6de3de3ab71f Issue #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 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
847 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
848 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
849 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
850 if name == pyop_name.proxyval(set()):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
851 return pyop_value, '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
852 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
853 if name == pyop_name.proxyval(set()):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
854 return pyop_value, '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
855 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
856
6de3de3ab71f Issue #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 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
858 '''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
859 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
860 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
861 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
862
6de3de3ab71f Issue #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 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
864 '''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
865
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
866 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
867
6de3de3ab71f Issue #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 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
869 '''
6de3de3ab71f Issue #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 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
871 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
872 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
873 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
874 # 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
875 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
876 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
877 #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
878 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
879 #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
880 # 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
881
6de3de3ab71f Issue #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 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
883 '''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
884 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
885 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
886 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
887 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
888 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
889 # 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
890 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
891
6de3de3ab71f Issue #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 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
893 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
894 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
895 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
896 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
897 % (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
898 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
899 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
900 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
901 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
902 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
903 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
904 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
905 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
906
6de3de3ab71f Issue #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(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
908 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
909 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
910
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
911 out.write(')')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
912
6de3de3ab71f Issue #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 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
914 _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
915
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
916 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
917 # 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
918 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
919 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
920 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
921
6de3de3ab71f Issue #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 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
923 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
924 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
925 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
926 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
927 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
928 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
929 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
930 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
931 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
932 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
933 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
934 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
935
6de3de3ab71f Issue #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 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
937 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
938
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
939 # 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
940 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
941 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
942 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
943 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
944
6de3de3ab71f Issue #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 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
946 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
947 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
948 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
949 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
950 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
951 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
952 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
953 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
954 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
955 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
956 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
957 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
958 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
959 out.write('])')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
960
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
963 _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
964
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
965 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
966 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
967 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
968 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
969 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
970
6de3de3ab71f Issue #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 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
972 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
973
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
974 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
975 _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
976
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
977 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
978 # 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
979 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
980 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
981
6de3de3ab71f Issue #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 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
983 # 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
984 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
985 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
986 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
987
6de3de3ab71f Issue #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 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
989 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
990 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
991
6de3de3ab71f Issue #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 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
993 # 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
994 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
995 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
996 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
997 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
998
6de3de3ab71f Issue #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 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
1000 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
1001 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
1002 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1003 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
1004 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
1005 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
1006 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
1007 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
1008 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
1009
6de3de3ab71f Issue #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 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
1011 _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
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
6de3de3ab71f Issue #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 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
1015 _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
1016
61770
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1017 def char_width(self):
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1018 _type_Py_UNICODE = gdb.lookup_type('Py_UNICODE')
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1019 return _type_Py_UNICODE.sizeof
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1020
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
1021 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
1022 # 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
1023 # 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
1024 # 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
1025 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
1026 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
1027
6de3de3ab71f Issue #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 # 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
1029 # 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
1030 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
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 # 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
1033 # 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
1034 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
1035 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
1036
61770
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1037 def write_repr(self, out, visited):
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1038 proxy = self.proxyval(visited)
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1039 if self.char_width() == 2:
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1040 # sizeof(Py_UNICODE)==2: join surrogates
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1041 proxy2 = []
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1042 i = 0
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1043 while i < len(proxy):
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1044 ch = proxy[i]
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1045 i += 1
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1046 if (i < len(proxy)
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1047 and 0xD800 <= ord(ch) < 0xDC00 \
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1048 and 0xDC00 <= ord(proxy[i]) <= 0xDFFF):
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1049 # Get code point from surrogate pair
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1050 ch2 = proxy[i]
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1051 code = (ord(ch) & 0x03FF) << 10
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1052 code |= ord(ch2) & 0x03FF
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1053 code += 0x00010000
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1054 i += 1
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1055 proxy2.append(unichr(code))
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1056 else:
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1057 proxy2.append(ch)
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1058 proxy = u''.join(proxy2)
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1059 out.write(repr(proxy))
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60791
diff changeset
1060
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
1061
6de3de3ab71f Issue #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 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
1063 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
1064
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1067 # 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
1068 # 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
1069 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
1070 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
1071 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
1072 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
1073 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
1074
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1075
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1076 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
1077 "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
1078
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1079 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
1080 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
1081
6de3de3ab71f Issue #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 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
1083 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
1084 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
1085 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
1086 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
1087 # 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
1088 # 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
1089 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
1090 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
1091
6de3de3ab71f Issue #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 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1100 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1101 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
1102 (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
1103
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1104 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
1105 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
1106 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
1107 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
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 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
1110 (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
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 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
1113 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
1114 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
1115 .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
1116 /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
1117 /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
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 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
1120 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
1121 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
1122
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1123 # 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
1124 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
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 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
1127
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1128
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1129
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1130 # 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
1131 # from build to build
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1132 # 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
1133
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
1134 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
1135 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1136 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
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 __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
1139 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
1140
6de3de3ab71f Issue #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 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
1142 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
1143 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
1144 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
1145 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
1146 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
1147
6de3de3ab71f Issue #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 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
1149 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
1150 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
1151 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
1152 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
1153 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
1154
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1155 def select(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1156 '''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
1157
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1158 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
1159 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
1160 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
1161 print ('Unable to select frame: '
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1162 '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
1163 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
1164 self._gdbframe.select()
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1165 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
1166
6de3de3ab71f Issue #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 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
1168 '''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
1169 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
1170 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
1171 # 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
1172 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
1173 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
1174 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
1175 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
1176 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
1177
6de3de3ab71f Issue #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 def is_evalframeex(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1179 '''Is this a PyEval_EvalFrameEx frame?'''
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1180 if self._gdbframe.name() == 'PyEval_EvalFrameEx':
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1181 '''
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1182 I believe we also need to filter on the inline
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1183 struct frame_id.inline_depth, only regarding frames with
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1184 an inline depth of 0 as actually being this function
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1185
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1186 So we reject those with type gdb.INLINE_FRAME
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1187 '''
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1188 if self._gdbframe.type() == gdb.NORMAL_FRAME:
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1189 # We have a PyEval_EvalFrameEx frame:
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1190 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
1191
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1192 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
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 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
1195 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
1196 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
1197 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
1198 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
1199 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
1200
6de3de3ab71f Issue #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 @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
1202 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
1203 _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
1204 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
1205 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
1206 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
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 @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
1209 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
1210 '''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
1211 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
1212 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
1213
6de3de3ab71f Issue #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 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
1215 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
1216 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
1217 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
1218
6de3de3ab71f Issue #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 # 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
1220 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
1221
6de3de3ab71f Issue #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 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
1223 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
1224 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
1225 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
1226 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
1227 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
1228 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
1229 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
1230 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
1231 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
1232
6de3de3ab71f Issue #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 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
1234 '''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
1235
6de3de3ab71f Issue #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 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
1237 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
1238 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
1239
6de3de3ab71f Issue #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 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
1241 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
1242 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
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
6de3de3ab71f Issue #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 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
1246 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
1247 "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
1248 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
1249 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
1250
6de3de3ab71f Issue #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 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
1253 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
1254
6de3de3ab71f Issue #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 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
1256 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
1257
6de3de3ab71f Issue #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 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
1259 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
1260 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
1261 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
1262
6de3de3ab71f Issue #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 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
1264 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
1265 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
1266
6de3de3ab71f Issue #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 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
1268 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
1269 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
1270 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
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 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
1273 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
1274 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
1275 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
1276
6de3de3ab71f Issue #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 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
1278 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
1279
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1280 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
1281 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
1282 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
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 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
1285 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
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 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
1288 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
1289 # 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
1290 # 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
1291 # 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
1292 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
1293 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
1294 # 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
1295 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
1296 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
1297 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
1298
6de3de3ab71f Issue #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 # ...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
1301 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
1302
6de3de3ab71f Issue #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 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
1304 '''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
1305 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
1306 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
1307 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
1308 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
1309 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
1310 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
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 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
1313 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
1314
6de3de3ab71f Issue #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 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
1316 # Result:
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1317 if iter_frame.select():
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60125
diff changeset
1318 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
1319 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
1320
6de3de3ab71f Issue #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 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
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 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
1324 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
1325 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
1326 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
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 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
1329 '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
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-up",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1333 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 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
1339
6de3de3ab71f Issue #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 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
1341 '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
1342 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
1343 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
1344 "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
1345 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
1346 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
1347
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1350 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
1351
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1352 # Not all builds of gdb have gdb.Frame.select
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1353 if hasattr(gdb.Frame, 'select'):
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1354 PyUp()
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
1355 PyDown()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1356
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1357 class 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
1358 '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
1359 def __init__(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1360 gdb.Command.__init__ (self,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1361 "py-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
1362 gdb.COMMAND_STACK,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1363 gdb.COMPLETE_NONE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1364
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1365
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1366 def invoke(self, args, from_tty):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1367 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
1368 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
1369 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
1370 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
1371 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
1372
6de3de3ab71f Issue #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 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
1374
6de3de3ab71f Issue #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 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
1376 '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
1377 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
1378 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
1379 "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
1380 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
1381 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
1382
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1385 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
1386
6de3de3ab71f Issue #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 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
1388 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
1389 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
1390 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
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 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
1393 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
1394 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
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_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
1398
6de3de3ab71f Issue #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 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
1400 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
1401 % (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
1402 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
1403 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
1404 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
1405 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
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 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
1408
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1409 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
1410 '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
1411 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
1412 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
1413 "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
1414 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
1415 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
1416
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1417
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1418 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
1419 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
1420
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1421 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
1422 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
1423 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
1424 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1425
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1426 pyop_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
1427 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
1428 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
1429 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
1430
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1431 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
1432 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
1433 % (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
1434 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
1435
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1436 PyLocals()