Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments.
  • Loading branch information
markshannon committed May 11, 2023
commit e76f241d596764850074b81ac42a2cd05a0ba3d6
4 changes: 4 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int

#include "generated_cases.c.h"

/* INSTRUMENTED_LINE has to be here, rather than in bytecodes.c,
* because it needs to capture frame->prev_instr before it is updated,
* as happens in the standard instruction prologue.
*/
#if USE_COMPUTED_GOTOS
TARGET_INSTRUMENTED_LINE:
#else
Expand Down
13 changes: 13 additions & 0 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ _Py_call_instrumentation_jump(
return NULL;
}
if (frame->prev_instr != target) {
/* The callback has caused a jump (by setting the line number) */
return frame->prev_instr;
}
Comment thread
markshannon marked this conversation as resolved.
/* Reset prev_instr for INSTRUMENTED_LINE */
Expand Down Expand Up @@ -1294,6 +1295,12 @@ initialize_lines(PyCodeObject *code)
line_data[i].original_opcode = 0;
break;
default:
/* Set original_opcode to the opcode iff the instruction
* starts a line, and thus should be instrumented.
* This saves having to perform this check every time the
* we turn instrumentation on or off, and serves as a sanity
* check when debugging.
*/
if (line != current_line && line >= 0) {
line_data[i].original_opcode = opcode;
}
Expand Down Expand Up @@ -1322,6 +1329,8 @@ initialize_lines(PyCodeObject *code)
switch (opcode) {
case POP_JUMP_IF_FALSE:
case POP_JUMP_IF_TRUE:
case POP_JUMP_IF_NONE:
case POP_JUMP_IF_NOT_NONE:
case JUMP_FORWARD:
Comment thread
markshannon marked this conversation as resolved.
{
target = i + oparg;
Expand Down Expand Up @@ -1363,6 +1372,10 @@ initialize_lines(PyCodeObject *code)
int depth_and_lasti;
scan = parse_varint(scan, &depth_and_lasti);
int original_opcode = _Py_GetBaseOpcode(code, handler);
/* Skip if not the start of a line.
* END_ASYNC_FOR is a bit special as it marks the end of
* an `async for` loop, which should not generate its own
* line event. */
if (line_data[handler].line_delta != NO_LINE &&
original_opcode != END_ASYNC_FOR) {
Comment thread
markshannon marked this conversation as resolved.
line_data[handler].original_opcode = original_opcode;
Expand Down