Skip to content

Commit

Permalink
pythonGH-96864: Check for error between line and opcode events (pytho…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher authored Sep 19, 2022
1 parent 5b3a256 commit c10e33a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,20 @@ def g(frame, event, arg):
finally:
sys.settrace(existing)

def test_line_event_raises_before_opcode_event(self):
exception = ValueError("BOOM!")
def trace(frame, event, arg):
if event == "line":
raise exception
frame.f_trace_opcodes = True
return trace
def f():
pass
with self.assertRaises(ValueError) as caught:
sys.settrace(trace)
f()
self.assertIs(caught.exception, exception)


# 'Jump' tests: assigning to frame.f_lineno within a trace function
# moves the execution position - it's how debuggers implement a Jump
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a possible assertion failure, fatal error, or :exc:`SystemError` if a
line tracing event raises an exception while opcode tracing is enabled.
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -6293,7 +6293,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
}
}
/* Always emit an opcode event if we're tracing all opcodes. */
if (f->f_trace_opcodes) {
if (f->f_trace_opcodes && result == 0) {
result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None);
}
return result;
Expand Down

0 comments on commit c10e33a

Please sign in to comment.