Skip to content

gh-136870: fix data races in instrumentation of bytecode #136994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2025
Merged
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
Next Next commit
fix deinstrumentation
  • Loading branch information
kumaraditya303 committed Jul 23, 2025
commit 443fc768fcf1224c33da178d691987f66a7f45cb
20 changes: 12 additions & 8 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,10 @@ call_instrumentation_vector(
break;
}
else {
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_tools(code, offset, event, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
}
}
Expand Down Expand Up @@ -1381,9 +1382,10 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
}
else {
/* DISABLE */
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_line_tools(code, i, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
} while (tools);
Py_DECREF(line_obj);
Expand Down Expand Up @@ -1438,9 +1440,10 @@ _Py_call_instrumentation_instruction(PyThreadState *tstate, _PyInterpreterFrame*
}
else {
/* DISABLE */
LOCK_CODE(code);
PyInterpreterState *interp = tstate->interp;
_PyEval_StopTheWorld(interp);
remove_per_instruction_tools(code, offset, 1 << tool);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
}
Py_DECREF(offset_obj);
Expand Down Expand Up @@ -2995,9 +2998,10 @@ branch_handler_vectorcall(
// Orphaned NOT_TAKEN -- Jump removed by the compiler
return res;
}
LOCK_CODE(code);
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyEval_StopTheWorld(interp);
remove_tools(code, offset, other_event, 1 << self->tool_id);
UNLOCK_CODE();
_PyEval_StartTheWorld(interp);
}
return res;
}
Expand Down
Loading