|
20 | 20 | # enough to let it install the compiled JIT entry and set a temporary |
21 | 21 | # breakpoint on the resulting address. |
22 | 22 | MAX_ENTRY_SETUP_STEPS = 20 |
23 | | -# After landing on the JIT entry frame, single-step a little further into the |
24 | | -# blob so the backtrace is taken from JIT code itself rather than the |
25 | | -# immediate helper-return site. |
26 | | -JIT_ENTRY_SINGLE_STEPS = 2 |
| 23 | +# After landing on the JIT entry frame, single-step a bounded number of |
| 24 | +# instructions further into the blob so the backtrace is taken from JIT code |
| 25 | +# itself rather than the immediate helper-return site. The exact number of |
| 26 | +# steps is not significant: each step is cross-checked against the selected |
| 27 | +# frame's symbol so the test fails loudly if stepping escapes the registered |
| 28 | +# JIT region, instead of asserting against a misleading backtrace. |
| 29 | +MAX_JIT_ENTRY_STEPS = 4 |
27 | 30 | EVAL_FRAME_RE = r"(_PyEval_EvalFrameDefault|_PyEval_Vector)" |
28 | 31 |
|
29 | 32 | FINISH_TO_JIT_ENTRY = ( |
|
49 | 52 | "else:\\n" |
50 | 53 | " raise RuntimeError('compiled JIT entry was not installed')\\n\")" |
51 | 54 | ) |
| 55 | +STEP_INSIDE_JIT_ENTRY = ( |
| 56 | + "python exec(\"import gdb\\n" |
| 57 | + "target = 'py::jit_entry:<jit>'\\n" |
| 58 | + f"for _ in range({MAX_JIT_ENTRY_STEPS}):\\n" |
| 59 | + " frame = gdb.selected_frame()\\n" |
| 60 | + " if frame is None or frame.name() != target:\\n" |
| 61 | + " raise RuntimeError('left JIT region during stepping: '\\n" |
| 62 | + " + repr(frame and frame.name()))\\n" |
| 63 | + " gdb.execute('si')\\n" |
| 64 | + "frame = gdb.selected_frame()\\n" |
| 65 | + "if frame is None or frame.name() != target:\\n" |
| 66 | + " raise RuntimeError('stepped out of JIT region after si')\\n\")" |
| 67 | +) |
52 | 68 |
|
53 | 69 |
|
54 | 70 | def setUpModule(): |
@@ -111,7 +127,7 @@ def test_bt_unwinds_from_inside_jit_entry(self): |
111 | 127 | script=JIT_SAMPLE_SCRIPT, |
112 | 128 | cmds_after_breakpoint=[ |
113 | 129 | FINISH_TO_JIT_ENTRY, |
114 | | - *(["si"] * JIT_ENTRY_SINGLE_STEPS), |
| 130 | + STEP_INSIDE_JIT_ENTRY, |
115 | 131 | "bt", |
116 | 132 | ], |
117 | 133 | PYTHON_JIT="1", |
|
0 commit comments