codekingpro/portable-devtools
114k
1#ifndef Py_INTERNAL_DEBUG_OFFSETS_H2#define Py_INTERNAL_DEBUG_OFFSETS_H3#ifdef __cplusplus4extern "C" {5#endif6 7#ifndef Py_BUILD_CORE8# error "this header requires Py_BUILD_CORE define"9#endif10 11 12#define _Py_Debug_Cookie "xdebugpy"13 14#if defined(__APPLE__)15# include <mach-o/loader.h>16#endif17 18// Macros to burn global values in custom sections so out-of-process19// profilers can locate them easily.20#define GENERATE_DEBUG_SECTION(name, declaration) \21 _GENERATE_DEBUG_SECTION_WINDOWS(name) \22 _GENERATE_DEBUG_SECTION_APPLE(name) \23 declaration \24 _GENERATE_DEBUG_SECTION_LINUX(name)25 26// Please note that section names are truncated to eight bytes27// on Windows!28#if defined(MS_WINDOWS)29#define _GENERATE_DEBUG_SECTION_WINDOWS(name) \30 _Pragma(Py_STRINGIFY(section(Py_STRINGIFY(name), read, write))) \31 __declspec(allocate(Py_STRINGIFY(name)))32#else33#define _GENERATE_DEBUG_SECTION_WINDOWS(name)34#endif35 36#if defined(__APPLE__)37#define _GENERATE_DEBUG_SECTION_APPLE(name) \38 __attribute__((section(SEG_DATA "," Py_STRINGIFY(name)))) \39 __attribute__((used))40#else41#define _GENERATE_DEBUG_SECTION_APPLE(name)42#endif43 44#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))45#define _GENERATE_DEBUG_SECTION_LINUX(name) \46 __attribute__((section("." Py_STRINGIFY(name)))) \47 __attribute__((used))48#else49#define _GENERATE_DEBUG_SECTION_LINUX(name)50#endif51 52#ifdef Py_GIL_DISABLED53# define _Py_Debug_gilruntimestate_enabled offsetof(struct _gil_runtime_state, enabled)54# define _Py_Debug_Free_Threaded 155# define _Py_Debug_code_object_co_tlbc offsetof(PyCodeObject, co_tlbc)56# define _Py_Debug_interpreter_frame_tlbc_index offsetof(_PyInterpreterFrame, tlbc_index)57# define _Py_Debug_interpreter_state_tlbc_generation offsetof(PyInterpreterState, tlbc_indices.tlbc_generation)58#else59# define _Py_Debug_gilruntimestate_enabled 060# define _Py_Debug_Free_Threaded 061# define _Py_Debug_code_object_co_tlbc 062# define _Py_Debug_interpreter_frame_tlbc_index 063# define _Py_Debug_interpreter_state_tlbc_generation 064#endif65 66 67typedef struct _Py_DebugOffsets {68 char cookie[8] _Py_NONSTRING;69 uint64_t version;70 uint64_t free_threaded;71 // Runtime state offset;72 struct _runtime_state {73 uint64_t size;74 uint64_t finalizing;75 uint64_t interpreters_head;76 } runtime_state;77 78 // Interpreter state offset;79 struct _interpreter_state {80 uint64_t size;81 uint64_t id;82 uint64_t next;83 uint64_t threads_head;84 uint64_t threads_main;85 uint64_t gc;86 uint64_t imports_modules;87 uint64_t sysdict;88 uint64_t builtins;89 uint64_t ceval_gil;90 uint64_t gil_runtime_state;91 uint64_t gil_runtime_state_enabled;92 uint64_t gil_runtime_state_locked;93 uint64_t gil_runtime_state_holder;94 uint64_t code_object_generation;95 uint64_t tlbc_generation;96 } interpreter_state;97 98 // Thread state offset;99 struct _thread_state{100 uint64_t size;101 uint64_t prev;102 uint64_t next;103 uint64_t interp;104 uint64_t current_frame;105 uint64_t thread_id;106 uint64_t native_thread_id;107 uint64_t datastack_chunk;108 uint64_t status;109 } thread_state;110 111 // InterpreterFrame offset;112 struct _interpreter_frame {113 uint64_t size;114 uint64_t previous;115 uint64_t executable;116 uint64_t instr_ptr;117 uint64_t localsplus;118 uint64_t owner;119 uint64_t stackpointer;120 uint64_t tlbc_index;121 } interpreter_frame;122 123 // Code object offset;124 struct _code_object {125 uint64_t size;126 uint64_t filename;127 uint64_t name;128 uint64_t qualname;129 uint64_t linetable;130 uint64_t firstlineno;131 uint64_t argcount;132 uint64_t localsplusnames;133 uint64_t localspluskinds;134 uint64_t co_code_adaptive;135 uint64_t co_tlbc;136 } code_object;137 138 // PyObject offset;139 struct _pyobject {140 uint64_t size;141 uint64_t ob_type;142 } pyobject;143 144 // PyTypeObject object offset;145 struct _type_object {146 uint64_t size;147 uint64_t tp_name;148 uint64_t tp_repr;149 uint64_t tp_flags;150 } type_object;151 152 // PyTuple object offset;153 struct _tuple_object {154 uint64_t size;155 uint64_t ob_item;156 uint64_t ob_size;157 } tuple_object;158 159 // PyList object offset;160 struct _list_object {161 uint64_t size;162 uint64_t ob_item;163 uint64_t ob_size;164 } list_object;165 166 // PySet object offset;167 struct _set_object {168 uint64_t size;169 uint64_t used;170 uint64_t table;171 uint64_t mask;172 } set_object;173 174 // PyDict object offset;175 struct _dict_object {176 uint64_t size;177 uint64_t ma_keys;178 uint64_t ma_values;179 } dict_object;180 181 // PyFloat object offset;182 struct _float_object {183 uint64_t size;184 uint64_t ob_fval;185 } float_object;186 187 // PyLong object offset;188 struct _long_object {189 uint64_t size;190 uint64_t lv_tag;191 uint64_t ob_digit;192 } long_object;193 194 // PyBytes object offset;195 struct _bytes_object {196 uint64_t size;197 uint64_t ob_size;198 uint64_t ob_sval;199 } bytes_object;200 201 // Unicode object offset;202 struct _unicode_object {203 uint64_t size;204 uint64_t state;205 uint64_t length;206 uint64_t asciiobject_size;207 } unicode_object;208 209 // GC runtime state offset;210 struct _gc {211 uint64_t size;212 uint64_t collecting;213 } gc;214 215 // Generator object offset;216 struct _gen_object {217 uint64_t size;218 uint64_t gi_name;219 uint64_t gi_iframe;220 uint64_t gi_frame_state;221 } gen_object;222 223 struct _llist_node {224 uint64_t next;225 uint64_t prev;226 } llist_node;227 228 struct _debugger_support {229 uint64_t eval_breaker;230 uint64_t remote_debugger_support;231 uint64_t remote_debugging_enabled;232 uint64_t debugger_pending_call;233 uint64_t debugger_script_path;234 uint64_t debugger_script_path_size;235 } debugger_support;236} _Py_DebugOffsets;237 238 239#define _Py_DebugOffsets_INIT(debug_cookie) { \240 .cookie = debug_cookie, \241 .version = PY_VERSION_HEX, \242 .free_threaded = _Py_Debug_Free_Threaded, \243 .runtime_state = { \244 .size = sizeof(_PyRuntimeState), \245 .finalizing = offsetof(_PyRuntimeState, _finalizing), \246 .interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \247 }, \248 .interpreter_state = { \249 .size = sizeof(PyInterpreterState), \250 .id = offsetof(PyInterpreterState, id), \251 .next = offsetof(PyInterpreterState, next), \252 .threads_head = offsetof(PyInterpreterState, threads.head), \253 .threads_main = offsetof(PyInterpreterState, threads.main), \254 .gc = offsetof(PyInterpreterState, gc), \255 .imports_modules = offsetof(PyInterpreterState, imports.modules), \256 .sysdict = offsetof(PyInterpreterState, sysdict), \257 .builtins = offsetof(PyInterpreterState, builtins), \258 .ceval_gil = offsetof(PyInterpreterState, ceval.gil), \259 .gil_runtime_state = offsetof(PyInterpreterState, _gil), \260 .gil_runtime_state_enabled = _Py_Debug_gilruntimestate_enabled, \261 .gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \262 .gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \263 .code_object_generation = offsetof(PyInterpreterState, _code_object_generation), \264 .tlbc_generation = _Py_Debug_interpreter_state_tlbc_generation, \265 }, \266 .thread_state = { \267 .size = sizeof(PyThreadState), \268 .prev = offsetof(PyThreadState, prev), \269 .next = offsetof(PyThreadState, next), \270 .interp = offsetof(PyThreadState, interp), \271 .current_frame = offsetof(PyThreadState, current_frame), \272 .thread_id = offsetof(PyThreadState, thread_id), \273 .native_thread_id = offsetof(PyThreadState, native_thread_id), \274 .datastack_chunk = offsetof(PyThreadState, datastack_chunk), \275 .status = offsetof(PyThreadState, _status), \276 }, \277 .interpreter_frame = { \278 .size = sizeof(_PyInterpreterFrame), \279 .previous = offsetof(_PyInterpreterFrame, previous), \280 .executable = offsetof(_PyInterpreterFrame, f_executable), \281 .instr_ptr = offsetof(_PyInterpreterFrame, instr_ptr), \282 .localsplus = offsetof(_PyInterpreterFrame, localsplus), \283 .owner = offsetof(_PyInterpreterFrame, owner), \284 .stackpointer = offsetof(_PyInterpreterFrame, stackpointer), \285 .tlbc_index = _Py_Debug_interpreter_frame_tlbc_index, \286 }, \287 .code_object = { \288 .size = sizeof(PyCodeObject), \289 .filename = offsetof(PyCodeObject, co_filename), \290 .name = offsetof(PyCodeObject, co_name), \291 .qualname = offsetof(PyCodeObject, co_qualname), \292 .linetable = offsetof(PyCodeObject, co_linetable), \293 .firstlineno = offsetof(PyCodeObject, co_firstlineno), \294 .argcount = offsetof(PyCodeObject, co_argcount), \295 .localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \296 .localspluskinds = offsetof(PyCodeObject, co_localspluskinds), \297 .co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \298 .co_tlbc = _Py_Debug_code_object_co_tlbc, \299 }, \300 .pyobject = { \301 .size = sizeof(PyObject), \302 .ob_type = offsetof(PyObject, ob_type), \303 }, \304 .type_object = { \305 .size = sizeof(PyTypeObject), \306 .tp_name = offsetof(PyTypeObject, tp_name), \307 .tp_repr = offsetof(PyTypeObject, tp_repr), \308 .tp_flags = offsetof(PyTypeObject, tp_flags), \309 }, \310 .tuple_object = { \311 .size = sizeof(PyTupleObject), \312 .ob_item = offsetof(PyTupleObject, ob_item), \313 .ob_size = offsetof(PyTupleObject, ob_base.ob_size), \314 }, \315 .list_object = { \316 .size = sizeof(PyListObject), \317 .ob_item = offsetof(PyListObject, ob_item), \318 .ob_size = offsetof(PyListObject, ob_base.ob_size), \319 }, \320 .set_object = { \321 .size = sizeof(PySetObject), \322 .used = offsetof(PySetObject, used), \323 .table = offsetof(PySetObject, table), \324 .mask = offsetof(PySetObject, mask), \325 }, \326 .dict_object = { \327 .size = sizeof(PyDictObject), \328 .ma_keys = offsetof(PyDictObject, ma_keys), \329 .ma_values = offsetof(PyDictObject, ma_values), \330 }, \331 .float_object = { \332 .size = sizeof(PyFloatObject), \333 .ob_fval = offsetof(PyFloatObject, ob_fval), \334 }, \335 .long_object = { \336 .size = sizeof(PyLongObject), \337 .lv_tag = offsetof(PyLongObject, long_value.lv_tag), \338 .ob_digit = offsetof(PyLongObject, long_value.ob_digit), \339 }, \340 .bytes_object = { \341 .size = sizeof(PyBytesObject), \342 .ob_size = offsetof(PyBytesObject, ob_base.ob_size), \343 .ob_sval = offsetof(PyBytesObject, ob_sval), \344 }, \345 .unicode_object = { \346 .size = sizeof(PyUnicodeObject), \347 .state = offsetof(PyUnicodeObject, _base._base.state), \348 .length = offsetof(PyUnicodeObject, _base._base.length), \349 .asciiobject_size = sizeof(PyASCIIObject), \350 }, \351 .gc = { \352 .size = sizeof(struct _gc_runtime_state), \353 .collecting = offsetof(struct _gc_runtime_state, collecting), \354 }, \355 .gen_object = { \356 .size = sizeof(PyGenObject), \357 .gi_name = offsetof(PyGenObject, gi_name), \358 .gi_iframe = offsetof(PyGenObject, gi_iframe), \359 .gi_frame_state = offsetof(PyGenObject, gi_frame_state), \360 }, \361 .llist_node = { \362 .next = offsetof(struct llist_node, next), \363 .prev = offsetof(struct llist_node, prev), \364 }, \365 .debugger_support = { \366 .eval_breaker = offsetof(PyThreadState, eval_breaker), \367 .remote_debugger_support = offsetof(PyThreadState, remote_debugger_support), \368 .remote_debugging_enabled = offsetof(PyInterpreterState, config.remote_debug), \369 .debugger_pending_call = offsetof(_PyRemoteDebuggerSupport, debugger_pending_call), \370 .debugger_script_path = offsetof(_PyRemoteDebuggerSupport, debugger_script_path), \371 .debugger_script_path_size = _Py_MAX_SCRIPT_PATH_SIZE, \372 }, \373}374 375 376#ifdef __cplusplus377}378#endif379#endif /* !Py_INTERNAL_DEBUG_OFFSETS_H */380 