mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
GH-106012: Fix monitoring of static code objects (GH-106017)
This commit is contained in:
parent
a72683ba8e
commit
9339d70ac2
1 changed files with 18 additions and 13 deletions
|
@ -903,26 +903,34 @@ instrumentation_cross_checks(PyInterpreterState *interp, PyCodeObject *code)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline uint8_t
|
static inline uint8_t
|
||||||
get_tools_for_instruction(PyCodeObject * code, int i, int event)
|
get_tools_for_instruction(PyCodeObject *code, PyInterpreterState *interp, int i, int event)
|
||||||
{
|
{
|
||||||
uint8_t tools;
|
uint8_t tools;
|
||||||
assert(event != PY_MONITORING_EVENT_LINE);
|
assert(event != PY_MONITORING_EVENT_LINE);
|
||||||
assert(event != PY_MONITORING_EVENT_INSTRUCTION);
|
assert(event != PY_MONITORING_EVENT_INSTRUCTION);
|
||||||
assert(instrumentation_cross_checks(PyThreadState_GET()->interp, code));
|
|
||||||
_PyCoMonitoringData *monitoring = code->_co_monitoring;
|
|
||||||
if (event >= PY_MONITORING_UNGROUPED_EVENTS) {
|
if (event >= PY_MONITORING_UNGROUPED_EVENTS) {
|
||||||
assert(event == PY_MONITORING_EVENT_C_RAISE ||
|
assert(event == PY_MONITORING_EVENT_C_RAISE ||
|
||||||
event == PY_MONITORING_EVENT_C_RETURN);
|
event == PY_MONITORING_EVENT_C_RETURN);
|
||||||
event = PY_MONITORING_EVENT_CALL;
|
event = PY_MONITORING_EVENT_CALL;
|
||||||
}
|
}
|
||||||
if (event < PY_MONITORING_INSTRUMENTED_EVENTS && monitoring->tools) {
|
if (event < PY_MONITORING_INSTRUMENTED_EVENTS) {
|
||||||
tools = monitoring->tools[i];
|
CHECK(is_version_up_to_date(code, interp));
|
||||||
|
CHECK(instrumentation_cross_checks(interp, code));
|
||||||
|
if (code->_co_monitoring->tools) {
|
||||||
|
tools = code->_co_monitoring->tools[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tools = code->_co_monitoring->active_monitors.tools[event];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tools = code->_co_monitoring->active_monitors.tools[event];
|
if (code->_co_monitoring) {
|
||||||
|
tools = code->_co_monitoring->active_monitors.tools[event];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tools = interp->monitors.tools[event];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CHECK(tools_is_subset_for_event(code, event, tools));
|
|
||||||
CHECK((tools & code->_co_monitoring->active_monitors.tools[event]) == tools);
|
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,9 +945,6 @@ call_instrumentation_vector(
|
||||||
assert(!_PyErr_Occurred(tstate));
|
assert(!_PyErr_Occurred(tstate));
|
||||||
assert(args[0] == NULL);
|
assert(args[0] == NULL);
|
||||||
PyCodeObject *code = _PyFrame_GetCode(frame);
|
PyCodeObject *code = _PyFrame_GetCode(frame);
|
||||||
assert(code->_co_instrumentation_version == tstate->interp->monitoring_version);
|
|
||||||
assert(is_version_up_to_date(code, tstate->interp));
|
|
||||||
assert(instrumentation_cross_checks(tstate->interp, code));
|
|
||||||
assert(args[1] == NULL);
|
assert(args[1] == NULL);
|
||||||
args[1] = (PyObject *)code;
|
args[1] = (PyObject *)code;
|
||||||
int offset = (int)(instr - _PyCode_CODE(code));
|
int offset = (int)(instr - _PyCode_CODE(code));
|
||||||
|
@ -952,11 +957,11 @@ call_instrumentation_vector(
|
||||||
}
|
}
|
||||||
assert(args[2] == NULL);
|
assert(args[2] == NULL);
|
||||||
args[2] = offset_obj;
|
args[2] = offset_obj;
|
||||||
uint8_t tools = get_tools_for_instruction(code, offset, event);
|
PyInterpreterState *interp = tstate->interp;
|
||||||
|
uint8_t tools = get_tools_for_instruction(code, interp, offset, event);
|
||||||
Py_ssize_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
Py_ssize_t nargsf = nargs | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||||
PyObject **callargs = &args[1];
|
PyObject **callargs = &args[1];
|
||||||
int err = 0;
|
int err = 0;
|
||||||
PyInterpreterState *interp = tstate->interp;
|
|
||||||
while (tools) {
|
while (tools) {
|
||||||
int tool = most_significant_bit(tools);
|
int tool = most_significant_bit(tools);
|
||||||
assert(tool >= 0 && tool < 8);
|
assert(tool >= 0 && tool < 8);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue