https://github.com/python/cpython/commit/bd1e9afa74a38697c7e51df935b3348fa178391e
commit: bd1e9afa74a38697c7e51df935b3348fa178391e
branch: main
author: Maurycy Pawłowski-Wieroński <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-11-16T12:28:13Z
summary:
gh-149584: _remote_debugging: Deduplicate frame parsing (GH-162105)
Use the shared frame parser for copied stack chunks. Remove unused output
parameters while preserving remote reads and fallback behavior.
files:
M Modules/_remote_debugging/_remote_debugging.h
M Modules/_remote_debugging/asyncio.c
M Modules/_remote_debugging/frames.c
diff --git a/Modules/_remote_debugging/_remote_debugging.h
b/Modules/_remote_debugging/_remote_debugging.h
index 7bbcd8942de61f..532fed28741738 100644
--- a/Modules/_remote_debugging/_remote_debugging.h
+++ b/Modules/_remote_debugging/_remote_debugging.h
@@ -574,7 +574,6 @@ extern int parse_frame_object(
RemoteUnwinderObject *unwinder,
PyObject** result,
uintptr_t address,
- uintptr_t* address_of_code_object,
uintptr_t* previous_frame
);
@@ -583,7 +582,6 @@ extern int parse_frame_from_chunks(
PyObject **result,
uintptr_t address,
uintptr_t *previous_frame,
- uintptr_t *stackpointer,
StackChunkList *chunks
);
diff --git a/Modules/_remote_debugging/asyncio.c
b/Modules/_remote_debugging/asyncio.c
index 9fc04cf348d144..787f7921d7d74a 100644
--- a/Modules/_remote_debugging/asyncio.c
+++ b/Modules/_remote_debugging/asyncio.c
@@ -386,8 +386,7 @@ parse_coro_chain(
// Parse the previous frame using the gi_iframe from local copy
uintptr_t prev_frame;
uintptr_t gi_iframe_addr = coro_address +
(uintptr_t)unwinder->debug_offsets.gen_object.gi_iframe;
- uintptr_t address_of_code_object = 0;
- if (parse_frame_object(unwinder, &name, gi_iframe_addr,
&address_of_code_object, &prev_frame) < 0) {
+ if (parse_frame_object(unwinder, &name, gi_iframe_addr, &prev_frame) <
0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse
frame object in coro chain");
return -1;
}
@@ -776,14 +775,12 @@ parse_async_frame_chain(
return -1;
}
PyObject* frame_info = NULL;
- uintptr_t address_of_code_object;
uintptr_t this_frame = address_of_current_frame;
int res = parse_frame_object(
unwinder,
&frame_info,
address_of_current_frame,
- &address_of_code_object,
&address_of_current_frame
);
diff --git a/Modules/_remote_debugging/frames.c
b/Modules/_remote_debugging/frames.c
index 19a9b5369148a9..5df309109fcfe3 100644
--- a/Modules/_remote_debugging/frames.c
+++ b/Modules/_remote_debugging/frames.c
@@ -195,11 +195,8 @@ parse_frame_buffer(
RemoteUnwinderObject *unwinder,
PyObject** result,
const char *frame,
- uintptr_t* address_of_code_object,
uintptr_t* previous_frame
) {
- *address_of_code_object = 0;
-
*previous_frame = GET_MEMBER(uintptr_t, frame,
unwinder->debug_offsets.interpreter_frame.previous);
uintptr_t code_object = GET_MEMBER_NO_TAG(uintptr_t, frame,
unwinder->debug_offsets.interpreter_frame.executable);
int frame_valid = is_frame_valid(unwinder, (uintptr_t)frame, code_object);
@@ -217,8 +214,6 @@ parse_frame_buffer(
}
#endif
- *address_of_code_object = code_object;
-
CodeObjectContext code_ctx = {
.code_addr = code_object,
.instruction_pointer = instruction_pointer,
@@ -232,7 +227,6 @@ parse_frame_object(
RemoteUnwinderObject *unwinder,
PyObject** result,
uintptr_t address,
- uintptr_t* address_of_code_object,
uintptr_t* previous_frame
) {
char frame[SIZEOF_INTERP_FRAME];
@@ -249,7 +243,7 @@ parse_frame_object(
STATS_INC(unwinder, memory_reads);
STATS_ADD(unwinder, memory_bytes_read, SIZEOF_INTERP_FRAME);
- return parse_frame_buffer(unwinder, result, frame, address_of_code_object,
previous_frame);
+ return parse_frame_buffer(unwinder, result, frame, previous_frame);
}
int
@@ -258,41 +252,16 @@ parse_frame_from_chunks(
PyObject **result,
uintptr_t address,
uintptr_t *previous_frame,
- uintptr_t *stackpointer,
StackChunkList *chunks
) {
- void *frame_ptr = find_frame_in_chunks(chunks, address);
- if (!frame_ptr) {
+ const char *frame = find_frame_in_chunks(chunks, address);
+ if (!frame) {
PyErr_Format(PyExc_RuntimeError, "Frame at address 0x%lx not found in
stack chunks", address);
set_exception_cause(unwinder, PyExc_RuntimeError, "Frame not found in
stack chunks");
return -1;
}
- char *frame = (char *)frame_ptr;
- *previous_frame = GET_MEMBER(uintptr_t, frame,
unwinder->debug_offsets.interpreter_frame.previous);
- *stackpointer = GET_MEMBER(uintptr_t, frame,
unwinder->debug_offsets.interpreter_frame.stackpointer);
- uintptr_t code_object = GET_MEMBER_NO_TAG(uintptr_t, frame_ptr,
unwinder->debug_offsets.interpreter_frame.executable);
- int frame_valid = is_frame_valid(unwinder, (uintptr_t)frame, code_object);
- if (frame_valid != 1) {
- return frame_valid;
- }
-
- uintptr_t instruction_pointer = GET_MEMBER(uintptr_t, frame,
unwinder->debug_offsets.interpreter_frame.instr_ptr);
-
- // Get tlbc_index for free threading builds
- int32_t tlbc_index = 0;
-#ifdef Py_GIL_DISABLED
- if (unwinder->debug_offsets.interpreter_frame.tlbc_index != 0) {
- tlbc_index = GET_MEMBER(int32_t, frame,
unwinder->debug_offsets.interpreter_frame.tlbc_index);
- }
-#endif
-
- CodeObjectContext code_ctx = {
- .code_addr = code_object,
- .instruction_pointer = instruction_pointer,
- .tlbc_index = tlbc_index,
- };
- return parse_code_object(unwinder, result, &code_ctx);
+ return parse_frame_buffer(unwinder, result, frame, previous_frame);
}
/* ============================================================================
@@ -316,7 +285,6 @@ process_frame_chain(
int parse_result = 0;
PyObject *frame = NULL;
uintptr_t next_frame_addr = 0;
- uintptr_t stackpointer = 0;
last_frame_addr = frame_addr;
if (++frame_count > MAX_FRAME_CHAIN_DEPTH) {
@@ -328,28 +296,23 @@ process_frame_chain(
if (ctx->chunks && ctx->chunks->count > 0) {
parse_result = parse_frame_from_chunks(
- unwinder, &frame, frame_addr, &next_frame_addr, &stackpointer,
ctx->chunks);
+ unwinder, &frame, frame_addr, &next_frame_addr, ctx->chunks);
if (parse_result == 0) {
goto parsed_frame;
}
PyErr_Clear();
}
- {
- uintptr_t address_of_code_object = 0;
- if (ctx->prefetch.frame && ctx->prefetch.frame_addr == frame_addr)
{
- parse_result = parse_frame_buffer(
- unwinder, &frame, ctx->prefetch.frame,
- &address_of_code_object, &next_frame_addr);
- }
- else {
- parse_result = parse_frame_object(
- unwinder, &frame, frame_addr,
- &address_of_code_object, &next_frame_addr);
- }
- if (parse_result < 0) {
- set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to
parse frame object in chain");
- return -1;
- }
+ if (ctx->prefetch.frame && ctx->prefetch.frame_addr == frame_addr) {
+ parse_result = parse_frame_buffer(
+ unwinder, &frame, ctx->prefetch.frame, &next_frame_addr);
+ }
+ else {
+ parse_result = parse_frame_object(
+ unwinder, &frame, frame_addr, &next_frame_addr);
+ }
+ if (parse_result < 0) {
+ set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse
frame object in chain");
+ return -1;
}
parsed_frame:
@@ -543,17 +506,16 @@ try_full_cache_hit(
}
PyObject *current_frame = NULL;
- uintptr_t code_object_addr = 0;
uintptr_t previous_frame = 0;
int parse_result;
if (ctx->prefetch.frame && ctx->prefetch.frame_addr == ctx->frame_addr) {
parse_result = parse_frame_buffer(unwinder, ¤t_frame,
ctx->prefetch.frame,
- &code_object_addr, &previous_frame);
+ &previous_frame);
}
else {
parse_result = parse_frame_object(unwinder, ¤t_frame,
ctx->frame_addr,
- &code_object_addr, &previous_frame);
+ &previous_frame);
}
if (parse_result < 0) {
return -1;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]