]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-123967: Fix faulthandler for trampoline frames (GH-127329) (#127362)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 30 Nov 2024 09:14:29 +0000 (10:14 +0100)
committerGitHub <noreply@github.com>
Sat, 30 Nov 2024 09:14:29 +0000 (09:14 +0000)
gh-123967: Fix faulthandler for trampoline frames (GH-127329)

If the top-most frame is a trampoline frame, skip it.
(cherry picked from commit 58e334e1431b2ed6b70ee42501ea73e08084e769)

Co-authored-by: Victor Stinner <vstinner@python.org>
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++;
     }
 }