|
| 1 | +#ifndef Py_INTERNAL_DEBUG_OFFSETS_H |
| 2 | +#define Py_INTERNAL_DEBUG_OFFSETS_H |
| 3 | +#ifdef __cplusplus |
| 4 | +extern "C" { |
| 5 | +#endif |
| 6 | + |
| 7 | +#ifndef Py_BUILD_CORE |
| 8 | +# error "this header requires Py_BUILD_CORE define" |
| 9 | +#endif |
| 10 | + |
| 11 | + |
| 12 | +#define _Py_Debug_Cookie "xdebugpy" |
| 13 | + |
| 14 | +#ifdef Py_GIL_DISABLED |
| 15 | +# define _Py_Debug_gilruntimestate_enabled offsetof(struct _gil_runtime_state, enabled) |
| 16 | +# define _Py_Debug_Free_Threaded 1 |
| 17 | +#else |
| 18 | +# define _Py_Debug_gilruntimestate_enabled 0 |
| 19 | +# define _Py_Debug_Free_Threaded 0 |
| 20 | +#endif |
| 21 | + |
| 22 | + |
| 23 | +typedef struct _Py_DebugOffsets { |
| 24 | + char cookie[8]; |
| 25 | + uint64_t version; |
| 26 | + uint64_t free_threaded; |
| 27 | + // Runtime state offset; |
| 28 | + struct _runtime_state { |
| 29 | + uint64_t size; |
| 30 | + uint64_t finalizing; |
| 31 | + uint64_t interpreters_head; |
| 32 | + } runtime_state; |
| 33 | + |
| 34 | + // Interpreter state offset; |
| 35 | + struct _interpreter_state { |
| 36 | + uint64_t size; |
| 37 | + uint64_t id; |
| 38 | + uint64_t next; |
| 39 | + uint64_t threads_head; |
| 40 | + uint64_t gc; |
| 41 | + uint64_t imports_modules; |
| 42 | + uint64_t sysdict; |
| 43 | + uint64_t builtins; |
| 44 | + uint64_t ceval_gil; |
| 45 | + uint64_t gil_runtime_state; |
| 46 | + uint64_t gil_runtime_state_enabled; |
| 47 | + uint64_t gil_runtime_state_locked; |
| 48 | + uint64_t gil_runtime_state_holder; |
| 49 | + } interpreter_state; |
| 50 | + |
| 51 | + // Thread state offset; |
| 52 | + struct _thread_state{ |
| 53 | + uint64_t size; |
| 54 | + uint64_t prev; |
| 55 | + uint64_t next; |
| 56 | + uint64_t interp; |
| 57 | + uint64_t current_frame; |
| 58 | + uint64_t thread_id; |
| 59 | + uint64_t native_thread_id; |
| 60 | + uint64_t datastack_chunk; |
| 61 | + uint64_t status; |
| 62 | + } thread_state; |
| 63 | + |
| 64 | + // InterpreterFrame offset; |
| 65 | + struct _interpreter_frame { |
| 66 | + uint64_t size; |
| 67 | + uint64_t previous; |
| 68 | + uint64_t executable; |
| 69 | + uint64_t instr_ptr; |
| 70 | + uint64_t localsplus; |
| 71 | + uint64_t owner; |
| 72 | + } interpreter_frame; |
| 73 | + |
| 74 | + // Code object offset; |
| 75 | + struct _code_object { |
| 76 | + uint64_t size; |
| 77 | + uint64_t filename; |
| 78 | + uint64_t name; |
| 79 | + uint64_t qualname; |
| 80 | + uint64_t linetable; |
| 81 | + uint64_t firstlineno; |
| 82 | + uint64_t argcount; |
| 83 | + uint64_t localsplusnames; |
| 84 | + uint64_t localspluskinds; |
| 85 | + uint64_t co_code_adaptive; |
| 86 | + } code_object; |
| 87 | + |
| 88 | + // PyObject offset; |
| 89 | + struct _pyobject { |
| 90 | + uint64_t size; |
| 91 | + uint64_t ob_type; |
| 92 | + } pyobject; |
| 93 | + |
| 94 | + // PyTypeObject object offset; |
| 95 | + struct _type_object { |
| 96 | + uint64_t size; |
| 97 | + uint64_t tp_name; |
| 98 | + uint64_t tp_repr; |
| 99 | + uint64_t tp_flags; |
| 100 | + } type_object; |
| 101 | + |
| 102 | + // PyTuple object offset; |
| 103 | + struct _tuple_object { |
| 104 | + uint64_t size; |
| 105 | + uint64_t ob_item; |
| 106 | + uint64_t ob_size; |
| 107 | + } tuple_object; |
| 108 | + |
| 109 | + // PyList object offset; |
| 110 | + struct _list_object { |
| 111 | + uint64_t size; |
| 112 | + uint64_t ob_item; |
| 113 | + uint64_t ob_size; |
| 114 | + } list_object; |
| 115 | + |
| 116 | + // PyDict object offset; |
| 117 | + struct _dict_object { |
| 118 | + uint64_t size; |
| 119 | + uint64_t ma_keys; |
| 120 | + uint64_t ma_values; |
| 121 | + } dict_object; |
| 122 | + |
| 123 | + // PyFloat object offset; |
| 124 | + struct _float_object { |
| 125 | + uint64_t size; |
| 126 | + uint64_t ob_fval; |
| 127 | + } float_object; |
| 128 | + |
| 129 | + // PyLong object offset; |
| 130 | + struct _long_object { |
| 131 | + uint64_t size; |
| 132 | + uint64_t lv_tag; |
| 133 | + uint64_t ob_digit; |
| 134 | + } long_object; |
| 135 | + |
| 136 | + // PyBytes object offset; |
| 137 | + struct _bytes_object { |
| 138 | + uint64_t size; |
| 139 | + uint64_t ob_size; |
| 140 | + uint64_t ob_sval; |
| 141 | + } bytes_object; |
| 142 | + |
| 143 | + // Unicode object offset; |
| 144 | + struct _unicode_object { |
| 145 | + uint64_t size; |
| 146 | + uint64_t state; |
| 147 | + uint64_t length; |
| 148 | + uint64_t asciiobject_size; |
| 149 | + } unicode_object; |
| 150 | + |
| 151 | + // GC runtime state offset; |
| 152 | + struct _gc { |
| 153 | + uint64_t size; |
| 154 | + uint64_t collecting; |
| 155 | + } gc; |
| 156 | +} _Py_DebugOffsets; |
| 157 | + |
| 158 | + |
| 159 | +#define _Py_DebugOffsets_INIT(debug_cookie) { \ |
| 160 | + .cookie = debug_cookie, \ |
| 161 | + .version = PY_VERSION_HEX, \ |
| 162 | + .free_threaded = _Py_Debug_Free_Threaded, \ |
| 163 | + .runtime_state = { \ |
| 164 | + .size = sizeof(_PyRuntimeState), \ |
| 165 | + .finalizing = offsetof(_PyRuntimeState, _finalizing), \ |
| 166 | + .interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \ |
| 167 | + }, \ |
| 168 | + .interpreter_state = { \ |
| 169 | + .size = sizeof(PyInterpreterState), \ |
| 170 | + .id = offsetof(PyInterpreterState, id), \ |
| 171 | + .next = offsetof(PyInterpreterState, next), \ |
| 172 | + .threads_head = offsetof(PyInterpreterState, threads.head), \ |
| 173 | + .gc = offsetof(PyInterpreterState, gc), \ |
| 174 | + .imports_modules = offsetof(PyInterpreterState, imports.modules), \ |
| 175 | + .sysdict = offsetof(PyInterpreterState, sysdict), \ |
| 176 | + .builtins = offsetof(PyInterpreterState, builtins), \ |
| 177 | + .ceval_gil = offsetof(PyInterpreterState, ceval.gil), \ |
| 178 | + .gil_runtime_state = offsetof(PyInterpreterState, _gil), \ |
| 179 | + .gil_runtime_state_enabled = _Py_Debug_gilruntimestate_enabled, \ |
| 180 | + .gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \ |
| 181 | + .gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \ |
| 182 | + }, \ |
| 183 | + .thread_state = { \ |
| 184 | + .size = sizeof(PyThreadState), \ |
| 185 | + .prev = offsetof(PyThreadState, prev), \ |
| 186 | + .next = offsetof(PyThreadState, next), \ |
| 187 | + .interp = offsetof(PyThreadState, interp), \ |
| 188 | + .current_frame = offsetof(PyThreadState, current_frame), \ |
| 189 | + .thread_id = offsetof(PyThreadState, thread_id), \ |
| 190 | + .native_thread_id = offsetof(PyThreadState, native_thread_id), \ |
| 191 | + .datastack_chunk = offsetof(PyThreadState, datastack_chunk), \ |
| 192 | + .status = offsetof(PyThreadState, _status), \ |
| 193 | + }, \ |
| 194 | + .interpreter_frame = { \ |
| 195 | + .size = sizeof(_PyInterpreterFrame), \ |
| 196 | + .previous = offsetof(_PyInterpreterFrame, previous), \ |
| 197 | + .executable = offsetof(_PyInterpreterFrame, f_executable), \ |
| 198 | + .instr_ptr = offsetof(_PyInterpreterFrame, instr_ptr), \ |
| 199 | + .localsplus = offsetof(_PyInterpreterFrame, localsplus), \ |
| 200 | + .owner = offsetof(_PyInterpreterFrame, owner), \ |
| 201 | + }, \ |
| 202 | + .code_object = { \ |
| 203 | + .size = sizeof(PyCodeObject), \ |
| 204 | + .filename = offsetof(PyCodeObject, co_filename), \ |
| 205 | + .name = offsetof(PyCodeObject, co_name), \ |
| 206 | + .qualname = offsetof(PyCodeObject, co_qualname), \ |
| 207 | + .linetable = offsetof(PyCodeObject, co_linetable), \ |
| 208 | + .firstlineno = offsetof(PyCodeObject, co_firstlineno), \ |
| 209 | + .argcount = offsetof(PyCodeObject, co_argcount), \ |
| 210 | + .localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \ |
| 211 | + .localspluskinds = offsetof(PyCodeObject, co_localspluskinds), \ |
| 212 | + .co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \ |
| 213 | + }, \ |
| 214 | + .pyobject = { \ |
| 215 | + .size = sizeof(PyObject), \ |
| 216 | + .ob_type = offsetof(PyObject, ob_type), \ |
| 217 | + }, \ |
| 218 | + .type_object = { \ |
| 219 | + .size = sizeof(PyTypeObject), \ |
| 220 | + .tp_name = offsetof(PyTypeObject, tp_name), \ |
| 221 | + .tp_repr = offsetof(PyTypeObject, tp_repr), \ |
| 222 | + .tp_flags = offsetof(PyTypeObject, tp_flags), \ |
| 223 | + }, \ |
| 224 | + .tuple_object = { \ |
| 225 | + .size = sizeof(PyTupleObject), \ |
| 226 | + .ob_item = offsetof(PyTupleObject, ob_item), \ |
| 227 | + .ob_size = offsetof(PyTupleObject, ob_base.ob_size), \ |
| 228 | + }, \ |
| 229 | + .list_object = { \ |
| 230 | + .size = sizeof(PyListObject), \ |
| 231 | + .ob_item = offsetof(PyListObject, ob_item), \ |
| 232 | + .ob_size = offsetof(PyListObject, ob_base.ob_size), \ |
| 233 | + }, \ |
| 234 | + .dict_object = { \ |
| 235 | + .size = sizeof(PyDictObject), \ |
| 236 | + .ma_keys = offsetof(PyDictObject, ma_keys), \ |
| 237 | + .ma_values = offsetof(PyDictObject, ma_values), \ |
| 238 | + }, \ |
| 239 | + .float_object = { \ |
| 240 | + .size = sizeof(PyFloatObject), \ |
| 241 | + .ob_fval = offsetof(PyFloatObject, ob_fval), \ |
| 242 | + }, \ |
| 243 | + .long_object = { \ |
| 244 | + .size = sizeof(PyLongObject), \ |
| 245 | + .lv_tag = offsetof(PyLongObject, long_value.lv_tag), \ |
| 246 | + .ob_digit = offsetof(PyLongObject, long_value.ob_digit), \ |
| 247 | + }, \ |
| 248 | + .bytes_object = { \ |
| 249 | + .size = sizeof(PyBytesObject), \ |
| 250 | + .ob_size = offsetof(PyBytesObject, ob_base.ob_size), \ |
| 251 | + .ob_sval = offsetof(PyBytesObject, ob_sval), \ |
| 252 | + }, \ |
| 253 | + .unicode_object = { \ |
| 254 | + .size = sizeof(PyUnicodeObject), \ |
| 255 | + .state = offsetof(PyUnicodeObject, _base._base.state), \ |
| 256 | + .length = offsetof(PyUnicodeObject, _base._base.length), \ |
| 257 | + .asciiobject_size = sizeof(PyASCIIObject), \ |
| 258 | + }, \ |
| 259 | + .gc = { \ |
| 260 | + .size = sizeof(struct _gc_runtime_state), \ |
| 261 | + .collecting = offsetof(struct _gc_runtime_state, collecting), \ |
| 262 | + }, \ |
| 263 | +} |
| 264 | + |
| 265 | + |
| 266 | +#ifdef __cplusplus |
| 267 | +} |
| 268 | +#endif |
| 269 | +#endif /* !Py_INTERNAL_DEBUG_OFFSETS_H */ |
0 commit comments