@@ -1083,8 +1083,8 @@ static const char *const event_names [] = {
10831083
10841084static int
10851085call_instrumentation_vector (
1086- PyThreadState * tstate , int event ,
1087- _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , Py_ssize_t nargs , PyObject * args [])
1086+ _Py_CODEUNIT * instr , PyThreadState * tstate , int event ,
1087+ _PyInterpreterFrame * frame , _Py_CODEUNIT * arg2 , Py_ssize_t nargs , PyObject * args [])
10881088{
10891089 if (tstate -> tracing ) {
10901090 return 0 ;
@@ -1097,13 +1097,13 @@ call_instrumentation_vector(
10971097 int offset = (int )(instr - _PyFrame_GetBytecode (frame ));
10981098 /* Offset visible to user should be the offset in bytes, as that is the
10991099 * convention for APIs involving code offsets. */
1100- int bytes_offset = offset * (int )sizeof (_Py_CODEUNIT );
1101- PyObject * offset_obj = PyLong_FromLong (bytes_offset );
1102- if (offset_obj == NULL ) {
1100+ int bytes_arg2 = ( int )( arg2 - _PyFrame_GetBytecode ( frame )) * (int )sizeof (_Py_CODEUNIT );
1101+ PyObject * arg2_obj = PyLong_FromLong (bytes_arg2 );
1102+ if (arg2_obj == NULL ) {
11031103 return -1 ;
11041104 }
11051105 assert (args [2 ] == NULL );
1106- args [2 ] = offset_obj ;
1106+ args [2 ] = arg2_obj ;
11071107 PyInterpreterState * interp = tstate -> interp ;
11081108 uint8_t tools = get_tools_for_instruction (code , interp , offset , event );
11091109 size_t nargsf = (size_t ) nargs | PY_VECTORCALL_ARGUMENTS_OFFSET ;
@@ -1141,7 +1141,7 @@ call_instrumentation_vector(
11411141 }
11421142 }
11431143 }
1144- Py_DECREF (offset_obj );
1144+ Py_DECREF (arg2_obj );
11451145 return err ;
11461146}
11471147
@@ -1151,7 +1151,7 @@ _Py_call_instrumentation(
11511151 _PyInterpreterFrame * frame , _Py_CODEUNIT * instr )
11521152{
11531153 PyObject * args [3 ] = { NULL , NULL , NULL };
1154- return call_instrumentation_vector (tstate , event , frame , instr , 2 , args );
1154+ return call_instrumentation_vector (instr , tstate , event , frame , instr , 2 , args );
11551155}
11561156
11571157int
@@ -1160,7 +1160,7 @@ _Py_call_instrumentation_arg(
11601160 _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , PyObject * arg )
11611161{
11621162 PyObject * args [4 ] = { NULL , NULL , NULL , arg };
1163- return call_instrumentation_vector (tstate , event , frame , instr , 3 , args );
1163+ return call_instrumentation_vector (instr , tstate , event , frame , instr , 3 , args );
11641164}
11651165
11661166int
@@ -1169,25 +1169,25 @@ _Py_call_instrumentation_2args(
11691169 _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , PyObject * arg0 , PyObject * arg1 )
11701170{
11711171 PyObject * args [5 ] = { NULL , NULL , NULL , arg0 , arg1 };
1172- return call_instrumentation_vector (tstate , event , frame , instr , 4 , args );
1172+ return call_instrumentation_vector (instr , tstate , event , frame , instr , 4 , args );
11731173}
11741174
11751175_Py_CODEUNIT *
11761176_Py_call_instrumentation_jump (
1177- PyThreadState * tstate , int event ,
1178- _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , _Py_CODEUNIT * target )
1177+ _Py_CODEUNIT * instr , PyThreadState * tstate , int event ,
1178+ _PyInterpreterFrame * frame , _Py_CODEUNIT * src , _Py_CODEUNIT * dest )
11791179{
11801180 assert (event == PY_MONITORING_EVENT_JUMP ||
11811181 event == PY_MONITORING_EVENT_BRANCH_RIGHT ||
11821182 event == PY_MONITORING_EVENT_BRANCH_LEFT );
1183- int to = (int )(target - _PyFrame_GetBytecode (frame ));
1183+ int to = (int )(dest - _PyFrame_GetBytecode (frame ));
11841184 PyObject * to_obj = PyLong_FromLong (to * (int )sizeof (_Py_CODEUNIT ));
11851185 if (to_obj == NULL ) {
11861186 return NULL ;
11871187 }
11881188 PyObject * args [4 ] = { NULL , NULL , NULL , to_obj };
11891189 _Py_CODEUNIT * instr_ptr = frame -> instr_ptr ;
1190- int err = call_instrumentation_vector (tstate , event , frame , instr , 3 , args );
1190+ int err = call_instrumentation_vector (instr , tstate , event , frame , src , 3 , args );
11911191 Py_DECREF (to_obj );
11921192 if (err ) {
11931193 return NULL ;
@@ -1196,7 +1196,7 @@ _Py_call_instrumentation_jump(
11961196 /* The callback has caused a jump (by setting the line number) */
11971197 return frame -> instr_ptr ;
11981198 }
1199- return target ;
1199+ return dest ;
12001200}
12011201
12021202static void
@@ -1206,7 +1206,7 @@ call_instrumentation_vector_protected(
12061206{
12071207 assert (_PyErr_Occurred (tstate ));
12081208 PyObject * exc = _PyErr_GetRaisedException (tstate );
1209- int err = call_instrumentation_vector (tstate , event , frame , instr , nargs , args );
1209+ int err = call_instrumentation_vector (instr , tstate , event , frame , instr , nargs , args );
12101210 if (err ) {
12111211 Py_XDECREF (exc );
12121212 }
@@ -1498,9 +1498,10 @@ initialize_lines(PyCodeObject *code)
14981498 case END_FOR :
14991499 case END_SEND :
15001500 case RESUME :
1501+ case POP_ITER :
15011502 /* END_FOR cannot start a line, as it is skipped by FOR_ITER
15021503 * END_SEND cannot start a line, as it is skipped by SEND
1503- * RESUME must not be instrumented with INSTRUMENT_LINE */
1504+ * RESUME and POP_ITER must not be instrumented with INSTRUMENT_LINE */
15041505 line_data [i ].original_opcode = 0 ;
15051506 break ;
15061507 default :
@@ -1572,11 +1573,14 @@ initialize_lines(PyCodeObject *code)
15721573 }
15731574 assert (target >= 0 );
15741575 if (line_data [target ].line_delta != NO_LINE ) {
1575- line_data [target ].original_opcode = _Py_GetBaseCodeUnit (code , target ).op .code ;
1576- if (line_data [target ].line_delta == COMPUTED_LINE_LINENO_CHANGE ) {
1577- // If the line is a jump target, we are not sure if the line
1578- // number changes, so we set it to COMPUTED_LINE.
1579- line_data [target ].line_delta = COMPUTED_LINE ;
1576+ int opcode = _Py_GetBaseCodeUnit (code , target ).op .code ;
1577+ if (opcode != POP_ITER ) {
1578+ line_data [target ].original_opcode = opcode ;
1579+ if (line_data [target ].line_delta == COMPUTED_LINE_LINENO_CHANGE ) {
1580+ // If the line is a jump target, we are not sure if the line
1581+ // number changes, so we set it to COMPUTED_LINE.
1582+ line_data [target ].line_delta = COMPUTED_LINE ;
1583+ }
15801584 }
15811585 }
15821586 }
0 commit comments