annotate Tools/gdb/libpython.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 2f2dfad79e33
children
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 '''
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
43
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
44 # NOTE: some gdbs are linked with Python 3, so this file should be dual-syntax
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
45 # compatible (2.6+ and 3.0+). See #19308.
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
46
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
47 from __future__ import print_function, with_statement
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
48 import gdb
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
49 import os
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
50 import locale
63012
d30b9dffb86d #9235: fix missing import of sys.
Georg Brandl <georg@python.org>
parents: 63011
diff changeset
51 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
52
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
53 if sys.version_info[0] >= 3:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
54 unichr = chr
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
55 xrange = range
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
56 long = int
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
57
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
58 # 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
59 _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
60 _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
61 _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
62 _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
63 _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
64
73885
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
65 # 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
66 _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
67
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
68 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
69
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
70
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
71 Py_TPFLAGS_HEAPTYPE = (1 << 9)
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
72
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
73 Py_TPFLAGS_LONG_SUBCLASS = (1 << 24)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
74 Py_TPFLAGS_LIST_SUBCLASS = (1 << 25)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
75 Py_TPFLAGS_TUPLE_SUBCLASS = (1 << 26)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
76 Py_TPFLAGS_BYTES_SUBCLASS = (1 << 27)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
77 Py_TPFLAGS_UNICODE_SUBCLASS = (1 << 28)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
78 Py_TPFLAGS_DICT_SUBCLASS = (1 << 29)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
79 Py_TPFLAGS_BASE_EXC_SUBCLASS = (1 << 30)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
80 Py_TPFLAGS_TYPE_SUBCLASS = (1 << 31)
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
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 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
84
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
85 hexdigits = "0123456789abcdef"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
86
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
87 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
88
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
89 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
90 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
91
6de3de3ab71f Issue #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
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
93 def 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 # 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
95 # 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
96 # 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
97 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
98
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
99
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
100 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
101 # 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
102 # threshold in case the data was corrupted
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
103 return xrange(safety_limit(int(val)))
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
104
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
105 if sys.version_info[0] >= 3:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
106 def write_unicode(file, text):
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
107 file.write(text)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
108 else:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
109 def write_unicode(file, text):
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
110 # Write a byte or unicode string to file. Unicode strings are encoded to
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
111 # ENCODING encoding with 'backslashreplace' error handler to avoid
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
112 # UnicodeEncodeError.
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
113 if isinstance(text, unicode):
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
114 text = text.encode(ENCODING, 'backslashreplace')
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
115 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
116
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
117 try:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
118 os_fsencode = os.fsencode
87434
f5a626f762f6 Undo (hopefully) buildbot failures
Antoine Pitrou <solipsis@pitrou.net>
parents: 87427
diff changeset
119 except AttributeError:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
120 def os_fsencode(filename):
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
121 if not isinstance(filename, unicode):
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
122 return filename
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
123 encoding = sys.getfilesystemencoding()
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
124 if encoding == 'mbcs':
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
125 # mbcs doesn't support surrogateescape
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
126 return filename.encode(encoding)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
127 encoded = []
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
128 for char in filename:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
129 # surrogateescape error handler
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
130 if 0xDC80 <= ord(char) <= 0xDCFF:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
131 byte = chr(ord(char) - 0xDC00)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
132 else:
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
133 byte = char.encode(encoding)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
134 encoded.append(byte)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
135 return ''.join(encoded)
65485
023b41376290 libpython: implementation of os.fsencode() with surrogateescape error handler
Victor Stinner <victor.stinner@haypocalc.com>
parents: 64573
diff changeset
136
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
137 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
138 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
139
6de3de3ab71f Issue #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 class TruncatedStringIO(object):
85441
6c0f5af2f5a5 Issue #18743: Fix references to non-existant "StringIO" module
Serhiy Storchaka <storchaka@gmail.com>
parents: 85406
diff changeset
141 '''Similar to io.StringIO, but can truncate the output by raising a
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
142 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
143 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
144 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
145 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
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 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
148 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
149 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
150 # 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
151 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
152 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
153
6de3de3ab71f Issue #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 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
155
6de3de3ab71f Issue #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 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
157 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
158
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
159 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
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 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
162 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
163
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
164 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
165 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
166
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
167 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
168 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
169 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
170 _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
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 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
173 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
174 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
175 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
176 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
177
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
178 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
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 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
181 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
182
6de3de3ab71f Issue #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 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
184 "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
185
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
186 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
187 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
188
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
189 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
190 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
191 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
192 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
193 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
194 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
195 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
196
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
197 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
198 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
199 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
200
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
201 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
202 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
203 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
204
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
205 # 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
206 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
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 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
209 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
210 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
211 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
212 '''
6de3de3ab71f Issue #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 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
214
6de3de3ab71f Issue #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 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
216 '''
6de3de3ab71f Issue #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 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
218 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
219 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
220 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
221 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
222
6de3de3ab71f Issue #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 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
224 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
225 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
226 (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
227 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 # 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
233 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
234
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
235 # 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
236 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
237
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
238 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
239 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
240
6de3de3ab71f Issue #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 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
242 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
243
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
244 def 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
245 '''
6de3de3ab71f Issue #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 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
247
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
248 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
249 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
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 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
252 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
253 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
254 return 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
255
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
256 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
257 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
258 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
259 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
260 # 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
261 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
262 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
263 # 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
264 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
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 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
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 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
269 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
270 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
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 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
273
6de3de3ab71f Issue #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 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
275 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
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 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
278 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
279 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
280 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
281 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
282
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
283 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
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 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
286 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
287 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
288 """
6de3de3ab71f Issue #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 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
291 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
292 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
293
6de3de3ab71f Issue #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 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
295 # 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
296 # 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
297 # 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
298 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
299 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
300 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
301
6de3de3ab71f Issue #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 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
303 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
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 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
306 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
307 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
308 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
309 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
310 # 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
311 # 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
312 # 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
313 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
314
6de3de3ab71f Issue #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 @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
316 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
317 '''
6de3de3ab71f Issue #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 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
319 (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
320 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
321
6de3de3ab71f Issue #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 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
323 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
324 (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
325 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
326 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
327 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
328 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
329
6de3de3ab71f Issue #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 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
331 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
332 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
333 '''
6de3de3ab71f Issue #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 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
335 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
336 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
337 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
338 # 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
339 # 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
340 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
341
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
342 #print('tp_flags = 0x%08x' % tp_flags)
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
343 #print('tp_name = %r' % 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
344
6de3de3ab71f Issue #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 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
346 '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
347 '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
348 '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
349 '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
350 '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
351 '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
352 }
6de3de3ab71f Issue #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 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
354 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
355
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
356 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
357 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
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 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
360 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
361 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
362 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
363 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
364 return PyTupleObjectPtr
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 #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
374 # 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
375
6de3de3ab71f Issue #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 # 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
377 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
378
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
379 @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
380 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
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 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
383 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
384 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
385 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
386 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
387 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
388 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
389 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
390 # 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
391 # 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
392 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
393 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
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 @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
396 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
397 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
398
6de3de3ab71f Issue #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 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
400 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
401
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
402 class PyVarObjectPtr(PyObjectPtr):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
403 _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
404
6de3de3ab71f Issue #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 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
406 '''
6de3de3ab71f Issue #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 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
408 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
409
6de3de3ab71f Issue #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 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
411 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
412 def __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
413 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
414
6de3de3ab71f Issue #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 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
416 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
417
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
418
6de3de3ab71f Issue #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 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
420 '''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
421 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
422 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
423 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
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 # 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
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438
6de3de3ab71f Issue #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 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
441
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
442 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
443 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
444 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
445 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
446
6de3de3ab71f Issue #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 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
457 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
458 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
459 _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
460
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
461 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
462 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
463 (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
464 ) & ~(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
465 ).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
466 _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
467
6de3de3ab71f Issue #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 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
469 _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
470
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
471 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
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 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
474 (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
475 '''
6de3de3ab71f Issue #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 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
477 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
478 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
479 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
480 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
481 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
482 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
483 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
484 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
485 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
486 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
487 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
488 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
489
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
490 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
491 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
492 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
493 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
494 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
495 # 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
496 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
497
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
498 # 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
499 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
500
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
501 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
502 '''
73949
021e5bb297d1 Issue #13575: there is only one class type.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73885
diff changeset
503 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
504
6de3de3ab71f Issue #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 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
506 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
507 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
508 # 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
509 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
510 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
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_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
514 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
515 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
516 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
517 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
518 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
519
73949
021e5bb297d1 Issue #13575: there is only one class type.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73885
diff changeset
520 # 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
521 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
522
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
523 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
524 # 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
525 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
526 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
527 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
528 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
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 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
531 _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
532 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
533
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
534 class 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
535 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
536 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
537 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
538
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
539 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
540 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
541
6de3de3ab71f Issue #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 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
543 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
544 Class 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
545 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
546 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
547 _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
548
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
549 def 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
550 # 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
551 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
552 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
553 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
554 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
555 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
556 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
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 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
559 # 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
560 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
561 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
562 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
563 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
564
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
565 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
566 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
567
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
568 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
569 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
570 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
571 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
572 """
6de3de3ab71f Issue #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 _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
574
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
575
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
576 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
577 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
578 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
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 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
581 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
582
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
583 class 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
584 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
585 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
586 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
587
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
588 def __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
589 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
590 % (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
591 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
592 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
593 )
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
594
6de3de3ab71f Issue #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 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
596 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
597 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
598 (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
599 """
6de3de3ab71f Issue #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 _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
601
6de3de3ab71f Issue #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 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
603 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
604 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
605
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
606 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
607 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
608 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
609 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
610 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
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
6de3de3ab71f Issue #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 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
614 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
615 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
616 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
617 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
618 _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
619
6de3de3ab71f Issue #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 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
621 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
622 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
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 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
625 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
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 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
628
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
629 # 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
630 # 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
631 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
632
6de3de3ab71f Issue #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 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
634 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
635 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
636 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
637 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
638 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
639 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
640
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
641
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
642 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
643 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
644 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
645 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
646 """
6de3de3ab71f Issue #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 _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
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 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
650 '''
6de3de3ab71f Issue #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 Yields a sequence of (PyObjectPtr key, PyObjectPtr value) pairs,
85406
c57d99a8fc42 #18803: fix more typos. Patch by Févry Thibault.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83648
diff changeset
652 analogous to dict.iteritems()
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
653 '''
76485
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
654 keys = self.field('ma_keys')
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
655 values = self.field('ma_values')
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
656 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
657 ep = keys['dk_entries'].address + i
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
658 if long(values):
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
659 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
660 else:
6e5855854a2e Implement PEP 412: Key-sharing dictionaries (closes #13903)
Benjamin Peterson <benjamin@python.org>
parents: 74077
diff changeset
661 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
662 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
663 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
664 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
665
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
666 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
667 # 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
668 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
669 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
670 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
671
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
672 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
673 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
674 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
675 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
676 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
677 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
678
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
679 def write_repr(self, out, visited):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
680 # Guard against infinite loops:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
681 if self.as_address() in visited:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
682 out.write('{...}')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
683 return
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
684 visited.add(self.as_address())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
685
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693 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
694 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
695 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
696
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
697 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
698 _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
699
6de3de3ab71f Issue #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 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
701 # 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
702 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
703 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
704
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
705 def 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
706 # 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
707 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
708 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
709 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
710
6de3de3ab71f Issue #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 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
712 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
713 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
714
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
715 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
716 # 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
717 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
718 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
719 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
720 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
721
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
722 out.write('[')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
723 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
724 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
725 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
726 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
727 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
728 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
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 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
731 _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
732
6de3de3ab71f Issue #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 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
734 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
735 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
736 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
737 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
738 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
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
6de3de3ab71f Issue #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 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
742 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
743 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
744 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
745 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
746
6de3de3ab71f Issue #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 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
748 #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
749 #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
750 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
751 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
752 if ob_size == 0:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
753 return 0
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
754
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
755 ob_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
756
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
757 if gdb.lookup_type('digit').sizeof == 2:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
758 SHIFT = 15
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
759 else:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
760 SHIFT = 30
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
761
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
762 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
763 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
764 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
765 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
766 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
767 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
768
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
769 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
770 # 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
771 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
772 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
773
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
774
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
775 class PyBoolObjectPtr(PyLongObjectPtr):
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
776 """
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
777 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
778 <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
779 """
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
780 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
781 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
782 return True
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
783 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
784 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
785
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
786 class 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
787 """
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
788 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
789 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
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 _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
792
6de3de3ab71f Issue #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 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
794 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
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
6de3de3ab71f Issue #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 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
798 _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
799
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
800 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
801 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
802
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
803 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
804 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
805 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
806 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
807
6de3de3ab71f Issue #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 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
809 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
810 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
811 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
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 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
814 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
815 Yield 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
816 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
817 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
818 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
819 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
820
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
821 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
822 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
823 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
824 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
825 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
826 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
827
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
828 def iter_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
829 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
830 Yield a sequence of (name,value) pairs of PyObjectPtr instances, for
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
831 the 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
832 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
833 if self.is_optimized_out():
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
834 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
835
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
836 pyop_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
837 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
838
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
839 def 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
840 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
841 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
842 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
843 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
844 if 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
845 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
846
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
847 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
848 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
849
6de3de3ab71f Issue #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 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
851 '''
6de3de3ab71f Issue #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 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
853 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
854
6de3de3ab71f Issue #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 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
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 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
858 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
859 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
860 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
861 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
862 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
863 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
864 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
865 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
866 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
867
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
868 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
869 '''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
870 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
871 return '(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
872 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
873
6de3de3ab71f Issue #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 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
875 '''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
876
6de3de3ab71f Issue #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 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
878
6de3de3ab71f Issue #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 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
880 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
881 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
882 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
883 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
884 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
885 # 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
886 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
887 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
888 #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
889 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
890 #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
891 # 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
892
6de3de3ab71f Issue #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 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
894 '''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
895 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
896 if self.is_optimized_out():
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
897 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
898 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
899 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
900 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
901 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
902 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
903 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
904 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
905 # 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
906 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
907
6de3de3ab71f Issue #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 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
909 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
910 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
911 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
912 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
913 % (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
914 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
915 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
916 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
917 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
918 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
919 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
920 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
921 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
922
6de3de3ab71f Issue #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 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
924 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
925 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
926
6de3de3ab71f Issue #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 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
928
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
929 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
930 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
931 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
932 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
933 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
934 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
935 % (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
936 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
937 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
938
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
939 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
940 _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
941
85366
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
942 @classmethod
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
943 def _dummy_key(self):
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
944 return gdb.lookup_global_symbol('_PySet_Dummy').value()
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
945
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
946 def __iter__(self):
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
947 dummy_ptr = self._dummy_key()
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
948 table = self.field('table')
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
949 for i in safe_range(self.field('mask') + 1):
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
950 setentry = table[i]
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
951 key = setentry['key']
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
952 if key != 0 and key != dummy_ptr:
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
953 yield PyObjectPtr.from_pyobject_ptr(key)
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
954
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
955 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
956 # 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
957 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
958 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
959 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
960
85366
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
961 members = (key.proxyval(visited) for key in self)
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
962 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
963 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
964 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
965 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
966
6de3de3ab71f Issue #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 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
968 # 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
969 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
970
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
971 # 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
972 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
973 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
974 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
975 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
976
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
977 # 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
978 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
979 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
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 return
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
982
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
983 # 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
984 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
985 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
986 out.write('(')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
987
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
988 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
989 first = True
85366
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
990 for key in self:
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
991 if not first:
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
992 out.write(', ')
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
993 first = False
2f1bac39565a Issue #18772: fix the gdb plugin after the set implementation changes
Antoine Pitrou <solipsis@pitrou.net>
parents: 83649
diff changeset
994 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
995 out.write('}')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
996
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
997 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
998 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
999
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1000
60812
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
1001 class PyBytesObjectPtr(PyObjectPtr):
6d836b10e370 Adapt libpython.py and test_gdb.py to Python3
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60803
diff changeset
1002 _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
1003
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1004 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
1005 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
1006 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
1007 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
1008 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
1009
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1010 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
1011 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
1012
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1013 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
1014 # 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
1015
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1016 # 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
1017 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
1018
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1019 # 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
1020 # 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
1021 quote = "'"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1022 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
1023 quote = '"'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1024 out.write('b')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1025 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1026 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
1027 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
1028 out.write('\\')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1029 out.write(byte)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1030 elif byte == '\t':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1031 out.write('\\t')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1032 elif byte == '\n':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1033 out.write('\\n')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1034 elif byte == '\r':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1035 out.write('\\r')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1036 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
1037 out.write('\\x')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1038 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
1039 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
1040 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1041 out.write(byte)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1042 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1043
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
1044 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
1045 _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
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 __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
1048 # 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
1049 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
1050 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
1051
6de3de3ab71f Issue #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 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
1053 # 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
1054 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
1055 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
1056 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
1057
6de3de3ab71f Issue #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 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
1059 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
1060 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
1061
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1062 def 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
1063 # 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
1064 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
1065 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
1066 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
1067 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
1068
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1069 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
1070 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
1071 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
1072 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
1073 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
1074 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
1075 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
1076 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
1077 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
1078 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
1079
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1080 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
1081 _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
1082
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1083
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1084 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
1085 # 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
1086 if char == u" ":
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1087 return True
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1088 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
1089 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
1090
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1091 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
1092 _unichr = unichr
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1093 else:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1094 # 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
1095 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
1096 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
1097 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
1098 x -= 0x10000
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1099 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
1100 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
1101 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
1102
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1103
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
1104 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
1105 _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
1106
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1107 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
1108 _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
1109 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
1110
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
1111 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
1112 global _is_pep393
50c7ac2fe13c libpython.py: defer call to gdb.lookup_type('PyUnicodeObject')
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73368
diff changeset
1113 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
1114 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
1115 _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
1116 if _is_pep393:
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1117 # Python 3.3 and newer
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1118 may_have_surrogates = False
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1119 compact = self.field('_base')
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1120 ascii = compact['_base']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1121 state = ascii['state']
72614
93f033c7cfea PyUnicode_Ready() now sets ascii=1 if maxchar < 128
Victor Stinner <victor.stinner@haypocalc.com>
parents: 72476
diff changeset
1122 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
1123 if not int(state['ready']):
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1124 # 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
1125 field_length = long(compact['wstr_length'])
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1126 may_have_surrogates = True
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1127 field_str = ascii['wstr']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1128 else:
73368
694f70ea1419 Oops, really fix gdb/libpython.py for not ready Unicode strings
Victor Stinner <victor.stinner@haypocalc.com>
parents: 73356
diff changeset
1129 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
1130 if is_compact_ascii:
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1131 field_str = ascii.address + 1
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1132 elif int(state['compact']):
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1133 field_str = compact.address + 1
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1134 else:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1135 field_str = self.field('data')['any']
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1136 repr_kind = int(state['kind'])
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1137 if repr_kind == 1:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1138 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
1139 elif repr_kind == 2:
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1140 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
1141 elif repr_kind == 4:
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1142 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
1143 else:
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1144 # Python 3.2 and earlier
72476
69a6c56e8989 Update for PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 72475
diff changeset
1145 field_length = long(self.field('length'))
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1146 field_str = self.field('str')
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 71106
diff changeset
1147 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
1148
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1149 # 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
1150 # 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
1151 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
1152 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
1153 else:
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1154 # 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
1155 # 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
1156 Py_UNICODEs = []
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1157 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
1158 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
1159 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
1160 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
1161 i += 1
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1162 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
1163 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
1164 continue
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1165 # 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
1166 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
1167 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
1168 continue
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1169 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
1170 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
1171 code += 0x00010000
a2aeddc19b66 Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well
Antoine Pitrou <solipsis@pitrou.net>
parents: 64134
diff changeset
1172 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
1173 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
1174
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1175 # 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
1176 # 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
1177 # 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
1178 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
1179 (_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
1180 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
1181 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
1182
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1183 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
1184 # 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
1185
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1186 # 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
1187 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
1188
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1189 # 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
1190 # to Python 2:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1191 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
1192 quote = '"'
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1193 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1194 quote = "'"
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1195 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1196
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1197 i = 0
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1198 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
1199 ch = proxy[i]
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1200 i += 1
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1201
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1202 # 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
1203 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
1204 out.write('\\')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1205 out.write(ch)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1206
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1207 # 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
1208 elif ch == '\t':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1209 out.write('\\t')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1210 elif ch == '\n':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1211 out.write('\\n')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1212 elif ch == '\r':
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1213 out.write('\\r')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1214
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1215 # 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
1216 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
1217 out.write('\\x')
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1218 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
1219 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
1220
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1221 # 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
1222 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
1223 out.write(ch)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1224
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1225 # Non-ASCII characters
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1226 else:
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1227 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
1228 ch2 = None
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1229 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
1230 # 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
1231 # 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
1232 if (i < len(proxy)
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1233 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
1234 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
1235 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
1236 ucs = ch + ch2
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1237 i += 1
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1238
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1239 # 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
1240 # 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
1241 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
1242 if printable:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1243 try:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1244 ucs.encode(ENCODING)
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1245 except UnicodeEncodeError:
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1246 printable = False
60823
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1247
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1248 # 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
1249 # (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
1250 if not printable:
64573
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1251 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
1252 # 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
1253 # wide characters.
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1254 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
1255 code |= ord(ch2) & 0x03FF
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1256 code += 0x00010000
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1257 else:
441e94ce4087 gdb: fix representation of non-printable surrogate pairs, and workaround
Antoine Pitrou <solipsis@pitrou.net>
parents: 64571
diff changeset
1258 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
1259
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1260 # 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
1261 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
1262 out.write('\\x')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1263 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
1264 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
1265 # 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
1266 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
1267 out.write('\\U')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1268 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
1269 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
1270 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
1271 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
1272 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
1273 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
1274 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
1275 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
1276 # 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
1277 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1278 out.write('\\u')
61768
503afc62d632 Issue #8559: improve unicode support of (gdb) libpython.py
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60823
diff changeset
1279 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
1280 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
1281 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
1282 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
1283 else:
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1284 # 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
1285 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
1286 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
1287 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
1288
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1289 out.write(quote)
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1290
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1291
888c75a1be55 Issue #8380: Port gdb/libpython to 3.x.
Martin v. Löwis <martin@v.loewis.de>
parents: 60812
diff changeset
1292
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
1293
6de3de3ab71f Issue #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 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
1295 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
1296
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1299 # 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
1300 # 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
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 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
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 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
1305 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
1306
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1307
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1308 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
1309 "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
1310
6de3de3ab71f Issue #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 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
1312 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
1313
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1314 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
1315 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
1316 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
1317 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
1318 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
1319 # 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
1320 # 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
1321 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
1322 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
1323
6de3de3ab71f Issue #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 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
1325 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
1326 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
1327 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
1328 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
1329 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
1330 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
1331
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1332 """
6de3de3ab71f Issue #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 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
1334 (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
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 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
1337 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
1338 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
1339 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
1340
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1341 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
1342 (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
1343
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1344 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
1345 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
1346 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
1347 .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
1348 /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
1349 /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
1350 """
6de3de3ab71f Issue #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 def register (obj):
79626
332b93ce7bf9 compare singletons by identity not equality (closes #16712)
Benjamin Peterson <benjamin@python.org>
parents: 77824
diff changeset
1352 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
1353 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
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 # 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
1356 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
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 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
1359
6de3de3ab71f Issue #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
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1361
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1362 # 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
1363 # 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
1364 # 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
1365
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
1366 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
1367 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1368 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
1369 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1370 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
1371 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
1372
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1373 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
1374 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
1375 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
1376 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
1377 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
1378 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
1379
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1380 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
1381 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
1382 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
1383 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
1384 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
1385 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
1386
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1387 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
1388 '''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
1389
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1390 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
1391 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
1392 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
1393 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
1394 '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
1395 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
1396 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
1397 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
1398
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1399 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
1400 '''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
1401 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
1402 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
1403 # 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
1404 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
1405 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
1406 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
1407 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
1408 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
1409
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1410 # 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
1411 # - "python frames":
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1412 # - "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
1413 # - "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
1414 # 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
1415 # - everything else
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1416
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1417 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
1418 '''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
1419 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
1420 context)'''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1421 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
1422 return True
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1423 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
1424 return True
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1425 return False
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1426
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
1427 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
1428 '''Is this a PyEval_EvalFrameEx frame?'''
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1429 if self._gdbframe.name() == 'PyEval_EvalFrameEx':
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1430 '''
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1431 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
1432 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
1433 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
1434
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1435 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
1436 '''
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1437 if self._gdbframe.type() == gdb.NORMAL_FRAME:
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1438 # We have a PyEval_EvalFrameEx frame:
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1439 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
1440
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1441 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
1442
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1443 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
1444 '''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
1445 Examples:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1446 - 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
1447 - garbage-collecting
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1448 - within a CFunction
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1449 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
1450 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
1451 '''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1452 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
1453 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
1454 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
1455 return 'Garbage-collecting'
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1456 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1457 # 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
1458 older = self.older()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1459 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
1460 # Within that frame:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1461 # "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
1462 # PyCFunctionObject instance
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1463 # "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
1464 # "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
1465 try:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1466 # 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
1467 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
1468 return str(func)
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1469 except RuntimeError:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1470 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
1471
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1472 # 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
1473 return False
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1474
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1475 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
1476 '''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
1477 # 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
1478 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
1479 if name:
83648
f4a6b731905a #17833: fix test_gdb failures seen on PPC64 Linux in test_threads (test.test_gdb.PyBtTests)
David Malcolm <dmalcolm@redhat.com>
parents: 81772
diff changeset
1480 return 'pthread_cond_timedwait' in name
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1481
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1482 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
1483 '''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
1484 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
1485
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
1486 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
1487 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
1488 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
1489 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
1490 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
1491 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
1492 # 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
1493 # 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
1494 # 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
1495 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
1496 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
1497 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
1498 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
1499 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
1500 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
1501 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
1502 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
1503 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
1504 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
1505
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1506 @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
1507 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
1508 _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
1509 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
1510 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
1511 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
1512
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1513 @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
1514 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
1515 '''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
1516 frame, or None'''
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1517 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
1518
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1519 while frame:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1520 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
1521 return frame
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1522 frame = frame.older()
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1523
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1524 # Not found:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1525 return None
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1526
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1527 @classmethod
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1528 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
1529 '''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
1530 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
1531 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
1532
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1533 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
1534 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
1535 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
1536 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
1537
6de3de3ab71f Issue #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 # 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
1539 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
1540
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1541 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
1542 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
1543 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
1544 if pyop:
64134
fc794add559d libpython.py: py-bt commands escape unencodable characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63012
diff changeset
1545 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
1546 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
1547 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
1548 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
1549 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
1550 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
1551 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
1552 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
1553 else:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1554 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
1555 if info:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1556 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
1557 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1558 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
1559
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
1560 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
1561 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
1562 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
1563 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
1564 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
1565 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
1566 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
1567 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
1568 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
1569 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
1570 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
1571 else:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1572 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
1573 if info:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1574 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
1575 else:
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1576 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
1577
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
1578 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
1579 '''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
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 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
1582 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
1583 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
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 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
1586 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
1587 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
1588 '''
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1591 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
1592 "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
1593 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
1594 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
1595
6de3de3ab71f Issue #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
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1597 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
1598 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
1599
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1600 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
1601 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
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 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
1604 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
1605 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
1606 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
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 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
1609 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
1610 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
1611
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1612 # 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
1613 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
1614 if not frame:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1615 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
1616 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
1617
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1618 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
1619 if not pyop or pyop.is_optimized_out():
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1620 print('Unable to read information on 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
1621 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
1622
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1623 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
1624 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
1625
6de3de3ab71f Issue #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 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
1627 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
1628 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
1629
6de3de3ab71f Issue #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 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
1631 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
1632
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
1633 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
1634 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
1635 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
1636 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
1637 % (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
1638 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
1639 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
1640 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
1641 # 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
1642 # 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
1643 # 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
1644 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
1645 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
1646 # 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
1647 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
1648 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
1649 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
1650
6de3de3ab71f Issue #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
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1652 # ...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
1653 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
1654
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1655 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
1656 '''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
1657 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
1658 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
1659 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
1660 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
1661 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
1662 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
1663
6de3de3ab71f Issue #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 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
1665 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
1666
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1667 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
1668 # Result:
60803
a2a4d9dc7884 Merged revisions 79986-79987,80156 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 60792
diff changeset
1669 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
1670 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
1671 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
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 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
1674
6de3de3ab71f Issue #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 if move_up:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1676 print('Unable to find an older 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
1677 else:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1678 print('Unable to find a newer 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
1679
6de3de3ab71f Issue #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 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
1681 '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
1682 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
1683 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
1684 "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
1685 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
1686 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
1687
6de3de3ab71f Issue #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
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1689 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
1690 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
1691
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1692 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
1693 '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
1694 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
1695 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
1696 "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
1697 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
1698 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
1699
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1700
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1701 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
1702 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
1703
60792
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1704 # 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
1705 if hasattr(gdb.Frame, 'select'):
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1706 PyUp()
19a9a457a47a Merged revisions 80288 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60125
diff changeset
1707 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
1708
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
1709 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
1710 '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
1711 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
1712 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
1713 "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
1714 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
1715 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
1716
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
1717
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
1718 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
1719 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
1720 while frame:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1721 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
1722 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
1723 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
1724
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
1725 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
1726
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 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
1728 '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
1729 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
1730 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
1731 "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
1732 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
1733 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
1734
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1737 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
1738 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
1739 while frame:
77824
abcd29c9a791 Issue #12605: Show information on more C frames within gdb backtraces
David Malcolm <dmalcolm@redhat.com>
parents: 76485
diff changeset
1740 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
1741 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
1742 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
1743
6de3de3ab71f Issue #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 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
1745
6de3de3ab71f Issue #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 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
1747 '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
1748 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
1749 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
1750 "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
1751 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
1752 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
1753
6de3de3ab71f Issue #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 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
1756 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
1757
6de3de3ab71f Issue #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 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
1759 if not frame:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1760 print('Unable to locate 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
1761 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
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 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
1764 if not pyop_frame:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1765 print('Unable to read information on 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
1766 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
1767
6de3de3ab71f Issue #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 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
1769
6de3de3ab71f Issue #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 if pyop_var:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1771 print('%s %r = %s'
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
1772 % (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
1773 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
1774 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
1775 else:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1776 print('%r not found' % 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
1777
6de3de3ab71f Issue #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 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
1779
6de3de3ab71f Issue #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 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
1781 '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
1782 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
1783 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
1784 "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
1785 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
1786 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
1787
6de3de3ab71f Issue #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
6de3de3ab71f Issue #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 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
1790 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
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 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
1793 if not frame:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1794 print('Unable to locate 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
1795 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
1796
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1797 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
1798 if not pyop_frame:
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1799 print('Unable to read information on 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
1800 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
1801
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1802 for pyop_name, pyop_value in pyop_frame.iter_locals():
87427
752db82b7933 Issue #19308: fix the gdb plugin on gdbs linked with Python 3
Antoine Pitrou <solipsis@pitrou.net>
parents: 85441
diff changeset
1803 print('%s = %s'
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
1804 % (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
1805 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
1806
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1807 PyLocals()