@@ -649,7 +649,10 @@ static const _Py_CODEUNIT _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = {
649649
650650extern const struct _PyCode_DEF (8 ) _Py_InitCleanup ;
651651
652- extern const char * _PyUOpName (int index );
652+ #ifdef Py_DEBUG
653+ extern void _PyUOpPrint (const _PyUOpInstruction * uop );
654+ #endif
655+
653656
654657/* Disable unused label warnings. They are handy for debugging, even
655658 if computed gotos aren't used. */
@@ -1006,14 +1009,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10061009 assert (next_uop -> opcode == _START_EXECUTOR || next_uop -> opcode == _COLD_EXIT );
10071010 for (;;) {
10081011 uopcode = next_uop -> opcode ;
1009- DPRINTF (3 ,
1010- "%4d: uop %s, oparg %d, operand %" PRIu64 ", target %d, stack_level %d\n" ,
1011- (int )(next_uop - (current_executor == NULL ? next_uop : current_executor -> trace )),
1012- _PyUOpName (uopcode ),
1013- next_uop -> oparg ,
1014- next_uop -> operand ,
1015- next_uop -> target ,
1012+ #ifdef Py_DEBUG
1013+ if (lltrace >= 3 ) {
1014+ printf ("%4d uop: " , (int )(next_uop - (current_executor == NULL ? next_uop : current_executor -> trace )));
1015+ _PyUOpPrint (next_uop );
1016+ printf (" stack_level=%d\n" ,
10161017 (int )(stack_pointer - _PyFrame_Stackbase (frame )));
1018+ }
1019+ #endif
10171020 next_uop ++ ;
10181021 OPT_STAT_INC (uops_executed );
10191022 UOP_STAT_INC (uopcode , execution_count );
@@ -1028,9 +1031,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10281031 default :
10291032#ifdef Py_DEBUG
10301033 {
1031- fprintf ( stderr , "Unknown uop %d, oparg %d, operand %" PRIu64 " @ %d\n" ,
1032- next_uop [-1 ]. opcode , next_uop [ -1 ]. oparg , next_uop [ -1 ]. operand ,
1033- (int )(next_uop - ( current_executor == NULL ? next_uop : current_executor -> trace ) - 1 ));
1034+ printf ( "Unknown uop: " );
1035+ _PyUOpPrint ( & next_uop [-1 ]);
1036+ printf ( " @ %d\n" , (int )(next_uop - current_executor -> trace - 1 ));
10341037 Py_FatalError ("Unknown uop" );
10351038 }
10361039#else
@@ -1058,10 +1061,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10581061pop_1_error_tier_two :
10591062 STACK_SHRINK (1 );
10601063error_tier_two :
1061- DPRINTF (2 , "Error: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d -> %s]\n" ,
1062- uopcode , _PyUOpName (uopcode ), next_uop [-1 ].oparg , next_uop [-1 ].operand , next_uop [-1 ].target ,
1063- (int )(next_uop - current_executor -> trace - 1 ),
1064- _PyOpcode_OpName [frame -> instr_ptr -> op .code ]);
1064+ #ifdef Py_DEBUG
1065+ if (lltrace >= 2 ) {
1066+ printf ("Error: [UOp " );
1067+ _PyUOpPrint (& next_uop [-1 ]);
1068+ printf (" @ %d -> %s]\n" ,
1069+ (int )(next_uop - current_executor -> trace - 1 ),
1070+ _PyOpcode_OpName [frame -> instr_ptr -> op .code ]);
1071+ }
1072+ #endif
10651073 OPT_HIST (trace_uop_execution_counter , trace_run_length_hist );
10661074 frame -> return_offset = 0 ; // Don't leave this random
10671075 _PyFrame_SetStackPointer (frame , stack_pointer );
@@ -1072,9 +1080,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10721080// Jump here from DEOPT_IF()
10731081deoptimize :
10741082 next_instr = next_uop [-1 ].target + _PyCode_CODE (_PyFrame_GetCode (frame ));
1075- DPRINTF (2 , "DEOPT: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d -> %s]\n" ,
1076- uopcode , _PyUOpName (uopcode ), next_uop [-1 ].oparg , next_uop [-1 ].operand , next_uop [-1 ].target ,
1077- _PyOpcode_OpName [next_instr -> op .code ]);
1083+ #ifdef Py_DEBUG
1084+ if (lltrace >= 2 ) {
1085+ printf ("DEOPT: [UOp " );
1086+ _PyUOpPrint (& next_uop [-1 ]);
1087+ printf (" -> %s]\n" ,
1088+ _PyOpcode_OpName [frame -> instr_ptr -> op .code ]);
1089+ }
1090+ #endif
10781091 OPT_HIST (trace_uop_execution_counter , trace_run_length_hist );
10791092 UOP_STAT_INC (uopcode , miss );
10801093 Py_DECREF (current_executor );
@@ -1088,9 +1101,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10881101 uint32_t exit_index = next_uop [-1 ].exit_index ;
10891102 assert (exit_index < current_executor -> exit_count );
10901103 _PyExitData * exit = & current_executor -> exits [exit_index ];
1091- DPRINTF (2 , "SIDE EXIT: [UOp %d (%s), oparg %d, operand %" PRIu64 ", exit %u, temp %d, target %d -> %s]\n" ,
1092- uopcode , _PyUOpName (uopcode ), next_uop [-1 ].oparg , next_uop [-1 ].operand , exit_index , exit -> temperature ,
1093- exit -> target , _PyOpcode_OpName [_PyCode_CODE (_PyFrame_GetCode (frame ))[exit -> target ].op .code ]);
1104+ #ifdef Py_DEBUG
1105+ if (lltrace >= 2 ) {
1106+ printf ("SIDE EXIT: [UOp " );
1107+ _PyUOpPrint (& next_uop [-1 ]);
1108+ printf (", exit %u, temp %d, target %d -> %s]\n" ,
1109+ exit_index , exit -> temperature , exit -> target ,
1110+ _PyOpcode_OpName [frame -> instr_ptr -> op .code ]);
1111+ }
1112+ #endif
10941113 Py_INCREF (exit -> executor );
10951114 tstate -> previous_executor = (PyObject * )current_executor ;
10961115 GOTO_TIER_TWO (exit -> executor );
0 commit comments