Skip to content

Commit 3eeddb9

Browse files
committed
Cross-check stepping stays inside JIT region in test_gdb.test_jit
Replace the fixed JIT_ENTRY_SINGLE_STEPS=2 loop with a helper that verifies frame.name() after every si, so a stencil or toolchain change that drifts the PC fails loudly instead of matching the tolerant final regex by accident.
1 parent 93bbf99 commit 3eeddb9

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Lib/test/test_gdb/test_jit.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
# enough to let it install the compiled JIT entry and set a temporary
2121
# breakpoint on the resulting address.
2222
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
2730
EVAL_FRAME_RE = r"(_PyEval_EvalFrameDefault|_PyEval_Vector)"
2831

2932
FINISH_TO_JIT_ENTRY = (
@@ -49,6 +52,19 @@
4952
"else:\\n"
5053
" raise RuntimeError('compiled JIT entry was not installed')\\n\")"
5154
)
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+
)
5268

5369

5470
def setUpModule():
@@ -111,7 +127,7 @@ def test_bt_unwinds_from_inside_jit_entry(self):
111127
script=JIT_SAMPLE_SCRIPT,
112128
cmds_after_breakpoint=[
113129
FINISH_TO_JIT_ENTRY,
114-
*(["si"] * JIT_ENTRY_SINGLE_STEPS),
130+
STEP_INSIDE_JIT_ENTRY,
115131
"bt",
116132
],
117133
PYTHON_JIT="1",

0 commit comments

Comments
 (0)