Skip to content

Commit

Permalink
Update libpython for gdb
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Sep 13, 2024
1 parent e63e403 commit 8b97771
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Tools/gdb/libpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def _managed_dict_offset():
else:
return -3 * _sizeof_void_p()

def _interp_frame_has_bytecode():
interp_frame = gdb.lookup_type("_PyInterpreterFrame")
return any(field.name == "bytecode" for field in interp_frame.fields())


Py_TPFLAGS_INLINE_VALUES = (1 << 2)
Py_TPFLAGS_MANAGED_DICT = (1 << 4)
Expand Down Expand Up @@ -105,6 +109,8 @@ def _managed_dict_offset():
UNABLE_READ_INFO_PYTHON_FRAME = 'Unable to read information on python frame'
EVALFRAME = '_PyEval_EvalFrameDefault'

INTERP_FRAME_HAS_BYTECODE = _interp_frame_has_bytecode()

class NullPyObjectPtr(RuntimeError):
pass

Expand Down Expand Up @@ -1082,7 +1088,10 @@ def _f_nlocalsplus(self):
def _f_lasti(self):
codeunit_p = gdb.lookup_type("_Py_CODEUNIT").pointer()
instr_ptr = self._gdbval["instr_ptr"]
first_instr = self._f_code().field("co_code_adaptive").cast(codeunit_p)
if INTERP_FRAME_HAS_BYTECODE:
first_instr = self._gdbval["bytecode"].cast(codeunit_p)
else:
first_instr = self._f_code().field("co_code_adaptive").cast(codeunit_p)
return int(instr_ptr - first_instr)

def is_shim(self):
Expand Down

0 comments on commit 8b97771

Please sign in to comment.