Skip to content

Commit 58e334e

Browse files
authored
gh-123967: Fix faulthandler for trampoline frames (#127329)
If the top-most frame is a trampoline frame, skip it.
1 parent 9328db7 commit 58e334e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix faulthandler for trampoline frames. If the top-most frame is a
2+
trampoline frame, skip it. Patch by Victor Stinner.

Python/traceback.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ _Py_DumpASCII(int fd, PyObject *text)
890890
static void
891891
dump_frame(int fd, _PyInterpreterFrame *frame)
892892
{
893+
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
894+
893895
PyCodeObject *code =_PyFrame_GetCode(frame);
894896
PUTS(fd, " File ");
895897
if (code->co_filename != NULL
@@ -963,6 +965,17 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
963965

964966
unsigned int depth = 0;
965967
while (1) {
968+
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
969+
/* Trampoline frame */
970+
frame = frame->previous;
971+
if (frame == NULL) {
972+
break;
973+
}
974+
975+
/* Can't have more than one shim frame in a row */
976+
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
977+
}
978+
966979
if (MAX_FRAME_DEPTH <= depth) {
967980
if (MAX_FRAME_DEPTH < depth) {
968981
PUTS(fd, "plus ");
@@ -971,20 +984,12 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
971984
}
972985
break;
973986
}
987+
974988
dump_frame(fd, frame);
975989
frame = frame->previous;
976990
if (frame == NULL) {
977991
break;
978992
}
979-
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
980-
/* Trampoline frame */
981-
frame = frame->previous;
982-
}
983-
if (frame == NULL) {
984-
break;
985-
}
986-
/* Can't have more than one shim frame in a row */
987-
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
988993
depth++;
989994
}
990995
}

0 commit comments

Comments
 (0)