@@ -566,7 +566,13 @@ de_instrument(PyCodeObject *code, int i, int event)
566566 _Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
567567 uint8_t * opcode_ptr = & instr -> op .code ;
568568 int opcode = * opcode_ptr ;
569- assert (opcode != ENTER_EXECUTOR );
569+ if (opcode == ENTER_EXECUTOR ) {
570+ int oparg = instr -> op .arg ;
571+ _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
572+ opcode_ptr = & exec -> vm_data .opcode ;
573+ opcode = * opcode_ptr ;
574+ assert (opcode != ENTER_EXECUTOR );
575+ }
570576 if (opcode == INSTRUMENTED_LINE ) {
571577 opcode_ptr = & code -> _co_monitoring -> lines [i ].original_opcode ;
572578 opcode = * opcode_ptr ;
@@ -711,7 +717,22 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
711717 assert (event != PY_MONITORING_EVENT_LINE );
712718 assert (event != PY_MONITORING_EVENT_INSTRUCTION );
713719 assert (PY_MONITORING_IS_INSTRUMENTED_EVENT (event ));
714- assert (opcode_has_event (_Py_GetBaseOpcode (code , offset )));
720+ #ifndef NDEBUG
721+ _Py_CODEUNIT co_instr = _PyCode_CODE (code )[offset ];
722+ uint8_t opcode = co_instr .op .code ;
723+ uint8_t oparg = co_instr .op .arg ;
724+ if (opcode == ENTER_EXECUTOR ) {
725+ _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
726+ assert (exec -> vm_data .opcode != ENTER_EXECUTOR );
727+ opcode = _PyOpcode_Deopt [exec -> vm_data .opcode ];
728+ opcode = exec -> vm_data .oparg ;
729+ }
730+ else {
731+ opcode = _Py_GetBaseOpcode (code , offset );
732+ }
733+ assert (opcode != ENTER_EXECUTOR );
734+ assert (opcode_has_event (opcode ));
735+ #endif
715736 _PyCoMonitoringData * monitoring = code -> _co_monitoring ;
716737 if (monitoring && monitoring -> tools ) {
717738 monitoring -> tools [offset ] &= ~tools ;
@@ -1282,9 +1303,16 @@ initialize_tools(PyCodeObject *code)
12821303 for (int i = 0 ; i < code_len ; i ++ ) {
12831304 _Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
12841305 int opcode = instr -> op .code ;
1285- if (opcode == INSTRUMENTED_LINE ) {
1306+ int oparg = instr -> op .arg ;
1307+ if (opcode == ENTER_EXECUTOR ) {
1308+ _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
1309+ opcode = exec -> vm_data .opcode ;
1310+ oparg = exec -> vm_data .oparg ;
1311+ }
1312+ else if (opcode == INSTRUMENTED_LINE ) {
12861313 opcode = code -> _co_monitoring -> lines [i ].original_opcode ;
12871314 }
1315+ assert (opcode != ENTER_EXECUTOR );
12881316 bool instrumented = is_instrumented (opcode );
12891317 if (instrumented ) {
12901318 opcode = DE_INSTRUMENT [opcode ];
@@ -1295,7 +1323,7 @@ initialize_tools(PyCodeObject *code)
12951323 if (instrumented ) {
12961324 int8_t event ;
12971325 if (opcode == RESUME ) {
1298- event = instr -> op . arg != 0 ;
1326+ event = oparg != 0 ;
12991327 }
13001328 else {
13011329 event = EVENT_FOR_OPCODE [opcode ];
0 commit comments