diff options
author | Mark Shannon <mark@hotpy.org> | 2021-01-05 12:04:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 12:04:10 (GMT) |
commit | ee9f98d9f4b881ee15868a836a2b99271df1bc0e (patch) | |
tree | 5f5a6b4cc99c86d7ee99cf0c8287cf601abd99a7 /Python/ceval.c | |
parent | e40e2a2cc94c554e7e245a8ca5a7432d31a95766 (diff) | |
download | cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.zip cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.tar.gz cpython-ee9f98d9f4b881ee15868a836a2b99271df1bc0e.tar.bz2 |
bpo-42823: Fix frame lineno when frame.f_trace is set (GH-24099)
* Add test for frame.f_lineno with/without tracing.
* Make sure that frame.f_lineno is correct regardless of whether frame.f_trace is set.
* Update importlib
* Add NEWS
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index f0f3953..6092156 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4993,27 +4993,28 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, PyCodeAddressRange *bounds, int *instr_prev) { int result = 0; - int line = frame->f_lineno; - /* If the last instruction executed isn't in the current - instruction window, reset the window. - */ - line = _PyCode_CheckLineNumber(frame->f_lasti, bounds); /* If the last instruction falls at the start of a line or if it represents a jump backwards, update the frame's line number and then call the trace function if we're tracing source lines. */ - if ((line != frame->f_lineno || frame->f_lasti < *instr_prev)) { - if (line != -1) { + int lastline = bounds->ar_line; + int line = _PyCode_CheckLineNumber(frame->f_lasti, bounds); + if (line != -1 && frame->f_trace_lines) { + /* Trace backward edges or first instruction of a new line */ + if (frame->f_lasti < *instr_prev || + (line != lastline && frame->f_lasti == bounds->ar_start)) + { frame->f_lineno = line; - if (frame->f_trace_lines) { - result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None); - } + result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None); + frame->f_lineno = 0; } } /* Always emit an opcode event if we're tracing all opcodes. */ if (frame->f_trace_opcodes) { + frame->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti, bounds); result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None); + frame->f_lineno = 0; } *instr_prev = frame->f_lasti; return result; |