]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123967: Fix faulthandler for trampoline frames (#127329)
authorVictor Stinner <vstinner@python.org>
Wed, 27 Nov 2024 15:14:49 +0000 (16:14 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Nov 2024 15:14:49 +0000 (16:14 +0100)
If the top-most frame is a trampoline frame, skip it.

Misc/NEWS.d/next/Library/2024-11-27-14-06-35.gh-issue-123967.wxUmnW.rst [new file with mode: 0644]
Python/traceback.c

diff --git a/Misc/NEWS.d/next/Library/2024-11-27-14-06-35.gh-issue-123967.wxUmnW.rst b/Misc/NEWS.d/next/Library/2024-11-27-14-06-35.gh-issue-123967.wxUmnW.rst
new file mode 100644 (file)
index 0000000..788fe0c
--- /dev/null
@@ -0,0 +1,2 @@
+Fix faulthandler for trampoline frames. If the top-most frame is a
+trampoline frame, skip it. Patch by Victor Stinner.
index 47b77c9108dd9a78fef6acbae21738e9305de803..e819909b6045c35e265d628170381f8b48a7688c 100644 (file)
@@ -890,6 +890,8 @@ done:
 static void
 dump_frame(int fd, _PyInterpreterFrame *frame)
 {
+    assert(frame->owner != FRAME_OWNED_BY_CSTACK);
+
     PyCodeObject *code =_PyFrame_GetCode(frame);
     PUTS(fd, "  File ");
     if (code->co_filename != NULL
@@ -963,6 +965,17 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
 
     unsigned int depth = 0;
     while (1) {
+        if (frame->owner == FRAME_OWNED_BY_CSTACK) {
+            /* Trampoline frame */
+            frame = frame->previous;
+            if (frame == NULL) {
+                break;
+            }
+
+            /* Can't have more than one shim frame in a row */
+            assert(frame->owner != FRAME_OWNED_BY_CSTACK);
+        }
+
         if (MAX_FRAME_DEPTH <= depth) {
             if (MAX_FRAME_DEPTH < depth) {
                 PUTS(fd, "plus ");
@@ -971,20 +984,12 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
             }
             break;
         }
+
         dump_frame(fd, frame);
         frame = frame->previous;
         if (frame == NULL) {
             break;
         }
-        if (frame->owner == FRAME_OWNED_BY_CSTACK) {
-            /* Trampoline frame */
-            frame = frame->previous;
-        }
-        if (frame == NULL) {
-            break;
-        }
-        /* Can't have more than one shim frame in a row */
-        assert(frame->owner != FRAME_OWNED_BY_CSTACK);
         depth++;
     }
 }