Skip to content

[3.11] gh-94215: Fix error handling for line-tracing events (GH-94681) #94688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,6 @@ def test_issue42383(self):
expected = '(Pdb) The correct file was executed'
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)

@unittest.skip("test crashes, see gh-94215")
def test_gh_94215_crash(self):
script = """\
def func():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix an issue where exceptions raised by line-tracing events would cause
frames to be left in an invalid state, possibly resulting in a hard crash of
the interpreter.
19 changes: 14 additions & 5 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5642,16 +5642,25 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
err = maybe_call_line_trace(tstate->c_tracefunc,
tstate->c_traceobj,
tstate, frame, instr_prev);
// Reload possibly changed frame fields:
stack_pointer = _PyFrame_GetStackPointer(frame);
frame->stacktop = -1;
// next_instr is only reloaded if tracing *does not* raise.
// This is consistent with the behavior of older Python
// versions. If a trace function sets a new f_lineno and
// *then* raises, we use the *old* location when searching
// for an exception handler, displaying the traceback, and
// so on:
if (err) {
/* trace function raised an exception */
// next_instr wasn't incremented at the start of this
// instruction. Increment it before handling the error,
// so that it looks the same as a "normal" instruction:
next_instr++;
goto error;
}
/* Reload possibly changed frame fields */
// Reload next_instr. Don't increment it, though, since
// we're going to re-dispatch to the "true" instruction now:
next_instr = frame->prev_instr;

stack_pointer = _PyFrame_GetStackPointer(frame);
frame->stacktop = -1;
}
}
}
Expand Down