Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit fa025f1

Browse files
committed
Update and enhance python-gdb.py
Issue python#29259: * Detect PyCFunction is the current frame, not only in the older frame * Ignore PyCFunction_Call() since it now calls _PyCFunction_FastCallDict(), and _PyCFunction_FastCallDict() is already detected
1 parent e69f0e6 commit fa025f1

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

Lib/test/test_gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ def test_pycfunction(self):
845845
breakpoint='time_gmtime',
846846
cmds_after_breakpoint=['py-bt-full'],
847847
)
848-
self.assertIn('#0 <built-in method gmtime', gdb_output)
848+
self.assertIn('#1 <built-in method gmtime', gdb_output)
849849

850850

851851
class PyPrintTests(DebuggerTests):

Tools/gdb/libpython.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,34 +1497,28 @@ def is_other_python_frame(self):
14971497
return 'Garbage-collecting'
14981498

14991499
# Detect invocations of PyCFunction instances:
1500-
older = self.older()
1501-
if not older:
1502-
return False
1503-
1504-
caller = older._gdbframe.name()
1500+
frame = self._gdbframe
1501+
caller = frame.name()
15051502
if not caller:
15061503
return False
15071504

1508-
if caller == 'PyCFunction_Call':
1505+
if caller in ('_PyCFunction_FastCallDict',
1506+
'_PyCFunction_FastCallKeywords'):
1507+
if caller == '_PyCFunction_FastCallKeywords':
1508+
arg_name = 'func_obj'
1509+
else:
1510+
arg_name = 'func'
15091511
# Within that frame:
15101512
# "func" is the local containing the PyObject* of the
15111513
# PyCFunctionObject instance
15121514
# "f" is the same value, but cast to (PyCFunctionObject*)
15131515
# "self" is the (PyObject*) of the 'self'
15141516
try:
15151517
# Use the prettyprinter for the func:
1516-
func = older._gdbframe.read_var('func')
1517-
return str(func)
1518-
except RuntimeError:
1519-
return 'PyCFunction invocation (unable to read "func")'
1520-
1521-
elif caller in ('_PyCFunction_FastCallDict',
1522-
'_PyCFunction_FastCallKeywords'):
1523-
try:
1524-
func = older._gdbframe.read_var('func_obj')
1518+
func = frame.read_var(arg_name)
15251519
return str(func)
15261520
except RuntimeError:
1527-
return 'PyCFunction invocation (unable to read "func_obj")'
1521+
return 'PyCFunction invocation (unable to read %s)' % arg_name
15281522

15291523
# This frame isn't worth reporting:
15301524
return False

0 commit comments

Comments
 (0)