| 1051 | return self._frame.write_repr(out, visited) |
| 1052 | |
| 1053 | class PyFramePtr: |
| 1054 | |
| 1055 | def __init__(self, gdbval): |
| 1056 | self._gdbval = gdbval |
| 1057 | if self.is_optimized_out(): |
| 1058 | return |
| 1059 | self.co = self._f_code() |
| 1060 | if self.is_shim(): |
| 1061 | return |
| 1062 | self.co_name = self.co.pyop_field('co_name') |
| 1063 | self.co_filename = self.co.pyop_field('co_filename') |
| 1064 | |
| 1065 | self.f_lasti = self._f_lasti() |
| 1066 | self.co_nlocals = int_from_int(self.co.field('co_nlocals')) |
| 1067 | pnames = self.co.field('co_localsplusnames') |
| 1068 | self.co_localsplusnames = PyTupleObjectPtr.from_pyobject_ptr(pnames) |
| 1069 | |
| 1070 | @staticmethod |
| 1071 | def get_thread_state(): |
| 1072 | exprs = [ |
| 1073 | '_Py_tss_gilstate', # 3.15+ |
| 1074 | '_Py_tss_tstate', # 3.12+ (and not when GIL is released) |
| 1075 | 'pthread_getspecific(_PyRuntime.autoTSSkey._key)', # only live programs |
| 1076 | '((struct pthread*)$fs_base)->specific_1stblock[_PyRuntime.autoTSSkey._key].data' # x86-64 |
| 1077 | ] |
| 1078 | for expr in exprs: |
| 1079 | try: |
| 1080 | val = gdb.parse_and_eval(f'(PyThreadState*)({expr})') |
| 1081 | except gdb.error: |
| 1082 | continue |
| 1083 | if int(val) != 0: |
| 1084 | return val |
| 1085 | return None |
| 1086 | |
| 1087 | @staticmethod |
| 1088 | def get_thread_local_frame(): |
| 1089 | thread_state = PyFramePtr.get_thread_state() |
| 1090 | if thread_state is None: |
| 1091 | return None |
| 1092 | current_frame = thread_state['current_frame'] |
| 1093 | if int(current_frame) == 0: |
| 1094 | return None |
| 1095 | return PyFramePtr(current_frame) |
| 1096 | |
| 1097 | def is_optimized_out(self): |
| 1098 | return self._gdbval.is_optimized_out |
| 1099 | |
| 1100 | def iter_locals(self): |
| 1101 | ''' |
| 1102 | Yield a sequence of (name,value) pairs of PyObjectPtr instances, for |
| 1103 | the local variables of this frame |
| 1104 | ''' |
| 1105 | if self.is_optimized_out(): |
| 1106 | return |
| 1107 | |
| 1108 | |
| 1109 | obj_ptr_ptr = gdb.lookup_type("PyObject").pointer().pointer() |
| 1110 |
no outgoing calls
no test coverage detected
searching dependent graphs…