summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-02-01 16:29:54 +0100
committerVictor Stinner <victor.stinner@gmail.com>2017-02-01 16:29:54 +0100
commitfba5031c50d359d3d1531ab88f19f2e8b6d4531b (patch)
tree0aac5ae4b47810d06019876fc16a81b469d656d3
parent2e835c97b60f5f554ea4742abc1c0f801567f1b9 (diff)
downloadcpython-fba5031c50d359d3d1531ab88f19f2e8b6d4531b.tar.gz
python-gdb.py supports method-wrapper
Issue #29367: python-gdb.py now supports also method-wrapper (wrapperobject) objects.
-rw-r--r--Lib/test/test_gdb.py21
-rw-r--r--Misc/NEWS3
-rwxr-xr-xTools/gdb/libpython.py53
3 files changed, 71 insertions, 6 deletions
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index 557591f76c..247c3adeec 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -3,13 +3,14 @@
# The code for testing gdb was adapted from similar work in Unladen Swallow's
# Lib/test/test_jit_gdb.py
+import locale
import os
import re
import subprocess
import sys
import sysconfig
+import textwrap
import unittest
-import locale
# Is this Python configured to support threads?
try:
@@ -847,6 +848,24 @@ id(42)
)
self.assertIn('#1 <built-in method gmtime', gdb_output)
+ @unittest.skipIf(python_is_optimized(),
+ "Python was compiled with optimizations")
+ def test_wrapper_call(self):
+ cmd = textwrap.dedent('''
+ class MyList(list):
+ def __init__(self):
+ super().__init__() # wrapper_call()
+
+ l = MyList()
+ ''')
+ # Verify with "py-bt":
+ gdb_output = self.get_stack_trace(cmd,
+ breakpoint='wrapper_call',
+ cmds_after_breakpoint=['py-bt'],
+ )
+ self.assertIn("<method-wrapper '__init__' of MyList object at ",
+ gdb_output)
+
class PyPrintTests(DebuggerTests):
@unittest.skipIf(python_is_optimized(),
diff --git a/Misc/NEWS b/Misc/NEWS
index 9289940107..2db0514884 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -746,6 +746,9 @@ Build
Tools/Demos
-----------
+- Issue #29367: python-gdb.py now supports also ``method-wrapper``
+ (``wrapperobject``) objects.
+
- Issue #28023: Fix python-gdb.py didn't support new dict implementation.
- Issue #15369: The pybench and pystone microbenchmark have been removed from
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index 0903c01766..cca9741ced 100755
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -362,6 +362,7 @@ class PyObjectPtr(object):
'set' : PySetObjectPtr,
'frozenset' : PySetObjectPtr,
'builtin_function_or_method' : PyCFunctionObjectPtr,
+ 'method-wrapper': wrapperobject,
}
if tp_name in name_map:
return name_map[tp_name]
@@ -1330,6 +1331,39 @@ class PyUnicodeObjectPtr(PyObjectPtr):
out.write(quote)
+class wrapperobject(PyObjectPtr):
+ _typename = 'wrapperobject'
+
+ def safe_name(self):
+ try:
+ name = self.field('descr')['d_base']['name'].string()
+ return repr(name)
+ except (NullPyObjectPtr, RuntimeError):
+ return '<unknown name>'
+
+ def safe_tp_name(self):
+ try:
+ return self.field('self')['ob_type']['tp_name'].string()
+ except (NullPyObjectPtr, RuntimeError):
+ return '<unknown tp_name>'
+
+ def safe_self_addresss(self):
+ try:
+ address = long(self.field('self'))
+ return '%#x' % address
+ except (NullPyObjectPtr, RuntimeError):
+ return '<failed to get self address>'
+
+ def proxyval(self, visited):
+ name = self.safe_name()
+ tp_name = self.safe_tp_name()
+ self_address = self.safe_self_addresss()
+ return ("<method-wrapper %s of %s object at %s>"
+ % (name, tp_name, self_address))
+
+ def write_repr(self, out, visited):
+ proxy = self.proxyval(visited)
+ out.write(proxy)
def int_from_int(gdbval):
@@ -1364,11 +1398,13 @@ class PyObjectPtrPrinter:
def pretty_printer_lookup(gdbval):
type = gdbval.type.unqualified()
- if type.code == gdb.TYPE_CODE_PTR:
- type = type.target().unqualified()
- t = str(type)
- if t in ("PyObject", "PyFrameObject", "PyUnicodeObject"):
- return PyObjectPtrPrinter(gdbval)
+ if type.code != gdb.TYPE_CODE_PTR:
+ return None
+
+ type = type.target().unqualified()
+ t = str(type)
+ if t in ("PyObject", "PyFrameObject", "PyUnicodeObject", "wrapperobject"):
+ return PyObjectPtrPrinter(gdbval)
"""
During development, I've been manually invoking the code in this way:
@@ -1520,6 +1556,13 @@ class Frame(object):
except RuntimeError:
return 'PyCFunction invocation (unable to read %s)' % arg_name
+ if caller == 'wrapper_call':
+ try:
+ func = frame.read_var('wp')
+ return str(func)
+ except RuntimeError:
+ return '<wrapper_call invocation>'
+
# This frame isn't worth reporting:
return False