Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address feedback
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
  • Loading branch information
pablogsal committed Jul 11, 2023
commit de2154a9e0b1b61b5ecc214a26600bc26702314d
43 changes: 39 additions & 4 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ typedef struct _Py_AuditHookEntry {
} _Py_AuditHookEntry;

typedef struct _Py_DebugOffsets {
Comment thread
pablogsal marked this conversation as resolved.
Comment thread
pablogsal marked this conversation as resolved.
char cookie[8];
uint64_t version;
// Runtime state offset;
struct _runtime_state {
off_t finalizing;
Expand All @@ -69,6 +71,8 @@ typedef struct _Py_DebugOffsets {
off_t sysdict;
off_t builtins;
off_t ceval_gil;
off_t gil_runtime_state_locked;
off_t gil_runtime_state_holder;
} interpreter_state;

// Thread state offset;
Expand All @@ -78,16 +82,23 @@ typedef struct _Py_DebugOffsets {
off_t interp;
off_t cframe;
off_t thread_id;
off_t native_thread_id;
} thread_state;

// Frame object offset;
struct _frame_object {
// InterpreterFrame offset;
struct _interpreter_frame {
off_t previous;
off_t executable;
off_t prev_instr;
off_t localsplus;
off_t owner;
} frame_object;
} interpreter_frame;

// CFrame offset;
struct _cframe {
off_t current_frame;
off_t previous;
} cframe;

// Code object offset;
struct _code_object {
Expand All @@ -97,8 +108,24 @@ typedef struct _Py_DebugOffsets {
off_t firstlineno;
off_t argcount;
off_t localsplusnames;
off_t localspluskinds;
off_t co_code_adaptive;
} code_object;

// PyObject offset;
struct _pyobject {
off_t ob_type;
} pyobject;

// PyTypeObject object offset;
struct _type_object {
off_t tp_name;
} type_object;

// PyTuple object offset;
struct _tuple_object {
off_t ob_item;
} tuple_object;
} _Py_DebugOffsets;

/* Full Python runtime state */
Expand All @@ -111,8 +138,16 @@ typedef struct pyruntimestate {
* debuggers. Out of process debuggers will use the offsets contained in this
* field to be able to locate other fields in several interpreter structures
* in a way that doesn't require them to know the exact layout of those
* structures */
* structures.
*
* IMPORTANT:
* This struct is **NOT** backwards compatible between minor version of the
* interpreter and the members, order of members and size can change between
* minor versions. This struct is only guaranteed to be stable between patch
* versions for a given minor version of the interpreter.
*/
_Py_DebugOffsets debug_offsets;

/* Has been initialized to a safe state.

In order to be effective, this must be set to 0 during or right
Expand Down
21 changes: 20 additions & 1 deletion Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ extern PyTypeObject _PyExc_MemoryError;
#define _PyRuntimeState_INIT(runtime) \
{ \
.debug_offsets = { \
.cookie = "xdebugpy", \
.version = PY_VERSION_HEX, \
.runtime_state = { \
.finalizing = offsetof(_PyRuntimeState, _finalizing), \
.interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
Expand All @@ -36,30 +38,47 @@ extern PyTypeObject _PyExc_MemoryError;
.sysdict = offsetof(PyInterpreterState, sysdict), \
.builtins = offsetof(PyInterpreterState, builtins), \
.ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
.gil_runtime_state_locked = offsetof(PyInterpreterState, _gil.locked), \
.gil_runtime_state_holder = offsetof(PyInterpreterState, _gil.last_holder), \
}, \
.thread_state = { \
.prev = offsetof(PyThreadState, prev), \
.next = offsetof(PyThreadState, next), \
.interp = offsetof(PyThreadState, interp), \
.cframe = offsetof(PyThreadState, cframe), \
.thread_id = offsetof(PyThreadState, thread_id), \
.native_thread_id = offsetof(PyThreadState, native_thread_id), \
}, \
.frame_object = { \
.interpreter_frame = { \
.previous = offsetof(_PyInterpreterFrame, previous), \
.executable = offsetof(_PyInterpreterFrame, f_executable), \
.prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
.localsplus = offsetof(_PyInterpreterFrame, localsplus), \
.owner = offsetof(_PyInterpreterFrame, owner), \
}, \
.cframe = { \
.current_frame = offsetof(_PyCFrame, current_frame), \
.previous = offsetof(_PyCFrame, previous), \
}, \
.code_object = { \
.filename = offsetof(PyCodeObject, co_filename), \
.name = offsetof(PyCodeObject, co_name), \
.linetable = offsetof(PyCodeObject, co_linetable), \
.firstlineno = offsetof(PyCodeObject, co_firstlineno), \
.argcount = offsetof(PyCodeObject, co_argcount), \
.localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
.localspluskinds = offsetof(PyCodeObject, co_localspluskinds), \
.co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
}, \
.pyobject = { \
.ob_type = offsetof(PyObject, ob_type), \
}, \
.type_object = { \
.tp_name = offsetof(PyTypeObject, tp_name), \
}, \
.tuple_object = { \
.ob_item = offsetof(PyTupleObject, ob_item), \
}, \
}, \
.allocators = { \
.standard = _pymem_allocators_standard_INIT(runtime), \
Expand Down