77
88
99JIT_SAMPLE_SCRIPT = os .path .join (os .path .dirname (__file__ ), "gdb_jit_sample.py" )
10+ # In batch GDB, break in builtin_id() while it is running under JIT,
11+ # then repeatedly "finish" until the selected frame is the executor.
12+ # That gives a deterministic backtrace starting with py::jit_executor:<jit>.
13+ #
14+ # builtin_id() sits only a few helper frames above the executor on this path.
15+ # This bound is just a generous upper limit so the test fails clearly if the
16+ # expected stack shape changes.
17+ MAX_FINISH_STEPS = 20
18+ # After landing on the executor frame, single-step a little further into the
19+ # blob so the backtrace is taken from executor code itself rather than the
20+ # immediate helper-return site.
21+ EXECUTOR_SINGLE_STEPS = 2
22+
23+ FINISH_TO_JIT_EXECUTOR = (
24+ "python exec(\" import gdb\\ n"
25+ "target = 'py::jit_executor:<jit>'\\ n"
26+ f"for _ in range({ MAX_FINISH_STEPS } ):\\ n"
27+ " frame = gdb.selected_frame()\\ n"
28+ " if frame is not None and frame.name() == target:\\ n"
29+ " break\\ n"
30+ " gdb.execute('finish')\\ n"
31+ "else:\\ n"
32+ " raise RuntimeError('did not reach %s' % target)\\ n\" )"
33+ )
1034
1135
1236def setUpModule ():
@@ -24,12 +48,30 @@ def test_bt_unwinds_through_jit_frames(self):
2448 cmds_after_breakpoint = ["bt" ],
2549 PYTHON_JIT = "1" ,
2650 )
27- self .assertIn ("py::jit_executor:<jit>" , gdb_output )
28- self .assertIn ("py::jit_shim:<jit>" , gdb_output )
2951 self .assertRegex (
3052 gdb_output ,
3153 re .compile (
32- r"py::jit_executor:<jit>.*(_PyEval_EvalFrameDefault|_PyEval_Vector)" ,
54+ r"py::jit_executor:<jit>.*py::jit_shim:<jit>.*"
55+ r"(_PyEval_EvalFrameDefault|_PyEval_Vector)" ,
56+ re .DOTALL ,
57+ ),
58+ )
59+
60+ def test_bt_unwinds_from_inside_jit_executor (self ):
61+ gdb_output = self .get_stack_trace (
62+ script = JIT_SAMPLE_SCRIPT ,
63+ cmds_after_breakpoint = [
64+ FINISH_TO_JIT_EXECUTOR ,
65+ * (["si" ] * EXECUTOR_SINGLE_STEPS ),
66+ "bt" ,
67+ ],
68+ PYTHON_JIT = "1" ,
69+ )
70+ self .assertRegex (
71+ gdb_output ,
72+ re .compile (
73+ r"#0\s+py::jit_executor:<jit>.*#1\s+py::jit_shim:<jit>.*"
74+ r"(_PyEval_EvalFrameDefault|_PyEval_Vector)" ,
3375 re .DOTALL ,
3476 ),
3577 )
0 commit comments