@@ -4993,27 +4993,28 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
4993
4993
PyCodeAddressRange * bounds , int * instr_prev )
4994
4994
{
4995
4995
int result = 0 ;
4996
- int line = frame -> f_lineno ;
4997
4996
4998
- /* If the last instruction executed isn't in the current
4999
- instruction window, reset the window.
5000
- */
5001
- line = _PyCode_CheckLineNumber (frame -> f_lasti , bounds );
5002
4997
/* If the last instruction falls at the start of a line or if it
5003
4998
represents a jump backwards, update the frame's line number and
5004
4999
then call the trace function if we're tracing source lines.
5005
5000
*/
5006
- if ((line != frame -> f_lineno || frame -> f_lasti < * instr_prev )) {
5007
- if (line != -1 ) {
5001
+ int lastline = bounds -> ar_line ;
5002
+ int line = _PyCode_CheckLineNumber (frame -> f_lasti , bounds );
5003
+ if (line != -1 && frame -> f_trace_lines ) {
5004
+ /* Trace backward edges or first instruction of a new line */
5005
+ if (frame -> f_lasti < * instr_prev ||
5006
+ (line != lastline && frame -> f_lasti == bounds -> ar_start ))
5007
+ {
5008
5008
frame -> f_lineno = line ;
5009
- if (frame -> f_trace_lines ) {
5010
- result = call_trace (func , obj , tstate , frame , PyTrace_LINE , Py_None );
5011
- }
5009
+ result = call_trace (func , obj , tstate , frame , PyTrace_LINE , Py_None );
5010
+ frame -> f_lineno = 0 ;
5012
5011
}
5013
5012
}
5014
5013
/* Always emit an opcode event if we're tracing all opcodes. */
5015
5014
if (frame -> f_trace_opcodes ) {
5015
+ frame -> f_lineno = _PyCode_CheckLineNumber (frame -> f_lasti , bounds );
5016
5016
result = call_trace (func , obj , tstate , frame , PyTrace_OPCODE , Py_None );
5017
+ frame -> f_lineno = 0 ;
5017
5018
}
5018
5019
* instr_prev = frame -> f_lasti ;
5019
5020
return result ;
0 commit comments