]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44570: Fix line tracing for forwards jumps to duplicated tails (GH-27068)
authorMark Shannon <mark@hotpy.org>
Thu, 8 Jul 2021 18:21:09 +0000 (19:21 +0100)
committerGitHub <noreply@github.com>
Thu, 8 Jul 2021 18:21:09 +0000 (19:21 +0100)
Lib/test/test_sys_settrace.py
Python/ceval.c

index 5f2b908d87acb8dea1e5e311960f7870487e114f..c42c69d0c807b58c4567504166cff8a9b55cd7f6 100644 (file)
@@ -1041,6 +1041,41 @@ class TraceTestCase(unittest.TestCase):
              (-8, 'return'),
              (1, 'return')])
 
+    def test_flow_converges_on_same_line(self):
+
+        def foo(x):
+            if x:
+                try:
+                    1/(x - 1)
+                except ZeroDivisionError:
+                    pass
+            return x
+
+        def func():
+            for i in range(2):
+                foo(i)
+
+        self.run_and_compare(func,
+            [(0, 'call'),
+             (1, 'line'),
+             (2, 'line'),
+             (-8, 'call'),
+             (-7, 'line'),
+             (-2, 'line'),
+             (-2, 'return'),
+             (1, 'line'),
+             (2, 'line'),
+             (-8, 'call'),
+             (-7, 'line'),
+             (-6, 'line'),
+             (-5, 'line'),
+             (-5, 'exception'),
+             (-4, 'line'),
+             (-3, 'line'),
+             (-2, 'line'),
+             (-2, 'return'),
+             (1, 'line'),
+             (1, 'return')])
 
 class SkipLineEventsTraceTestCase(TraceTestCase):
     """Repeat the trace tests, but with per-line events skipped"""
index 611a39de75d1a0a50b1e91e4696836ed6af7b93f..22184058af2d4b4ea1a7d21f4b1e0ebffe89f65f 100644 (file)
@@ -5476,10 +5476,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
     int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds);
     int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds);
     if (line != -1 && frame->f_trace_lines) {
-        /* Trace backward edges or first instruction of a new line */
-        if (frame->f_lasti < instr_prev ||
-            (line != lastline && frame->f_lasti*2 == tstate->trace_info.bounds.ar_start))
-        {
+        /* Trace backward edges or if line number has changed */
+        if (frame->f_lasti < instr_prev || line != lastline) {
             result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None);
         }
     }