]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] GH-96864: Check for error between line and opcode events (GH-96969)
authorBrandt Bucher <brandtbucher@microsoft.com>
Tue, 20 Sep 2022 18:42:06 +0000 (11:42 -0700)
committerGitHub <noreply@github.com>
Tue, 20 Sep 2022 18:42:06 +0000 (11:42 -0700)
(cherry picked from commit c10e33ac119d96c4d88d5ae8b59e65a76ae0ad3c)

Lib/test/test_sys_settrace.py
Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst [new file with mode: 0644]
Python/ceval.c

index 1f509eee556b01b6be53eb13144eb6d32102cdfd..312b909426ee904ad67916fd4bef7c22be321e81 100644 (file)
@@ -1310,6 +1310,20 @@ class RaisingTraceFuncTestCase(unittest.TestCase):
         finally:
             sys.settrace(existing)
 
+    def test_line_event_raises_before_opcode_event(self):
+        exception = ValueError("BOOM!")
+        def trace(frame, event, arg):
+            if event == "line":
+                raise exception
+            frame.f_trace_opcodes = True
+            return trace
+        def f():
+            pass
+        with self.assertRaises(ValueError) as caught:
+            sys.settrace(trace)
+            f()
+        self.assertIs(caught.exception, exception)
+
 
 # 'Jump' tests: assigning to frame.f_lineno within a trace function
 # moves the execution position - it's how debuggers implement a Jump
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-16-12-36-13.gh-issue-96864.PLU3i8.rst
new file mode 100644 (file)
index 0000000..c0d41ae
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a possible assertion failure, fatal error, or :exc:`SystemError` if a
+line tracing event raises an exception while opcode tracing is enabled.
index df4b9a84a2defa9829a977eb8fcffaec9f5e03f8..9719177e19bab8297ac964332c0c055d30397d6c 100644 (file)
@@ -5512,7 +5512,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
         }
     }
     /* Always emit an opcode event if we're tracing all opcodes. */
-    if (frame->f_trace_opcodes) {
+    if (frame->f_trace_opcodes && result == 0) {
         result = call_trace(func, obj, tstate, frame, trace_info, PyTrace_OPCODE, Py_None);
     }
     return result;