diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 41d4b6ff5ecf59..3d17421fe48417 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -86,7 +86,7 @@ typedef struct _PyInterpreterFrame { } _PyInterpreterFrame; #define NewPyInterpreterFrame_LASTI(IF) \ - ((int)((IF)->instr_ptr - _PyCode_CODE(_PyFrame_GetCode(IF)))) + ((int)(((IF)->instr_ptr - 1) - _PyCode_CODE(_PyFrame_GetCode(IF)))) #define _PyInterpreterFrame_LASTI(IF) \ ((int)((IF)->prev_instr - _PyCode_CODE(_PyFrame_GetCode(IF)))) @@ -160,6 +160,7 @@ _PyFrame_Initialize( frame->prev_instr = _PyCode_CODE(code) - 1; frame->instr_ptr = _PyCode_CODE(code); frame->return_offset = 0; + frame->new_return_offset = 0; frame->owner = FRAME_OWNED_BY_THREAD; for (int i = null_locals_from; i < code->co_nlocalsplus; i++) { @@ -325,6 +326,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int frame->instr_ptr = _PyCode_CODE(code) + prev_instr + 1; frame->owner = FRAME_OWNED_BY_THREAD; frame->return_offset = 0; + frame->new_return_offset = 0; return frame; } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 830b6f2aa3514c..018ac883707caa 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -771,7 +771,9 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins assert(frame == &entry_frame); assert(_PyFrame_IsIncomplete(frame)); /* Restore previous frame and return. */ +fprintf(stderr, "INTERPRETER_EXIT1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d frame->previous = %p\n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset, frame->previous); tstate->current_frame = frame->previous; +if (frame->previous) fprintf(stderr, "INTERPRETER_EXIT2: tstate->current_frame=%p tstate->current_frame->prev_instr=%p tstate->current_frame->instr_ptr=%p new_return_offset=%d \n", tstate->current_frame, tstate->current_frame->prev_instr, tstate->current_frame->instr_ptr, tstate->current_frame->new_return_offset); assert(!_PyErr_Occurred(tstate)); tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS; return retval; @@ -792,7 +794,7 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins _PyInterpreterFrame *dying = frame; frame = tstate->current_frame = dying->previous; _PyEval_FrameClearAndPop(tstate, dying); -fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p \n", frame, frame->prev_instr, frame->instr_ptr); +fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d \n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset); frame->prev_instr += frame->return_offset; frame->instr_ptr += frame->new_return_offset; frame->new_return_offset = 0; @@ -1080,6 +1082,10 @@ fprintf(stderr, "_POP_FRAME[3]: frame=%p frame->prev_instr=%p frame->instr_ptr=% frame = tstate->current_frame = frame->previous; gen_frame->previous = NULL; _PyFrame_StackPush(frame, retval); + frame->instr_ptr += frame->new_return_offset; + frame->new_return_offset = 0; + frame->prev_instr = frame->instr_ptr - 1; +fprintf(stderr, "YIELD_VALUE: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); goto resume_frame; } @@ -2665,7 +2671,7 @@ fprintf(stderr, "_POP_FRAME[3]: frame=%p frame->prev_instr=%p frame->instr_ptr=% assert(next_instr[oparg].op.code == END_FOR || next_instr[oparg].op.code == INSTRUMENTED_END_FOR); frame->return_offset = oparg; - frame->new_return_offset = oparg; + frame->new_return_offset = oparg + next_instr - frame->instr_ptr; DISPATCH_INLINED(gen_frame); } @@ -2913,7 +2919,7 @@ fprintf(stderr, "_POP_FRAME[3]: frame=%p frame->prev_instr=%p frame->instr_ptr=% // When calling Python, inline the call using DISPATCH_INLINED(). inst(CALL, (unused/1, unused/2, callable, self_or_null, args[oparg] -- res)) { // oparg counts all of the args, but *not* self: -fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); int total_args = oparg; if (self_or_null != NULL) { args--; @@ -2929,7 +2935,7 @@ fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_i STAT_INC(CALL, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ -fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); if (self_or_null == NULL && Py_TYPE(callable) == &PyMethod_Type) { args--; total_args++; @@ -2940,7 +2946,8 @@ fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_i Py_DECREF(callable); callable = method; } -fprintf(stderr, "CALL3: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL3: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); + // Check if the call can be inlined or not if (Py_TYPE(callable) == &PyFunction_Type && tstate->interp->eval_frame == NULL && @@ -2969,10 +2976,12 @@ fprintf(stderr, "CALL-DISPATCH_INLINED: frame=%p frame->prev_instr=%p frame->ins DISPATCH_INLINED(new_frame); } /* Callable is not a normal Python function */ +fprintf(stderr, "CALL-not normal python func1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); res = PyObject_Vectorcall( callable, args, total_args | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); +fprintf(stderr, "CALL-not normal python func2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); if (opcode == INSTRUMENTED_CALL) { PyObject *arg = total_args == 0 ? &_PyInstrumentation_MISSING : args[0]; @@ -2998,6 +3007,8 @@ fprintf(stderr, "CALL-DISPATCH_INLINED: frame=%p frame->prev_instr=%p frame->ins ERROR_IF(res == NULL, error); fprintf(stderr, "CALL-END: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + frame->return_offset = 0; + frame->new_return_offset = 0; CHECK_EVAL_BREAKER(); } @@ -3675,8 +3686,7 @@ fprintf(stderr, "_PUSH_FRAME: frame=%p frame->prev_instr=%p frame->instr_ptr=%p\ goto error; } frame->return_offset = 0; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; + frame->new_return_offset = next_instr - frame->instr_ptr; DISPATCH_INLINED(new_frame); } result = PyObject_Call(func, callargs, kwargs); @@ -3946,11 +3956,11 @@ fprintf(stderr, "_PUSH_FRAME: frame=%p frame->prev_instr=%p frame->instr_ptr=%p\ op(_SAVE_CURRENT_IP, (--)) { #if TIER_ONE -fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; -fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; +fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 785e39a553edbb..f718ae1604f811 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -71,10 +71,10 @@ #else #define INSTRUCTION_START(op) \ do { \ -fprintf(stderr, "-- %s: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", _PyOpcode_OpName[op], frame, frame->prev_instr, frame->instr_ptr, next_instr); \ +fprintf(stderr, "--- %s: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", _PyOpcode_OpName[op], frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); \ frame->instr_ptr = next_instr; \ frame->prev_instr = next_instr++; \ -fprintf(stderr, "== %s: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", _PyOpcode_OpName[op], frame, frame->prev_instr, frame->instr_ptr, next_instr); \ +fprintf(stderr, "=== %s: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", _PyOpcode_OpName[op], frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); \ } while(0) #endif @@ -387,6 +387,9 @@ static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) { #define LOAD_IP() do { \ assert(frame->prev_instr + 1 == frame->instr_ptr); \ + frame->instr_ptr += frame->new_return_offset; \ + frame->new_return_offset = 0; \ +fprintf(stderr, "LOAD_IP: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); \ next_instr = frame->instr_ptr; \ } while (0) diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index a1288ca1017c24..7729cccd1fcdf4 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -692,7 +692,7 @@ _PyInterpreterFrame *dying = frame; frame = tstate->current_frame = dying->previous; _PyEval_FrameClearAndPop(tstate, dying); -fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p \n", frame, frame->prev_instr, frame->instr_ptr); +fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d \n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset); frame->prev_instr += frame->return_offset; frame->instr_ptr += frame->new_return_offset; frame->new_return_offset = 0; @@ -2978,11 +2978,11 @@ fprintf(stderr, "_POP_FRAME[3]: frame=%p frame->prev_instr=%p frame->instr_ptr=% case _SAVE_CURRENT_IP: { #if TIER_ONE -fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; -fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; +fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 786d66abb55012..be6d5d5f55547a 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -979,7 +979,9 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins assert(frame == &entry_frame); assert(_PyFrame_IsIncomplete(frame)); /* Restore previous frame and return. */ +fprintf(stderr, "INTERPRETER_EXIT1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d frame->previous = %p\n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset, frame->previous); tstate->current_frame = frame->previous; +if (frame->previous) fprintf(stderr, "INTERPRETER_EXIT2: tstate->current_frame=%p tstate->current_frame->prev_instr=%p tstate->current_frame->instr_ptr=%p new_return_offset=%d \n", tstate->current_frame, tstate->current_frame->prev_instr, tstate->current_frame->instr_ptr, tstate->current_frame->new_return_offset); assert(!_PyErr_Occurred(tstate)); tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS; return retval; @@ -990,11 +992,11 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins // _SAVE_CURRENT_IP { #if TIER_ONE - fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; - fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; + fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP @@ -1015,7 +1017,7 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins _PyInterpreterFrame *dying = frame; frame = tstate->current_frame = dying->previous; _PyEval_FrameClearAndPop(tstate, dying); - fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p \n", frame, frame->prev_instr, frame->instr_ptr); + fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d \n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset); frame->prev_instr += frame->return_offset; frame->instr_ptr += frame->new_return_offset; frame->new_return_offset = 0; @@ -1069,11 +1071,11 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins // _SAVE_CURRENT_IP { #if TIER_ONE - fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; - fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; + fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP @@ -1093,7 +1095,7 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins _PyInterpreterFrame *dying = frame; frame = tstate->current_frame = dying->previous; _PyEval_FrameClearAndPop(tstate, dying); - fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p \n", frame, frame->prev_instr, frame->instr_ptr); + fprintf(stderr, "_POP_FRAME[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p new_return_offset=%d \n", frame, frame->prev_instr, frame->instr_ptr, frame->new_return_offset); frame->prev_instr += frame->return_offset; frame->instr_ptr += frame->new_return_offset; frame->new_return_offset = 0; @@ -1381,6 +1383,10 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins frame = tstate->current_frame = frame->previous; gen_frame->previous = NULL; _PyFrame_StackPush(frame, retval); + frame->instr_ptr += frame->new_return_offset; + frame->new_return_offset = 0; + frame->prev_instr = frame->instr_ptr - 1; +fprintf(stderr, "YIELD_VALUE: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); goto resume_frame; } @@ -3446,7 +3452,7 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins assert(next_instr[oparg].op.code == END_FOR || next_instr[oparg].op.code == INSTRUMENTED_END_FOR); frame->return_offset = oparg; - frame->new_return_offset = oparg; + frame->new_return_offset = oparg + next_instr - frame->instr_ptr; DISPATCH_INLINED(gen_frame); } @@ -3747,7 +3753,7 @@ fprintf(stderr, "goto exception_unwind: frame=%p frame->prev_instr=%p frame->ins self_or_null = stack_pointer[-1 - oparg]; callable = stack_pointer[-2 - oparg]; // oparg counts all of the args, but *not* self: -fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); int total_args = oparg; if (self_or_null != NULL) { args--; @@ -3763,7 +3769,7 @@ fprintf(stderr, "CALL1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_i STAT_INC(CALL, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ -fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); if (self_or_null == NULL && Py_TYPE(callable) == &PyMethod_Type) { args--; total_args++; @@ -3774,7 +3780,8 @@ fprintf(stderr, "CALL2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_i Py_DECREF(callable); callable = method; } -fprintf(stderr, "CALL3: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); +fprintf(stderr, "CALL3: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); + // Check if the call can be inlined or not if (Py_TYPE(callable) == &PyFunction_Type && tstate->interp->eval_frame == NULL && @@ -3803,10 +3810,12 @@ fprintf(stderr, "CALL-DISPATCH_INLINED: frame=%p frame->prev_instr=%p frame->ins DISPATCH_INLINED(new_frame); } /* Callable is not a normal Python function */ +fprintf(stderr, "CALL-not normal python func1: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); res = PyObject_Vectorcall( callable, args, total_args | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); +fprintf(stderr, "CALL-not normal python func2: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); if (opcode == INSTRUMENTED_CALL) { PyObject *arg = total_args == 0 ? &_PyInstrumentation_MISSING : args[0]; @@ -3832,6 +3841,8 @@ fprintf(stderr, "CALL-DISPATCH_INLINED: frame=%p frame->prev_instr=%p frame->ins if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } fprintf(stderr, "CALL-END: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + frame->return_offset = 0; + frame->new_return_offset = 0; STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3905,11 +3916,11 @@ fprintf(stderr, "CALL-END: frame=%p frame->prev_instr=%p frame->instr_ptr=%p nex next_instr += 3; { #if TIER_ONE - fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; - fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; + fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP @@ -3989,11 +4000,11 @@ fprintf(stderr, "CALL-END: frame=%p frame->prev_instr=%p frame->instr_ptr=%p nex next_instr += 3; { #if TIER_ONE - fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + fprintf(stderr, "_SAVE_CURRENT_IP[1]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); frame->prev_instr = next_instr - 1; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; - fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p\n", frame, frame->prev_instr, frame->instr_ptr, next_instr); + assert(frame->new_return_offset == 0); + frame->new_return_offset = next_instr - frame->instr_ptr; + fprintf(stderr, "_SAVE_CURRENT_IP[2]: frame=%p frame->prev_instr=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d\n", frame, frame->prev_instr, frame->instr_ptr, next_instr, frame->new_return_offset); #endif #if TIER_TWO // Relies on a preceding _SET_IP @@ -4807,8 +4818,7 @@ fprintf(stderr, "CALL-END: frame=%p frame->prev_instr=%p frame->instr_ptr=%p nex goto error; } frame->return_offset = 0; - frame->instr_ptr = next_instr - frame->new_return_offset; - frame->new_return_offset = 0; + frame->new_return_offset = next_instr - frame->instr_ptr; DISPATCH_INLINED(new_frame); } result = PyObject_Call(func, callargs, kwargs); diff --git a/Python/traceback.c b/Python/traceback.c index 16f5d34e46286d..a7c4c7c6ed820d 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -239,8 +239,8 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame) int newline = PyCode_Addr2Line(_PyFrame_GetCode(frame->f_frame), new_addr); int line = PyCode_Addr2Line(_PyFrame_GetCode(frame->f_frame), addr); if (true || line != newline) { - fprintf(stderr, "frame=%p frame->prev_instr=%p frame->instr_ptr=%p line=%d newline=%d %s\n", - frame->f_frame, frame->f_frame->prev_instr, frame->f_frame->instr_ptr, line, newline, newline - line ? "XXX" : ""); + fprintf(stderr, "frame=%p frame->prev_instr=%p frame->instr_ptr=%p frame->new_return_offset=%d line=%d newline=%d %s\n", + frame->f_frame, frame->f_frame->prev_instr, frame->f_frame->instr_ptr, frame->f_frame->new_return_offset, line, newline, newline - line ? "XXX" : ""); } assert(line == newline); return tb_create_raw((PyTracebackObject *)tb_next, frame, addr,