Skip to content

Commit aa1137f

Browse files
committed
gh-136692: Provide extra debug info when monitoring assertion fails
We are seeing occasional failures in the free threading buildbots, but they are difficult to reproduce locally. Add some extra information to the failure messages.
1 parent 49ff8b6 commit aa1137f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

Python/instrumentation.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,35 @@ instrumentation_cross_checks(PyInterpreterState *interp, PyCodeObject *code)
10811081
static int
10821082
debug_check_sanity(PyInterpreterState *interp, PyCodeObject *code)
10831083
{
1084-
int res;
1084+
int res = 1;
10851085
LOCK_CODE(code);
1086-
res = is_version_up_to_date(code, interp) &&
1087-
instrumentation_cross_checks(interp, code);
1086+
// gh-136692: These assertions are triggering on buildbots, so provide
1087+
// some more information when crashing.
1088+
uint32_t glob_version = global_version(interp);
1089+
uintptr_t code_version = code->_co_instrumentation_version;
1090+
if (glob_version != code_version) {
1091+
_Py_FatalErrorFormat(
1092+
__func__,
1093+
"Instrumentation version mismatch: global=%lu code=%lu",
1094+
(unsigned long)glob_version, (unsigned long)code_version);
1095+
}
1096+
1097+
_Py_LocalMonitors expected = local_union(
1098+
interp->monitors,
1099+
code->_co_monitoring->local_monitors);
1100+
_Py_LocalMonitors active = code->_co_monitoring->active_monitors;
1101+
if (!monitors_equals(active, expected)) {
1102+
char buf1[64];
1103+
char buf2[64];
1104+
for (int event = 0; event < _PY_MONITORING_LOCAL_EVENTS; event++) {
1105+
snprintf(&buf1[event*3], 4, "%02x ", expected.tools[event]);
1106+
snprintf(&buf2[event*3], 4, "%02x ", active.tools[event]);
1107+
}
1108+
_Py_FatalErrorFormat(
1109+
__func__,
1110+
"Instrumentation monitors mismatch: expected=%s active=%s",
1111+
buf1, buf2);
1112+
}
10881113
UNLOCK_CODE();
10891114
return res;
10901115
}

0 commit comments

Comments
 (0)