From 13fae6df30e3a19e5a30f228482b15a679d931e4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 02:32:21 +0000 Subject: [PATCH] qemu_session.py: the CPU snapshot also dumps the code at each PC Eight words at the PC, by its address, name the function offline. The image loads where the firmware puts it, and the boot does not print that address. aarch64's monitor has no $pc, so the address is taken from the register line; checked on a real, paused QEMU. Test first: the snapshot test, 6 checks; the new one failed before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm --- logs/20261119-ci-snapshot/test2-after.log | 7 +++++++ logs/20261119-ci-snapshot/test2-before.log | 7 +++++++ scripts/qemu_session.py | 13 ++++++++++++- scripts/test_qemu_session_snapshot.sh | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 logs/20261119-ci-snapshot/test2-after.log create mode 100644 logs/20261119-ci-snapshot/test2-before.log diff --git a/logs/20261119-ci-snapshot/test2-after.log b/logs/20261119-ci-snapshot/test2-after.log new file mode 100644 index 00000000..07587ae4 --- /dev/null +++ b/logs/20261119-ci-snapshot/test2-after.log @@ -0,0 +1,7 @@ +PASS: qemu_session.py has cpu_snapshot() +PASS: a failed check asks the monitor for the registers three times +PASS: and prints where the CPU is, each time +PASS: and the code at the PC each time, by its address (the monitor has no $pc on aarch64) +PASS: a passing check asks the monitor nothing +PASS: a monitor that does not answer does not stop the run +RESULT: PASS diff --git a/logs/20261119-ci-snapshot/test2-before.log b/logs/20261119-ci-snapshot/test2-before.log new file mode 100644 index 00000000..320dc06a --- /dev/null +++ b/logs/20261119-ci-snapshot/test2-before.log @@ -0,0 +1,7 @@ +PASS: qemu_session.py has cpu_snapshot() +PASS: a failed check asks the monitor for the registers three times +PASS: and prints where the CPU is, each time +FAIL: and the code at the PC each time, to name the function offline (x /8wx $pc) +PASS: a passing check asks the monitor nothing +PASS: a monitor that does not answer does not stop the run +RESULT: FAIL diff --git a/scripts/qemu_session.py b/scripts/qemu_session.py index fae6cc38..6c3b0b02 100755 --- a/scripts/qemu_session.py +++ b/scripts/qemu_session.py @@ -352,7 +352,9 @@ def excerpt(near=None, after=20, tail=40): def cpu_snapshot(times=3, apart=1.0): """Where the CPUs are (Captain Bob, 2026-11-19: "Diagnose on CI"): QEMU's monitor asked for the registers `times` times, `apart` seconds apart, and the lines that name the program - counter printed -- so a failed check's log shows where the kernel is, and whether it moves. + counter printed, with the code at it (`x /8wx` at that address, which names the function offline: the image is + loaded where the firmware puts it) -- so a failed check's log shows where the kernel is, and + whether it moves. A monitor that does not answer is said, and the run goes on.""" for k in range(times): try: @@ -363,6 +365,15 @@ def cpu_snapshot(times=3, apart=1.0): return pcs = [l.strip() for l in said.splitlines() if re.search(r"\b(PC|RIP|EIP|pc)\s*[=:]?\s*[0-9a-fA-F]", l)] print(f" --- the CPUs, {k + 1} of {times}: " + (" | ".join(pcs) if pcs else said.strip()[:200]), flush=True) + m = re.search(r"\b(?:PC|RIP|EIP|pc)\s*[=:]?\s*([0-9a-fA-F]+)", said) + if not m: + continue + try: # the code there: unique enough to name the function offline + c = qcmd("human-monitor-command", **{"command-line": f"x /8wx 0x{m.group(1)}"}) + code = c.get("return", "") if isinstance(c, dict) else str(c) + print(f" the code at the PC: {' '.join(code.split())[:200]}", flush=True) + except Exception as e: + print(f" the code at the PC: the monitor did not answer ({e})", flush=True) if k + 1 < times: time.sleep(apart) diff --git a/scripts/test_qemu_session_snapshot.sh b/scripts/test_qemu_session_snapshot.sh index 333f00e6..b8b3160d 100755 --- a/scripts/test_qemu_session_snapshot.sh +++ b/scripts/test_qemu_session_snapshot.sh @@ -24,6 +24,8 @@ report("qemu_session.py has cpu_snapshot()", any(f.name == "cpu_snapshot" for f calls = [] def qcmd(cmd, **args): calls.append((cmd, args)) + if args.get("command-line", "").startswith("x "): + return {"return": "00000000400812a4: 0xd503201f 0x94000123 0xf9400000 0xd65f03c0\n"} return {"return": "X0=0000000000000001\nPC=00000000400812a4 X30=0000000040081000 SP=0000000040300000\n"} import re g = {"qcmd": qcmd, "re": re, "time": type("T", (), {"sleep": staticmethod(lambda s: None)}), "ok": True, @@ -40,6 +42,8 @@ said = out.getvalue() regs = [c for c in calls if c[0] == "human-monitor-command" and c[1].get("command-line") == "info registers"] report("a failed check asks the monitor for the registers three times", len(regs) == 3) report(" and prints where the CPU is, each time", said.count("PC=00000000400812a4") == 3) +code = [c for c in calls if c[0] == "human-monitor-command" and c[1].get("command-line", "") == "x /8wx 0x00000000400812a4"] +report(" and the code at the PC each time, by its address (the monitor has no $pc on aarch64)", len(code) == 3 and said.count("0xd503201f") == 3) calls.clear(); out = io.StringIO() with contextlib.redirect_stdout(out): if "check" in g: g["check"]("a check that passes", True)