Skip to content

Commit

Permalink
use prev_traced_instr instead of prev_instr in line tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Sep 29, 2023
1 parent b3b55ee commit 6f0fe7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typedef struct _PyInterpreterFrame {
// example, it may be an inline CACHE entry, an instruction we just jumped
// over, or (in the case of a newly-created frame) a totally invalid value:
_Py_CODEUNIT *prev_instr;
_Py_CODEUNIT *prev_traced_instr;
/* The instruction that is currently executing (possibly not started yet). */
_Py_CODEUNIT *instr_ptr;
int stacktop; /* Offset of TOS from localsplus */
Expand Down Expand Up @@ -173,6 +174,7 @@ _PyFrame_Initialize(
frame->f_locals = locals;
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->prev_traced_instr = NULL;
frame->prev_instr = _PyCode_CODE(code) - 1;
frame->instr_ptr = _PyCode_CODE(code);
frame->return_offset = 0;
Expand Down Expand Up @@ -339,6 +341,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->f_locals = NULL;
frame->stacktop = code->co_nlocalsplus + stackdepth;
frame->frame_obj = NULL;
frame->prev_traced_instr = NULL;
frame->prev_instr = _PyCode_CODE(code) + previous_instr;
frame->instr_ptr = _PyCode_CODE(code) + previous_instr + 1;
frame->owner = FRAME_OWNED_BY_THREAD;
Expand Down
7 changes: 4 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
case INSTRUMENTED_LINE:
#endif
{
_Py_CODEUNIT *prev = frame->prev_instr;
_Py_CODEUNIT *here = frame->instr_ptr = frame->prev_instr = next_instr;
DUMP_FRAME("INSTRUMENTED_LINE");
_Py_CODEUNIT *prev = frame->prev_traced_instr;
_Py_CODEUNIT *here = frame->instr_ptr = frame->prev_instr = frame->prev_traced_instr = next_instr;
_PyFrame_SetStackPointer(frame, stack_pointer);
int original_opcode = _Py_call_instrumentation_line(
tstate, frame, here, prev);
Expand All @@ -801,7 +802,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
next_instr = here+1;
goto error;
}
next_instr = frame->prev_instr;
next_instr = frame->prev_traced_instr;
if (next_instr != here) {
DISPATCH();
}
Expand Down
21 changes: 11 additions & 10 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,6 @@ _Py_Instrumentation_GetLine(PyCodeObject *code, int index)
int
_Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr, _Py_CODEUNIT *prev)
{
assert(frame->prev_instr == instr);
PyCodeObject *code = _PyFrame_GetCode(frame);
assert(is_version_up_to_date(code, tstate->interp));
assert(instrumentation_cross_checks(tstate->interp, code));
Expand All @@ -1135,15 +1134,17 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
int8_t line_delta = line_data->line_delta;
int line = compute_line(code, i, line_delta);
assert(line >= 0);
int prev_index = (int)(prev - _PyCode_CODE(code));
int prev_line = _Py_Instrumentation_GetLine(code, prev_index);
if (prev_line == line) {
int prev_opcode = _PyCode_CODE(code)[prev_index].op.code;
/* RESUME and INSTRUMENTED_RESUME are needed for the operation of
* instrumentation, so must never be hidden by an INSTRUMENTED_LINE.
*/
if (prev_opcode != RESUME && prev_opcode != INSTRUMENTED_RESUME) {
goto done;
if (prev != NULL) {
int prev_index = (int)(prev - _PyCode_CODE(code));
int prev_line = _Py_Instrumentation_GetLine(code, prev_index);
if (prev_line == line) {
int prev_opcode = _PyCode_CODE(code)[prev_index].op.code;
/* RESUME and INSTRUMENTED_RESUME are needed for the operation of
* instrumentation, so must never be hidden by an INSTRUMENTED_LINE.
*/
if (prev_opcode != RESUME && prev_opcode != INSTRUMENTED_RESUME) {
goto done;
}
}
}
uint8_t tools = code->_co_monitoring->line_tools != NULL ?
Expand Down

0 comments on commit 6f0fe7b

Please sign in to comment.