Skip to content

Commit e2202fc

Browse files
committed
Fix the gdb pretty printer in the face of --enable-shared by delaying the
attempt to load the _PyInterpreterFrame definition until after .so files are loaded.
1 parent 78842e4 commit e2202fc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Tools/gdb/libpython.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ def _managed_dict_offset():
7777
else:
7878
return -3 * _sizeof_void_p()
7979

80-
def _interp_frame_has_tlbc_index():
81-
interp_frame = gdb.lookup_type("_PyInterpreterFrame")
82-
return any(field.name == "tlbc_index" for field in interp_frame.fields())
83-
80+
_INTERP_FRAME_HAS_TLBC_INDEX = None
81+
def interp_frame_has_tlbc_index():
82+
global _INTERP_FRAME_HAS_TLBC_INDEX
83+
if _INTERP_FRAME_HAS_TLBC_INDEX is None:
84+
interp_frame = gdb.lookup_type("_PyInterpreterFrame")
85+
_INTERP_FRAME_HAS_TLBC_INDEX = any(field.name == "tlbc_index"
86+
for field in interp_frame.fields())
87+
return _INTERP_FRAME_HAS_TLBC_INDEX
8488

8589
Py_TPFLAGS_INLINE_VALUES = (1 << 2)
8690
Py_TPFLAGS_MANAGED_DICT = (1 << 4)
@@ -109,7 +113,6 @@ def _interp_frame_has_tlbc_index():
109113
UNABLE_READ_INFO_PYTHON_FRAME = 'Unable to read information on python frame'
110114
EVALFRAME = '_PyEval_EvalFrameDefault'
111115

112-
INTERP_FRAME_HAS_TLBC_INDEX = _interp_frame_has_tlbc_index()
113116

114117
class NullPyObjectPtr(RuntimeError):
115118
pass
@@ -1101,7 +1104,7 @@ def _f_nlocalsplus(self):
11011104
def _f_lasti(self):
11021105
codeunit_p = gdb.lookup_type("_Py_CODEUNIT").pointer()
11031106
instr_ptr = self._gdbval["instr_ptr"]
1104-
if INTERP_FRAME_HAS_TLBC_INDEX:
1107+
if interp_frame_has_tlbc_index():
11051108
tlbc_index = self._gdbval["tlbc_index"]
11061109
code_arr = PyCodeArrayPtr(self._f_code().field("co_tlbc"))
11071110
first_instr = code_arr.get_entry(tlbc_index).cast(codeunit_p)

0 commit comments

Comments
 (0)