Skip to content

Commit

Permalink
Update and enhance python-gdb.py
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vstinner committed Jan 18, 2017
1 parent e69f0e6 commit fa025f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_pycfunction(self):
breakpoint='time_gmtime',
cmds_after_breakpoint=['py-bt-full'],
)
self.assertIn('#0 <built-in method gmtime', gdb_output)
self.assertIn('#1 <built-in method gmtime', gdb_output)


class PyPrintTests(DebuggerTests):
Expand Down
26 changes: 10 additions & 16 deletions Tools/gdb/libpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,34 +1497,28 @@ def is_other_python_frame(self):
return 'Garbage-collecting'

# Detect invocations of PyCFunction instances:
older = self.older()
if not older:
return False

caller = older._gdbframe.name()
frame = self._gdbframe
caller = frame.name()
if not caller:
return False

if caller == 'PyCFunction_Call':
if caller in ('_PyCFunction_FastCallDict',
'_PyCFunction_FastCallKeywords'):
if caller == '_PyCFunction_FastCallKeywords':
arg_name = 'func_obj'
else:
arg_name = 'func'
# Within that frame:
# "func" is the local containing the PyObject* of the
# PyCFunctionObject instance
# "f" is the same value, but cast to (PyCFunctionObject*)
# "self" is the (PyObject*) of the 'self'
try:
# Use the prettyprinter for the func:
func = older._gdbframe.read_var('func')
return str(func)
except RuntimeError:
return 'PyCFunction invocation (unable to read "func")'

elif caller in ('_PyCFunction_FastCallDict',
'_PyCFunction_FastCallKeywords'):
try:
func = older._gdbframe.read_var('func_obj')
func = frame.read_var(arg_name)
return str(func)
except RuntimeError:
return 'PyCFunction invocation (unable to read "func_obj")'
return 'PyCFunction invocation (unable to read %s)' % arg_name

# This frame isn't worth reporting:
return False
Expand Down

0 comments on commit fa025f1

Please sign in to comment.