@@ -566,7 +566,13 @@ de_instrument(PyCodeObject *code, int i, int event)
566
566
_Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
567
567
uint8_t * opcode_ptr = & instr -> op .code ;
568
568
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
+ }
570
576
if (opcode == INSTRUMENTED_LINE ) {
571
577
opcode_ptr = & code -> _co_monitoring -> lines [i ].original_opcode ;
572
578
opcode = * opcode_ptr ;
@@ -711,7 +717,22 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
711
717
assert (event != PY_MONITORING_EVENT_LINE );
712
718
assert (event != PY_MONITORING_EVENT_INSTRUCTION );
713
719
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
715
736
_PyCoMonitoringData * monitoring = code -> _co_monitoring ;
716
737
if (monitoring && monitoring -> tools ) {
717
738
monitoring -> tools [offset ] &= ~tools ;
@@ -1282,9 +1303,16 @@ initialize_tools(PyCodeObject *code)
1282
1303
for (int i = 0 ; i < code_len ; i ++ ) {
1283
1304
_Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
1284
1305
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 ) {
1286
1313
opcode = code -> _co_monitoring -> lines [i ].original_opcode ;
1287
1314
}
1315
+ assert (opcode != ENTER_EXECUTOR );
1288
1316
bool instrumented = is_instrumented (opcode );
1289
1317
if (instrumented ) {
1290
1318
opcode = DE_INSTRUMENT [opcode ];
@@ -1295,7 +1323,7 @@ initialize_tools(PyCodeObject *code)
1295
1323
if (instrumented ) {
1296
1324
int8_t event ;
1297
1325
if (opcode == RESUME ) {
1298
- event = instr -> op . arg != 0 ;
1326
+ event = oparg != 0 ;
1299
1327
}
1300
1328
else {
1301
1329
event = EVENT_FOR_OPCODE [opcode ];
0 commit comments