annotate Tools/gdb/libpython.py @ 83254:91a57079afbb

python-gdb.py: Replace invalid Unicode character with U+FFFD to be able to display invalid strings. Such strings can be found while Python is creating a new string, in a text decoder for example, when Python is compiled in debug mode.
author Victor Stinner <victor.stinner@gmail.com>
date Thu, 11 Apr 2013 21:37:45 +0200
parents 07488c3c85f1
children 6d971b172389
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*
60812
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
22 holding three PyObject* that turn out to be PyBytesObject* instances, we can
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
23 generate a proxy value within the gdb process that is a list of bytes
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
24 instances:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
25 [b"foo", b"bar", b"baz"]
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
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
27 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
28 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
29 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
30 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
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
32 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
33 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
34 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
35
6de3de3ab71f Issue #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 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
37 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
38 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
39 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
40
6de3de3ab71f Issue #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 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
42 '''
6de3de3ab71f Issue #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 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
44 import gdb
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
45 import locale
63012
d30b9dffb86d #9235: fix missing import of sys.
Georg Brandl <georg@python.org>
parents: 63011
diff changeset
46 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
47
6de3de3ab71f Issue #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 # 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
49 _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
50 _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
51 _type_void_ptr = gdb.lookup_type('void').pointer() # void*
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
52 _type_unsigned_short_ptr = gdb.lookup_type('unsigned short').pointer()
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
53 _type_unsigned_int_ptr = gdb.lookup_type('unsigned int').pointer()
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
54
73885
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
55 # value computed later, see PyUnicodeObjectPtr.proxy()
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
56 _is_pep393 = None
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
57
6de3de3ab71f Issue #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 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
59
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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_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
62
6de3de3ab71f Issue #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_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
64 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
65 Py_TPFLAGS_TUPLE_SUBCLASS = (1L << 26)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
66 Py_TPFLAGS_BYTES_SUBCLASS = (1L << 27)
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
67 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
68 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
69 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
70 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
71
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
72
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
73 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
74
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
75 hexdigits = "0123456789abcdef"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
76
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
77 ENCODING = locale.getpreferredencoding()
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
78
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
79 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
80 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
81
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
84 # 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
85 # 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
86 # 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
87 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
88
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
89
6de3de3ab71f Issue #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 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
91 # 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
92 # 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
93 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
94
64134
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
95 def write_unicode(file, text):
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
96 # Write a byte or unicode string to file. Unicode strings are encoded to
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
97 # ENCODING encoding with 'backslashreplace' error handler to avoid
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
98 # UnicodeEncodeError.
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
99 if isinstance(text, unicode):
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
100 text = text.encode(ENCODING, 'backslashreplace')
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
101 file.write(text)
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
102
65485
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
103 def os_fsencode(filename):
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
104 if not isinstance(filename, unicode):
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
105 return filename
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
106 encoding = sys.getfilesystemencoding()
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
107 if encoding == 'mbcs':
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
108 # mbcs doesn't support surrogateescape
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
109 return filename.encode(encoding)
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
110 encoded = []
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
111 for char in filename:
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
112 # surrogateescape error handler
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
113 if 0xDC80 <= ord(char) <= 0xDCFF:
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
114 byte = chr(ord(char) - 0xDC00)
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
115 else:
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
116 byte = char.encode(encoding)
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
117 encoded.append(byte)
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
118 return ''.join(encoded)
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
119
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
120 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
121 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
122
6de3de3ab71f Issue #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 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
124 '''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
125 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
126 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
127 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
128 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
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 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
131 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
132 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
133 # 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
134 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
135 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
136
6de3de3ab71f Issue #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 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
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 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
140 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
141
6de3de3ab71f Issue #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 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
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 Class wrapping a gdb.Value that's a either a (PyObject*) within the
60812
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
145 inferior process, or some subclass pointer e.g. (PyBytesObject*)
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
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 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
148 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
149
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
150 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
151 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
152 """
6de3de3ab71f Issue #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 _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
154
6de3de3ab71f Issue #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 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
156 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
157 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
158 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
159 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
160
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
161 def field(self, name):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
162 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
163 Get 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
164 some python 2 versus python 3 differences.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
165
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
166 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
167 "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
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 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
170 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
171
6de3de3ab71f Issue #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 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
173 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
174 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
175 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
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 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
178 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
179
6de3de3ab71f Issue #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 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
181 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
182 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
183
6de3de3ab71f Issue #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 if name == 'ob_size':
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
185 pyo_ptr = self._gdbval.cast(PyVarObjectPtr.get_gdb_type())
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
186 return pyo_ptr.dereference()[name]
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
187
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
188 # 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
189 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
190
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
191 def 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
192 '''
6de3de3ab71f Issue #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 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
194 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
195 '''
6de3de3ab71f Issue #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 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
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 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
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 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
201 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
202 '''
6de3de3ab71f Issue #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 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
204 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
205
6de3de3ab71f Issue #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 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
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 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
209 (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
210 '''
6de3de3ab71f Issue #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 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
212 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
213 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
214 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
215 # 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
216 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
217
6de3de3ab71f Issue #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 # 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
219 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
220
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
221 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
222 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
223
6de3de3ab71f Issue #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 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
225 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
226
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
227 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
228 '''
6de3de3ab71f Issue #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 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
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 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
232 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
233
6de3de3ab71f Issue #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 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
235 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
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 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
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 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
240 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
241 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
242 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
243 # 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
244 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
245 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
246 # 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
247 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
248
6de3de3ab71f Issue #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 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
250 '''
6de3de3ab71f Issue #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 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
252 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
253 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
254
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
255 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
256
6de3de3ab71f Issue #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 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
258 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
259
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
260 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
261 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
262 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
263 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
264 '''
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
267 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
268 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
269 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
270 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
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
6de3de3ab71f Issue #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 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
274 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
275 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
276
6de3de3ab71f Issue #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 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
278 # 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
279 # 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
280 # 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
281 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
282 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
283 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
284
6de3de3ab71f Issue #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 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
286 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
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 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
289 '''
6de3de3ab71f Issue #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 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
291 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
292 '''
6de3de3ab71f Issue #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 # 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
294 # 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
295 # 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
296 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
297
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
298 @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
299 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
300 '''
6de3de3ab71f Issue #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 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
302 (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
303 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
304
6de3de3ab71f Issue #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 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
306 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
307 (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
308 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
309 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
310 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
311 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
312
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
313 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
314 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
315 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
316 '''
6de3de3ab71f Issue #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 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
318 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
319 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
320 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
321 # 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
322 # 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
323 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
324
6de3de3ab71f Issue #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 #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
326 #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
327
6de3de3ab71f Issue #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 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
329 '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
330 '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
331 '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
332 '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
333 '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
334 '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
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 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
337 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
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 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
340 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
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 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
343 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
344 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
345 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
346 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
347 return PyTupleObjectPtr
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
348 if tp_flags & Py_TPFLAGS_BYTES_SUBCLASS:
60812
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
349 return PyBytesObjectPtr
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
350 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
351 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
352 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
353 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
354 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
355 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
356 #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
357 # 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
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 # 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
360 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
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 @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
363 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
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 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
366 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
367 '''
6de3de3ab71f Issue #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 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
369 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
370 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
371 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
372 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
373 # 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
374 # 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
375 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
376 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
377
6de3de3ab71f Issue #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 @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
379 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
380 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
381
6de3de3ab71f Issue #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 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
383 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
384
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
385 class PyVarObjectPtr(PyObjectPtr):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
386 _typename = 'PyVarObject'
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
387
6de3de3ab71f Issue #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 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
389 '''
6de3de3ab71f Issue #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 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
391 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
392
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
393 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
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 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
396 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
397
6de3de3ab71f Issue #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 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
399 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
400
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
401
6de3de3ab71f Issue #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 _write_instance_repr(out, visited, name, pyop_attrdict, address):
73949
021e5bb297d1 Issue #13575: there is only one class type.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73885
diff changeset
403 '''Shared code for use by all classes:
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
404 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
405 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
406 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
407
6de3de3ab71f Issue #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 # 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
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
6de3de3ab71f Issue #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 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
424
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
425 def __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
426 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
427 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
428 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
429
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
440 def _PyObject_VAR_SIZE(typeobj, nitems):
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
441 if _PyObject_VAR_SIZE._type_size_t is None:
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
442 _PyObject_VAR_SIZE._type_size_t = gdb.lookup_type('size_t')
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
443
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
444 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
445 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
446 (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
447 ) & ~(SIZEOF_VOID_P - 1)
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
448 ).cast(_PyObject_VAR_SIZE._type_size_t)
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
449 _PyObject_VAR_SIZE._type_size_t = None
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
450
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
451 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
452 _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
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 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
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 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
457 (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
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 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
460 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
461 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
462 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
463 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
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
473 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
474 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
475 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
476 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
477 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
478 # 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
479 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
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 # 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
482 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
483
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
484 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
485 '''
73949
021e5bb297d1 Issue #13575: there is only one class type.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73885
diff changeset
486 Support for classes.
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
487
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
488 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
489 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
490 '''
6de3de3ab71f Issue #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 # 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
492 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
493 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
494 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
495
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
496 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
497 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
498 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
499 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
500 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
501 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
502
73949
021e5bb297d1 Issue #13575: there is only one class type.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73885
diff changeset
503 # Class:
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
504 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
505
6de3de3ab71f Issue #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 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
507 # 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
508 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
509 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
510 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
511 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
512
6de3de3ab71f Issue #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 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
514 _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
515 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
516
6de3de3ab71f Issue #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 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
518 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
519 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
520 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
521
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
522 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
523 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
524
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
525 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
526 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
527 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
528 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
529 """
6de3de3ab71f Issue #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 _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
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 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
533 # 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
534 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
535 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
536 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
537 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
538 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
539 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
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 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
542 # 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
543 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
544 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
545 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
546 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
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 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
549 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
550
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
551 class 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
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 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
554 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
555 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
556 _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
557
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
558
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
559 class 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
560 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
561 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
562
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
563 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
564 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
565
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
566 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
567 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
568 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
569 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
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 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
572 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
573 % (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
574 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
575 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
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 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
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 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
581 (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
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 = '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
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 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
586 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
587 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
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 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
590 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
591 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
592 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
593 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
594
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
595
6de3de3ab71f Issue #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 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
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 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
599 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
600 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
601 _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
602
6de3de3ab71f Issue #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 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
604 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
605 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
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 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
608 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
609 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
610 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
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 # 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
613 # 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
614 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
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 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
617 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
618 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
619 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
620 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
621 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
622 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
623
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
624
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
625 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
626 """
6de3de3ab71f Issue #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 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
628 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
629 """
6de3de3ab71f Issue #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 _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
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 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
633 '''
6de3de3ab71f Issue #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 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
635 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
636 '''
76485
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
637 keys = self.field('ma_keys')
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
638 values = self.field('ma_values')
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
639 for i in safe_range(keys['dk_size']):
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
640 ep = keys['dk_entries'].address + i
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
641 if long(values):
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
642 pyop_value = PyObjectPtr.from_pyobject_ptr(values[i])
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
643 else:
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
644 pyop_value = PyObjectPtr.from_pyobject_ptr(ep['me_value'])
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
645 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
646 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
647 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
648
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
649 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
650 # 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
651 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
652 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
653 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
654
6de3de3ab71f Issue #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 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
656 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
657 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
658 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
659 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
660 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
661
6de3de3ab71f Issue #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 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
663 # 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
664 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
665 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
666 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
667 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
668
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
669 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
670 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
671 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
672 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
673 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
674 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
675 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
676 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
677 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
678 out.write('}')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
679
6de3de3ab71f Issue #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 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
681 _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
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 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
684 # 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
685 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
686 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
687
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
688 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
689 # 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
690 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
691 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
692 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
693
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
694 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
695 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
696 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
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 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
699 # 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
700 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
701 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
702 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
703 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
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 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
706 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
707 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
708 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
709 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
710 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
711 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
712
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
713 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
714 _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
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 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
717 '''
6de3de3ab71f Issue #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 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
719 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
720 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
721 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
722 };
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
723
6de3de3ab71f Issue #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 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
725 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
726 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
727 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
728 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
729
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
730 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
731 #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
732 #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
733 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
734 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
735 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
736 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
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 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
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 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
741 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
742 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
743 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
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 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
746 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
747 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
748 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
749 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
750 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
751
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
752 def write_repr(self, out, visited):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
753 # Write this out as a Python 3 int literal, i.e. without the "L" suffix
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
754 proxy = self.proxyval(visited)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
755 out.write("%s" % proxy)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
756
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
757
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
758 class PyBoolObjectPtr(PyLongObjectPtr):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
759 """
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
760 Class wrapping a gdb.Value that's a PyBoolObject* i.e. one of the two
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
761 <bool> instances (Py_True/Py_False) within the process being debugged.
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
762 """
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
763 def proxyval(self, visited):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
764 if PyLongObjectPtr.proxyval(self, visited):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
765 return True
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
766 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
767 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
768
6de3de3ab71f Issue #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 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
770 """
6de3de3ab71f Issue #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 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
772 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
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 _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
775
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
776 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
777 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
778
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
779
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
780 class 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
781 _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
782
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
783 def __init__(self, gdbval, cast_to=None):
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
784 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
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 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
787 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
788 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
789 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
790
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
791 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
792 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
793 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
794 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
795
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
796 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
797 '''
6de3de3ab71f Issue #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 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
799 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
800 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
801 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
802 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
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 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
805 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
806 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
807 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
808 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
809 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
810
6de3de3ab71f Issue #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 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
812 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
813 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
814 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
815 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
816 if self.is_optimized_out():
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
817 return ()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
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 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
820 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
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 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
823 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
824 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
825 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
826 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
827 if self.is_optimized_out():
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
828 return ()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
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 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
831 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
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 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
834 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
835 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
836 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
837
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
838 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
839 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
840 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
841 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
842 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
843 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
844 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
845 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
846 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
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, '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
849 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
850
6de3de3ab71f Issue #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 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
852 '''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
853 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
854 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
855 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
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 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
858 '''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
859
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
860 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
861
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
862 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
863 '''
6de3de3ab71f Issue #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 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
865 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
866 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
867 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
868 # 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
869 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
870 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
871 #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
872 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
873 #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
874 # return self.f_lineno
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
875
6de3de3ab71f Issue #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 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
877 '''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
878 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
879 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
880 return '(frame information optimized out)'
65485
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
881 filename = self.filename()
71106
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
882 try:
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
883 f = open(os_fsencode(filename), 'r')
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
884 except IOError:
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
885 return None
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
886 with f:
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
887 all_lines = f.readlines()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
888 # Convert from 1-based current_line_num to 0-based list offset:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
889 return all_lines[self.current_line_num()-1]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
890
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
891 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
892 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
893 out.write('(frame information optimized out)')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
894 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
895 out.write('Frame 0x%x, for file %s, line %i, in %s ('
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
896 % (self.as_address(),
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
897 self.co_filename.proxyval(visited),
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
898 self.current_line_num(),
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
899 self.co_name.proxyval(visited)))
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
900 first = True
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
901 for pyop_name, pyop_value in self.iter_locals():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
902 if not first:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
903 out.write(', ')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
904 first = False
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
905
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
906 out.write(pyop_name.proxyval(visited))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
907 out.write('=')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
908 pyop_value.write_repr(out, visited)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
909
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
910 out.write(')')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
911
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
912 def print_traceback(self):
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
913 if self.is_optimized_out():
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
914 sys.stdout.write(' (frame information optimized out)\n')
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
915 return
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
916 visited = set()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
917 sys.stdout.write(' File "%s", line %i, in %s\n'
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
918 % (self.co_filename.proxyval(visited),
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
919 self.current_line_num(),
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
920 self.co_name.proxyval(visited)))
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
921
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
922 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
923 _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
924
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
925 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
926 # 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
927 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
928 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
929 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
930
6de3de3ab71f Issue #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 members = []
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
932 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
933 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
934 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
935 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
936 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
937 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
938 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
939 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
940 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
941 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
942 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
943 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
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 def write_repr(self, out, visited):
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
946 # Emulate Python 3's set_repr
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
947 tp_name = self.safe_tp_name()
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
948
6de3de3ab71f Issue #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 # 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
950 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
951 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
952 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
953 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
954
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
955 # Python 3's set_repr special-cases the empty set:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
956 if not self.field('used'):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
957 out.write(tp_name)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
958 out.write('()')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
959 return
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
960
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
961 # Python 3 uses {} for set literals:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
962 if tp_name != 'set':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
963 out.write(tp_name)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
964 out.write('(')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
965
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
966 out.write('{')
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
967 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
968 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
969 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
970 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
971 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
972 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
973 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
974 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
975 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
976 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
977 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
978 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
979 pyop_key.write_repr(out, visited)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
980 out.write('}')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
981
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
982 if tp_name != 'set':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
983 out.write(')')
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
984
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
985
60812
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
986 class PyBytesObjectPtr(PyObjectPtr):
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
987 _typename = 'PyBytesObject'
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
988
6de3de3ab71f Issue #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 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
990 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
991 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
992 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
993 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
994
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
995 def 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
996 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
997
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
998 def write_repr(self, out, visited):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
999 # Write this out as a Python 3 bytes literal, i.e. with a "b" prefix
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1000
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1001 # Get a PyStringObject* within the Python 2 gdb process:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1002 proxy = self.proxyval(visited)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1003
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1004 # Transliteration of Python 3's Objects/bytesobject.c:PyBytes_Repr
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1005 # to Python 2 code:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1006 quote = "'"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1007 if "'" in proxy and not '"' in proxy:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1008 quote = '"'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1009 out.write('b')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1010 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1011 for byte in proxy:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1012 if byte == quote or byte == '\\':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1013 out.write('\\')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1014 out.write(byte)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1015 elif byte == '\t':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1016 out.write('\\t')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1017 elif byte == '\n':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1018 out.write('\\n')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1019 elif byte == '\r':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1020 out.write('\\r')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1021 elif byte < ' ' or ord(byte) >= 0x7f:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1022 out.write('\\x')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1023 out.write(hexdigits[(ord(byte) & 0xf0) >> 4])
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1024 out.write(hexdigits[ord(byte) & 0xf])
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1025 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1026 out.write(byte)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1027 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1028
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1029 class 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
1030 _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
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 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
1033 # 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
1034 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
1035 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
1036
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1037 def 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
1038 # 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
1039 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
1040 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
1041 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
1042
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1043 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
1044 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
1045 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
1046
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1047 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
1048 # 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
1049 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
1050 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
1051 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
1052 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
1053
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1054 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
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 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
1063 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
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 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
1066 _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
1067
6de3de3ab71f Issue #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
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1069 def _unichr_is_printable(char):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1070 # Logic adapted from Python 3's Tools/unicode/makeunicodedata.py
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1071 if char == u" ":
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1072 return True
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1073 import unicodedata
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1074 return unicodedata.category(char) not in ("C", "Z")
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1075
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1076 if sys.maxunicode >= 0x10000:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1077 _unichr = unichr
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1078 else:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1079 # Needed for proper surrogate support if sizeof(Py_UNICODE) is 2 in gdb
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1080 def _unichr(x):
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1081 if x < 0x10000:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1082 return unichr(x)
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1083 x -= 0x10000
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1084 ch1 = 0xD800 | (x >> 10)
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1085 ch2 = 0xDC00 | (x & 0x3FF)
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1086 return unichr(ch1) + unichr(ch2)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1087
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1088
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
1089 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
1090 _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
1091
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1092 def char_width(self):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1093 _type_Py_UNICODE = gdb.lookup_type('Py_UNICODE')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1094 return _type_Py_UNICODE.sizeof
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1095
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
1096 def proxyval(self, visited):
73885
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
1097 global _is_pep393
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
1098 if _is_pep393 is None:
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
1099 fields = gdb.lookup_type('PyUnicodeObject').target().fields()
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
1100 _is_pep393 = 'data' in [f.name for f in fields]
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1101 if _is_pep393:
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1102 # Python 3.3 and newer
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1103 may_have_surrogates = False
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1104 compact = self.field('_base')
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1105 ascii = compact['_base']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1106 state = ascii['state']
72614
93f033c7cfea PyUnicode_Ready() now sets ascii=1 if maxchar < 128
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72476
diff changeset
1107 is_compact_ascii = (int(state['ascii']) and int(state['compact']))
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1108 if not int(state['ready']):
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1109 # string is not ready
73368
694f70ea1419 Oops, really fix gdb/libpython.py for not ready Unicode strings
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73356
diff changeset
1110 field_length = long(compact['wstr_length'])
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1111 may_have_surrogates = True
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1112 field_str = ascii['wstr']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1113 else:
73368
694f70ea1419 Oops, really fix gdb/libpython.py for not ready Unicode strings
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73356
diff changeset
1114 field_length = long(ascii['length'])
72614
93f033c7cfea PyUnicode_Ready() now sets ascii=1 if maxchar < 128
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72476
diff changeset
1115 if is_compact_ascii:
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1116 field_str = ascii.address + 1
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1117 elif int(state['compact']):
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1118 field_str = compact.address + 1
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1119 else:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1120 field_str = self.field('data')['any']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1121 repr_kind = int(state['kind'])
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1122 if repr_kind == 1:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1123 field_str = field_str.cast(_type_unsigned_char_ptr)
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1124 elif repr_kind == 2:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1125 field_str = field_str.cast(_type_unsigned_short_ptr)
72809
ef1f0434c79c Fix test_gdb following the small unicode struct change in c25262e97304 (issue #13130)
Antoine Pitrou <solipsis@pitrou.net>
parents: 72614
diff changeset
1126 elif repr_kind == 4:
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1127 field_str = field_str.cast(_type_unsigned_int_ptr)
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1128 else:
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1129 # Python 3.2 and earlier
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1130 field_length = long(self.field('length'))
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1131 field_str = self.field('str')
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1132 may_have_surrogates = self.char_width() == 2
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
1133
6de3de3ab71f Issue #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 # Gather a list of ints from the Py_UNICODE array; these are either
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1135 # UCS-1, UCS-2 or UCS-4 code points:
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1136 if not may_have_surrogates:
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1137 Py_UNICODEs = [int(field_str[i]) for i in safe_range(field_length)]
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1138 else:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1139 # A more elaborate routine if sizeof(Py_UNICODE) is 2 in the
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1140 # inferior process: we must join surrogate pairs.
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1141 Py_UNICODEs = []
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1142 i = 0
64571
b1cf3f7f304c Add a safety limit to the number of unicode characters we fetch
Antoine Pitrou <solipsis@pitrou.net>
parents: 64570
diff changeset
1143 limit = safety_limit(field_length)
b1cf3f7f304c Add a safety limit to the number of unicode characters we fetch
Antoine Pitrou <solipsis@pitrou.net>
parents: 64570
diff changeset
1144 while i < limit:
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1145 ucs = int(field_str[i])
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1146 i += 1
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1147 if ucs < 0xD800 or ucs >= 0xDC00 or i == field_length:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1148 Py_UNICODEs.append(ucs)
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1149 continue
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1150 # This could be a surrogate pair.
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1151 ucs2 = int(field_str[i])
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1152 if ucs2 < 0xDC00 or ucs2 > 0xDFFF:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1153 continue
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1154 code = (ucs & 0x03FF) << 10
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1155 code |= ucs2 & 0x03FF
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1156 code += 0x00010000
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1157 Py_UNICODEs.append(code)
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1158 i += 1
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1159
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1160 # Convert the int code points to unicode characters, and generate a
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1161 # local unicode instance.
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1162 # This splits surrogate pairs if sizeof(Py_UNICODE) is 2 here (in gdb).
83254
91a57079afbb python-gdb.py: Replace invalid Unicode character with U+FFFD to be able to
Victor Stinner <victor.stinner@gmail.com>
parents: 81772
diff changeset
1163 result = u''.join([
91a57079afbb python-gdb.py: Replace invalid Unicode character with U+FFFD to be able to
Victor Stinner <victor.stinner@gmail.com>
parents: 81772
diff changeset
1164 (_unichr(ucs) if ucs <= 0x10ffff else '\ufffd')
91a57079afbb python-gdb.py: Replace invalid Unicode character with U+FFFD to be able to
Victor Stinner <victor.stinner@gmail.com>
parents: 81772
diff changeset
1165 for ucs in Py_UNICODEs])
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1166 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
1167
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1168 def write_repr(self, out, visited):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1169 # Write this out as a Python 3 str literal, i.e. without a "u" prefix
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1170
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1171 # Get a PyUnicodeObject* within the Python 2 gdb process:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1172 proxy = self.proxyval(visited)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1173
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1174 # Transliteration of Python 3's Object/unicodeobject.c:unicode_repr
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1175 # to Python 2:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1176 if "'" in proxy and '"' not in proxy:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1177 quote = '"'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1178 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1179 quote = "'"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1180 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1181
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1182 i = 0
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1183 while i < len(proxy):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1184 ch = proxy[i]
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1185 i += 1
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1186
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1187 # Escape quotes and backslashes
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1188 if ch == quote or ch == '\\':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1189 out.write('\\')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1190 out.write(ch)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1191
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1192 # Map special whitespace to '\t', \n', '\r'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1193 elif ch == '\t':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1194 out.write('\\t')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1195 elif ch == '\n':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1196 out.write('\\n')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1197 elif ch == '\r':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1198 out.write('\\r')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1199
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1200 # Map non-printable US ASCII to '\xhh' */
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1201 elif ch < ' ' or ch == 0x7F:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1202 out.write('\\x')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1203 out.write(hexdigits[(ord(ch) >> 4) & 0x000F])
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1204 out.write(hexdigits[ord(ch) & 0x000F])
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1205
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1206 # Copy ASCII characters as-is
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1207 elif ord(ch) < 0x7F:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1208 out.write(ch)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1209
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1210 # Non-ASCII characters
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1211 else:
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1212 ucs = ch
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1213 ch2 = None
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1214 if sys.maxunicode < 0x10000:
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1215 # If sizeof(Py_UNICODE) is 2 here (in gdb), join
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1216 # surrogate pairs before calling _unichr_is_printable.
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1217 if (i < len(proxy)
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1218 and 0xD800 <= ord(ch) < 0xDC00 \
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1219 and 0xDC00 <= ord(proxy[i]) <= 0xDFFF):
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1220 ch2 = proxy[i]
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1221 ucs = ch + ch2
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1222 i += 1
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1223
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1224 # Unfortuately, Python 2's unicode type doesn't seem
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1225 # to expose the "isprintable" method
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1226 printable = _unichr_is_printable(ucs)
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1227 if printable:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1228 try:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1229 ucs.encode(ENCODING)
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1230 except UnicodeEncodeError:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1231 printable = False
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1232
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1233 # Map Unicode whitespace and control characters
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1234 # (categories Z* and C* except ASCII space)
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1235 if not printable:
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1236 if ch2 is not None:
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1237 # Match Python 3's representation of non-printable
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1238 # wide characters.
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1239 code = (ord(ch) & 0x03FF) << 10
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1240 code |= ord(ch2) & 0x03FF
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1241 code += 0x00010000
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1242 else:
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1243 code = ord(ucs)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1244
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1245 # Map 8-bit characters to '\\xhh'
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1246 if code <= 0xff:
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1247 out.write('\\x')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1248 out.write(hexdigits[(code >> 4) & 0x000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1249 out.write(hexdigits[code & 0x000F])
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1250 # Map 21-bit characters to '\U00xxxxxx'
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1251 elif code >= 0x10000:
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1252 out.write('\\U')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1253 out.write(hexdigits[(code >> 28) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1254 out.write(hexdigits[(code >> 24) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1255 out.write(hexdigits[(code >> 20) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1256 out.write(hexdigits[(code >> 16) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1257 out.write(hexdigits[(code >> 12) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1258 out.write(hexdigits[(code >> 8) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1259 out.write(hexdigits[(code >> 4) & 0x0000000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1260 out.write(hexdigits[code & 0x0000000F])
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1261 # Map 16-bit characters to '\uxxxx'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1262 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1263 out.write('\\u')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1264 out.write(hexdigits[(code >> 12) & 0x000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1265 out.write(hexdigits[(code >> 8) & 0x000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1266 out.write(hexdigits[(code >> 4) & 0x000F])
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1267 out.write(hexdigits[code & 0x000F])
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1268 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1269 # Copy characters as-is
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1270 out.write(ch)
64570
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1271 if ch2 is not None:
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1272 out.write(ch2)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1273
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1274 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1275
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1276
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1277
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
1278
6de3de3ab71f Issue #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 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
1280 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
1281
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1284 # 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
1285 # 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
1286 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
1287 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
1288 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
1289 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
1290 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
1291
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1292
6de3de3ab71f Issue #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 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
1294 "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
1295
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1296 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
1297 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
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 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
1300 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
1301 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
1302 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
1303 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
1304 # 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
1305 # 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
1306 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
1307 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
1308
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1309 def 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
1310 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
1311 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
1312 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
1313 t = str(type)
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1314 if t in ("PyObject", "PyFrameObject", "PyUnicodeObject"):
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
1315 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
1316
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1317 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1318 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
1319 (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
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 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
1322 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
1323 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
1324 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
1325
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1326 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
1327 (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
1328
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1329 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
1330 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
1331 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
1332 .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
1333 /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
1334 /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
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 def register (obj):
79626
332b93ce7bf9 compare singletons by identity not equality (closes #16712)
Benjamin Peterson <benjamin@python.org>
parents: 77824
diff changeset
1337 if obj is None:
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1338 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
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 # 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
1341 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
1342
6de3de3ab71f Issue #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 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
1344
6de3de3ab71f Issue #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
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1346
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1347 # Unfortunately, the exact API exposed by the gdb module varies somewhat
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1348 # from build to build
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1349 # See http://bugs.python.org/issue8279?#msg102276
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1350
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
1351 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
1352 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1353 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
1354 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1355 def __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
1356 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
1357
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1358 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
1359 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
1360 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
1361 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
1362 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
1363 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
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 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
1366 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
1367 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
1368 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
1369 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
1370 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
1371
6de3de3ab71f Issue #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 def select(self):
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1373 '''If supported, select this frame and return True; return False if unsupported
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1374
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1375 Not all builds have a gdb.Frame.select method; seems to be present on Fedora 12
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1376 onwards, but absent on Ubuntu buildbot'''
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1377 if not hasattr(self._gdbframe, 'select'):
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1378 print ('Unable to select frame: '
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1379 'this build of gdb does not expose a gdb.Frame.select method')
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1380 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
1381 self._gdbframe.select()
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1382 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
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 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
1385 '''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
1386 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
1387 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
1388 # 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
1389 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
1390 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
1391 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
1392 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
1393 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
1394
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1395 # We divide frames into:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1396 # - "python frames":
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1397 # - "bytecode frames" i.e. PyEval_EvalFrameEx
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1398 # - "other python frames": things that are of interest from a python
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1399 # POV, but aren't bytecode (e.g. GC, GIL)
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1400 # - everything else
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1401
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1402 def is_python_frame(self):
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1403 '''Is this a PyEval_EvalFrameEx frame, or some other important
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1404 frame? (see is_other_python_frame for what "important" means in this
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1405 context)'''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1406 if self.is_evalframeex():
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1407 return True
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1408 if self.is_other_python_frame():
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1409 return True
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1410 return False
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1411
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
1412 def is_evalframeex(self):
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1413 '''Is this a PyEval_EvalFrameEx frame?'''
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1414 if self._gdbframe.name() == 'PyEval_EvalFrameEx':
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1415 '''
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1416 I believe we also need to filter on the inline
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1417 struct frame_id.inline_depth, only regarding frames with
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1418 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
1419
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1420 So we reject those with type gdb.INLINE_FRAME
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1421 '''
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1422 if self._gdbframe.type() == gdb.NORMAL_FRAME:
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1423 # We have a PyEval_EvalFrameEx frame:
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1424 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
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 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
1427
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1428 def is_other_python_frame(self):
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1429 '''Is this frame worth displaying in python backtraces?
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1430 Examples:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1431 - waiting on the GIL
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1432 - garbage-collecting
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1433 - within a CFunction
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1434 If it is, return a descriptive string
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1435 For other frames, return False
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1436 '''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1437 if self.is_waiting_for_gil():
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1438 return 'Waiting for the GIL'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1439 elif self.is_gc_collect():
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1440 return 'Garbage-collecting'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1441 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1442 # Detect invocations of PyCFunction instances:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1443 older = self.older()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1444 if older and older._gdbframe.name() == 'PyCFunction_Call':
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1445 # Within that frame:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1446 # "func" is the local containing the PyObject* of the
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1447 # PyCFunctionObject instance
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1448 # "f" is the same value, but cast to (PyCFunctionObject*)
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1449 # "self" is the (PyObject*) of the 'self'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1450 try:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1451 # Use the prettyprinter for the func:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1452 func = older._gdbframe.read_var('func')
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1453 return str(func)
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1454 except RuntimeError:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1455 return 'PyCFunction invocation (unable to read "func")'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1456
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1457 # This frame isn't worth reporting:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1458 return False
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1459
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1460 def is_waiting_for_gil(self):
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1461 '''Is this frame waiting on the GIL?'''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1462 # This assumes the _POSIX_THREADS version of Python/ceval_gil.h:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1463 name = self._gdbframe.name()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1464 if name:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1465 return name.startswith('pthread_cond_timedwait')
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1466
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1467 def is_gc_collect(self):
81772
07488c3c85f1 Fix a few typos and a double semicolon. Patch by Eitan Adler.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 79626
diff changeset
1468 '''Is this frame "collect" within the garbage-collector?'''
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1469 return self._gdbframe.name() == 'collect'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1470
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
1471 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
1472 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
1473 f = self._gdbframe.read_var('f')
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1474 frame = PyFrameObjectPtr.from_pyobject_ptr(f)
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1475 if not frame.is_optimized_out():
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1476 return frame
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1477 # gdb is unable to get the "f" argument of PyEval_EvalFrameEx()
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1478 # because it was "optimized out". Try to get "f" from the frame
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1479 # of the caller, PyEval_EvalCodeEx().
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1480 orig_frame = frame
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1481 caller = self._gdbframe.older()
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1482 if caller:
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1483 f = caller.read_var('f')
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1484 frame = PyFrameObjectPtr.from_pyobject_ptr(f)
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1485 if not frame.is_optimized_out():
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1486 return frame
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1487 return orig_frame
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1488 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
1489 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
1490
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1491 @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
1492 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
1493 _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
1494 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
1495 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
1496 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
1497
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1498 @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
1499 def get_selected_python_frame(cls):
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1500 '''Try to obtain the Frame for the python-related code in the selected
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1501 frame, or None'''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1502 frame = cls.get_selected_frame()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1503
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1504 while frame:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1505 if frame.is_python_frame():
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1506 return frame
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1507 frame = frame.older()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1508
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1509 # Not found:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1510 return None
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1511
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1512 @classmethod
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1513 def get_selected_bytecode_frame(cls):
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1514 '''Try to obtain the Frame for the python bytecode interpreter in the
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1515 selected GDB frame, or None'''
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1516 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
1517
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1518 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
1519 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
1520 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
1521 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
1522
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1523 # 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
1524 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
1525
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1526 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
1527 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
1528 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
1529 if pyop:
64134
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
1530 line = pyop.get_truncated_repr(MAX_OUTPUT_LEN)
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
1531 write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line))
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1532 if not pyop.is_optimized_out():
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1533 line = pyop.current_line()
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1534 if line is not None:
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1535 sys.stdout.write(' %s\n' % line.strip())
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1536 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
1537 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
1538 else:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1539 info = self.is_other_python_frame()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1540 if info:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1541 sys.stdout.write('#%i %s\n' % (self.get_index(), info))
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1542 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1543 sys.stdout.write('#%i\n' % self.get_index())
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
1544
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1545 def print_traceback(self):
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1546 if self.is_evalframeex():
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1547 pyop = self.get_pyop()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1548 if pyop:
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1549 pyop.print_traceback()
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1550 if not pyop.is_optimized_out():
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1551 line = pyop.current_line()
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1552 if line is not None:
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1553 sys.stdout.write(' %s\n' % line.strip())
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1554 else:
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1555 sys.stdout.write(' (unable to read python frame information)\n')
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1556 else:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1557 info = self.is_other_python_frame()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1558 if info:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1559 sys.stdout.write(' %s\n' % info)
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1560 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1561 sys.stdout.write(' (not a python frame)\n')
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1562
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
1563 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
1564 '''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
1565
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1566 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
1567 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
1568 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
1569
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1570 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
1571 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
1572 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
1573 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1574
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1575 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
1576 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
1577 "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
1578 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
1579 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
1580
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1581
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1582 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
1583 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
1584
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1585 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
1586 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
1587
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1588 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
1589 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
1590 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
1591 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
1592
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1593 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
1594 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
1595 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
1596
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1597 # py-list requires an actual PyEval_EvalFrameEx frame:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1598 frame = Frame.get_selected_bytecode_frame()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1599 if not frame:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1600 print 'Unable to locate gdb frame for python bytecode interpreter'
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
1601 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
1602
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1603 pyop = frame.get_pyop()
74076
0b03cb97dac0 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 71106
diff changeset
1604 if not pyop or pyop.is_optimized_out():
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1605 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
1606 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
1607
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1608 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
1609 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
1610
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1611 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
1612 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
1613 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
1614
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1615 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
1616 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
1617
71106
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1618 try:
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1619 f = open(os_fsencode(filename), 'r')
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1620 except IOError as err:
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1621 sys.stdout.write('Unable to open %s: %s\n'
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1622 % (filename, err))
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1623 return
316764e64b0a libpython.py (gdb) now catchs IOError in py-list and py-bt commands
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70078
diff changeset
1624 with f:
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
1625 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
1626 # 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
1627 # 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
1628 # 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
1629 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
1630 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
1631 # 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
1632 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
1633 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
1634 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
1635
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1636
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1637 # ...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
1638 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
1639
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1640 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
1641 '''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
1642 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
1643 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
1644 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
1645 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
1646 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
1647 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
1648
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1649 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
1650 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
1651
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1652 if iter_frame.is_python_frame():
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1653 # Result:
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1654 if iter_frame.select():
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1655 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
1656 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
1657
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1658 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
1659
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1660 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
1661 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
1662 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
1663 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
1664
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1665 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
1666 '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
1667 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
1668 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
1669 "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
1670 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
1671 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
1672
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1673
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1674 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
1675 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
1676
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1677 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
1678 '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
1679 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
1680 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
1681 "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
1682 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
1683 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
1684
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1685
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1686 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
1687 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
1688
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1689 # Not all builds of gdb have gdb.Frame.select
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1690 if hasattr(gdb.Frame, 'select'):
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1691 PyUp()
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1692 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
1693
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1694 class PyBacktraceFull(gdb.Command):
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1695 'Display the current python frame and all the frames within its call stack (if any)'
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1696 def __init__(self):
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1697 gdb.Command.__init__ (self,
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1698 "py-bt-full",
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1699 gdb.COMMAND_STACK,
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1700 gdb.COMPLETE_NONE)
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1701
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1702
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1703 def invoke(self, args, from_tty):
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1704 frame = Frame.get_selected_python_frame()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1705 while frame:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1706 if frame.is_python_frame():
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1707 frame.print_summary()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1708 frame = frame.older()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1709
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1710 PyBacktraceFull()
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1711
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
1712 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
1713 '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
1714 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
1715 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
1716 "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
1717 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
1718 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
1719
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1720
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1721 def invoke(self, args, from_tty):
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1722 sys.stdout.write('Traceback (most recent call first):\n')
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
1723 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
1724 while frame:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1725 if frame.is_python_frame():
70078
b340d1577dc5 Issue #11996: libpython (gdb), replace "py-bt" command by "py-bt-full" and add
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65485
diff changeset
1726 frame.print_traceback()
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
1727 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
1728
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1729 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
1730
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1731 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
1732 '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
1733 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
1734 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
1735 "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
1736 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
1737 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
1738
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1739
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1740 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
1741 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
1742
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1743 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
1744 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
1745 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
1746 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
1747
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1748 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
1749 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
1750 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
1751 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
1752
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1753 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
1754
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1755 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
1756 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
1757 % (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
1758 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
1759 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
1760 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
1761 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
1762
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1763 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
1764
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1765 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
1766 '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
1767 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
1768 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
1769 "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
1770 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
1771 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
1772
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1773
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1774 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
1775 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
1776
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1777 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
1778 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
1779 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
1780 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
1781
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1782 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
1783 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
1784 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
1785 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
1786
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1787 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
1788 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
1789 % (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
1790 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
1791
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1792 PyLocals()