Skip to content

Commit 9339d70

Browse files
authored
pythonGH-106012: Fix monitoring of static code objects (pythonGH-106017)
1 parent a72683b commit 9339d70

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Python/instrumentation.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -903,26 +903,34 @@ instrumentation_cross_checks(PyInterpreterState *interp, PyCodeObject *code)
903903
#endif
904904

905905
static inline uint8_t
906-
get_tools_for_instruction(PyCodeObject * code, int i, int event)
906+
get_tools_for_instruction(PyCodeObject *code, PyInterpreterState *interp, int i, int event)
907907
{
908908
uint8_t tools;
909909
assert(event != PY_MONITORING_EVENT_LINE);
910910
assert(event != PY_MONITORING_EVENT_INSTRUCTION);
911-
assert(instrumentation_cross_checks(PyThreadState_GET()->interp, code));
912-
_PyCoMonitoringData *monitoring = code->_co_monitoring;
913911
if (event >= PY_MONITORING_UNGROUPED_EVENTS) {
914912
assert(event == PY_MONITORING_EVENT_C_RAISE ||
915913
event == PY_MONITORING_EVENT_C_RETURN);
916914
event = PY_MONITORING_EVENT_CALL;
917915
}
918-
if (event < PY_MONITORING_INSTRUMENTED_EVENTS && monitoring->tools) {
919-
tools = monitoring->tools[i];
916+
if (event < PY_MONITORING_INSTRUMENTED_EVENTS) {
917+
CHECK(is_version_up_to_date(code, interp));
918+
CHECK(instrumentation_cross_checks(interp, code));
919+
if (code->_co_monitoring->tools) {
920+
tools = code->_co_monitoring->tools[i];
921+
}
922+
else {
923+
tools = code->_co_monitoring->active_monitors.tools[event];
924+
}
920925
}
921926
else {
922-
tools = code->_co_monitoring->active_monitors.tools[event];
927+
if (code->_co_monitoring) {
928+
tools = code->_co_monitoring->active_monitors.tools[event];
929+
}
930+
else {
931+
tools = interp->monitors.tools[event];
932+
}
923933
}
924-
CHECK(tools_is_subset_for_event(code, event, tools));
925-
CHECK((tools & code->_co_monitoring->active_monitors.tools[event]) == tools);
926934
return tools;
927935
}
928936

@@ -937,9 +945,6 @@ call_instrumentation_vector(
937945
assert(!_PyErr_Occurred(tstate));
938946
assert(args[0] == NULL);
939947
PyCodeObject *code = _PyFrame_GetCode(frame);
940-
assert(code->_co_instrumentation_version == tstate->interp->monitoring_version);
941-
assert(is_version_up_to_date(code, tstate->interp));
942-
assert(instrumentation_cross_checks(tstate->interp, code));
943948
assert(args[1] == NULL);
944949
args[1] = (PyObject *)code;
945950
int offset = (int)(instr - _PyCode_CODE(code));
@@ -952,11 +957,11 @@ call_instrumentation_vector(
952957
}
953958
assert(args[2] == NULL);
954959
args[2] = offset_obj;
955-
uint8_t tools = get_tools_for_instruction(code, offset, event);
960+
PyInterpreterState *interp = tstate->interp;
961+
uint8_t tools = get_tools_for_instruction(code, interp, offset, event);
956962
Py_ssize_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET;
957963
PyObject **callargs = &args[1];
958964
int err = 0;
959-
PyInterpreterState *interp = tstate->interp;
960965
while (tools) {
961966
int tool = most_significant_bit(tools);
962967
assert(tool >= 0 && tool < 8);

0 commit comments

Comments
 (0)