Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67df3a4

Browse files
author
Victor Stinner
committed
Adapt libpython.py and test_gdb.py to Python3
* Rename PyStringObjectPtr to PyBytesObjectPtr * Replace PyObject_Print by textiowrapper_write
1 parent e212416 commit 67df3a4

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/test/test_gdb.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def run_gdb(self, *args):
6060
return out.decode('iso-8859-1'), err.decode('iso-8859-1')
6161

6262
def get_stack_trace(self, source=None, script=None,
63-
breakpoint='PyObject_Print',
63+
breakpoint='textiowrapper_write',
6464
cmds_after_breakpoint=None,
6565
import_site=False):
6666
'''
@@ -78,7 +78,7 @@ def get_stack_trace(self, source=None, script=None,
7878
# error, which typically happens python is dynamically linked (the
7979
# breakpoints of interest are to be found in the shared library)
8080
# When this happens, we still get:
81-
# Function "PyObject_Print" not defined.
81+
# Function "textiowrapper_write" not defined.
8282
# emitted to stderr each time, alas.
8383

8484
# Initially I had "--eval-command=continue" here, but removed it to
@@ -130,18 +130,18 @@ def get_gdb_repr(self, source,
130130
import_site=False):
131131
# Given an input python source representation of data,
132132
# run "python -c'print DATA'" under gdb with a breakpoint on
133-
# PyObject_Print and scrape out gdb's representation of the "op"
133+
# textiowrapper_write and scrape out gdb's representation of the "op"
134134
# parameter, and verify that the gdb displays the same string
135135
#
136136
# For a nested structure, the first time we hit the breakpoint will
137137
# give us the top-level structure
138-
gdb_output = self.get_stack_trace(source, breakpoint='PyObject_Print',
138+
gdb_output = self.get_stack_trace(source, breakpoint='textiowrapper_write',
139139
cmds_after_breakpoint=cmds_after_breakpoint,
140140
import_site=import_site)
141141
# gdb can insert additional '\n' and space characters in various places
142142
# in its output, depending on the width of the terminal it's connected
143143
# to (using its "wrap_here" function)
144-
m = re.match('.*#0\s+PyObject_Print\s+\(\s*op\=\s*(.*?),\s+fp=.*\).*',
144+
m = re.match('.*#0\s+textiowrapper_write\s+\(\s*op\=\s*(.*?),\s+fp=.*\).*',
145145
gdb_output, re.DOTALL)
146146
if not m:
147147
self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
@@ -163,7 +163,7 @@ def get_sample_script(self):
163163
class PrettyPrintTests(DebuggerTests):
164164
def test_getting_backtrace(self):
165165
gdb_output = self.get_stack_trace('print(42)')
166-
self.assertTrue('PyObject_Print' in gdb_output)
166+
self.assertTrue('textiowrapper_write' in gdb_output)
167167

168168
def assertGdbRepr(self, val, cmds_after_breakpoint=None):
169169
# Ensure that gdb's rendering of the value in a debugged process
@@ -533,7 +533,7 @@ def foo(a, b, c):
533533
534534
foo(3, 4, 5)
535535
print foo.__code__''',
536-
breakpoint='PyObject_Print',
536+
breakpoint='textiowrapper_write',
537537
cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)op)->co_zombieframe)']
538538
)
539539
self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',

Tools/gdb/libpython.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
In particular, given a gdb.Value corresponding to a PyObject* in the inferior
2020
process, we can generate a "proxy value" within the gdb process. For example,
2121
given a PyObject* in the inferior process that is in fact a PyListObject*
22-
holding three PyObject* that turn out to be PyStringObject* instances, we can
22+
holding three PyObject* that turn out to be PyBytesObject* instances, we can
2323
generate a proxy value within the gdb process that is a list of strings:
2424
["foo", "bar", "baz"]
2525
@@ -108,7 +108,7 @@ def getvalue(self):
108108
class PyObjectPtr(object):
109109
"""
110110
Class wrapping a gdb.Value that's a either a (PyObject*) within the
111-
inferior process, or some subclass pointer e.g. (PyStringObject*)
111+
inferior process, or some subclass pointer e.g. (PyBytesObject*)
112112
113113
There will be a subclass for every refined PyObject type that we care
114114
about.
@@ -319,7 +319,7 @@ def subclass_from_type(cls, t):
319319
if tp_flags & Py_TPFLAGS_TUPLE_SUBCLASS:
320320
return PyTupleObjectPtr
321321
if tp_flags & Py_TPFLAGS_STRING_SUBCLASS:
322-
return PyStringObjectPtr
322+
return PyBytesObjectPtr
323323
if tp_flags & Py_TPFLAGS_UNICODE_SUBCLASS:
324324
return PyUnicodeObjectPtr
325325
if tp_flags & Py_TPFLAGS_DICT_SUBCLASS:
@@ -958,8 +958,8 @@ def write_repr(self, out, visited):
958958
out.write('])')
959959

960960

961-
class PyStringObjectPtr(PyObjectPtr):
962-
_typename = 'PyStringObject'
961+
class PyBytesObjectPtr(PyObjectPtr):
962+
_typename = 'PyBytesObject'
963963

964964
def __str__(self):
965965
field_ob_size = self.field('ob_size')

0 commit comments

Comments
 (0)