tooling: log registers and memory at bounded startup breakpoints (X2W_LOG_AT) #2182
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2190"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T03:28:32Z.
Adds a bounded per-hit register/memory logger to the startup debugger, next to
X2W_COUNT,X2W_STOP_ATandX2W_WATCH. Useful for #870 investigations where a stop needs the state of one table entry or call result, not just a hit count.Change
X2W_LOG_ATto the startup debugger. It records elapsed time, thread ID, RVA, hit number, and selected registers or qwords infiles.txt. It uses the existing software breakpoint and resume path. The default is 16 hits per site with all 16 integer registers.events.txt. Include the logged counts in the end summary.Verification
Tested commit
8a2e9fbb770fd6b2a43324e8aa086d1718e8601don Windows 10 22H2 (19045.6456) with MSVC 19.44.35230.startup_debuggit diff --checkThe source-built probe ran all 19 calls. The two-hit case recorded the expected changing register, both qwords at signed offsets, and
unreadablefor a null address with the regular file hooks off. The original opcode was restored. Malformed, duplicate, out-of-image, non-executable, and existing INT3 requests were ignored with diagnostics. The default case logged all registers on 16 hits whileX2W_COUNTstill counted 19 calls.Real-run use: in a local startup run on the same host, five sites logged 31,677 bounded hits, about 26k of them on one site. Each site restored its original instruction at its limit, and the run reached the same endpoint as an unlogged run. The logs stay local.
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:31:12Z.
Review: COMMENTED
Review of head
8a2e9fbb770fd6b2a43324e8aa086d1718e8601d(tooling only:tools/startup/debug_launch.py, probe, check, 2 docs).Verdict: no blocking findings. P1=0, P2=0, 2 nits.
Checked locally (Linux):
git diff --stat origin/main...HEAD: 5 files, +203/-20. Title is neutral, PR is mergeable, no non-public references.python3 tests/docs_links_check.py-> Self-test passed; 18 Markdown files, 402 links OK.python3 tests/bidi_controls_check.py-> Self-test passed; 1453 files, no bidi controls.git diff --check origin/main...HEAD-> clean.tests/startup_debug_check.pyneeds the Windows probe binary and calls DLL (main(probe, calls_dll)), so it cannot run on Linux. I did not run the Windows gate; CI "Build and test on Windows" was still pending when I looked.parse_log_atand ran it standalone on 11 inputs: default (16 GPRs, 16 hits),@2limit with[rcx+8];[rcx-8],@0, non-hex,rip,[rcx*8], duplicate RVA with different case, RVA > 32 bits,0xoffsets, empty item. All behave as the new test expects (valid ones accepted; bad ones logged asX2W_LOG_AT ignored ...and skipped, never raise).Code read (
debug_launch.py):int3(skip_int3). Bad sites are dropped with a log line, so they cannot corrupt the run.X2W_COUNTshared-site case is covered by thelog-at-defaulttest (x16 logged, x19 counted).read_qword, so unreadable pointers printunreadableinstead of crashing.VirtualQueryExstruct moved to module scope and is reused by the fault path with no behavior change.Nits:
tools/startup/debug_launch.py(stack scan in the VALLOC hook): the page-bounded retry is a behavior change unrelated toX2W_LOG_AT. It is harmless, but it deserves a line in the PR body or a short test.parse_log_at: duplicate items such asrdx;rdxare accepted and logged twice. Harmless, just noting it.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:41:18Z.
Review: COMMENTED
Re-review of head
73c6b72a59684d2532802b65e858f6e3d7f768a9(previous review was on8a2e9fbb). New commit since then:73c6b72a"tooling: reject repeated X2W_LOG_AT items" (3 files, +4/-2).Verdict: no P1, no P2. One nit.
What I checked
tools/startup/debug_launch.py:79-80: the new check rejects an item whose text matches an earlier item in the same entry. It sits before register and memory parsing, so it covers bothrdx;rdxand[rcx+8];[rcx+8]. The error goes through the sameX2W_LOG_AT ignored ...path as the other malformed entries, and the whole entry is dropped (no partial logging).tests/startup_debug_check.py:160: adds<rva>:rdx;rdxto the malformed list, so the existing "ignored" assertions cover the new rule. The test is a Windows debugger check; I did not run it on Linux.docs/startup-runtime.mdmatches the behaviour.Nit (non-blocking)
[rcx+8];[rcx+0x8]and[rcx+8];[rcx+08]are both accepted, and the same slot is logged twice. Harmless (just a repeated column); comparing(register, offset)would make the rule exact if you want it.Commands run locally
git diff --stat origin/main...HEAD: 5 files, +205/-20.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: self-test passed, 402 links in 18 files OK.python3 tests/bidi_controls_check.py: self-test passed, 1453 files, no bidi controls.parse_log_at(extracted from the file, Linux) on 8 inputs:rdx;rdxand[rcx+8];[rcx+8]rejected (also with a trailing;);[rcx+8];[rcx-8],rdx;rcxaccepted;[rcx+8];[RCX+0x8]and[rcx+8];[rcx+08]accepted (the nit above).rdx;rdxis accepted by construction (the only rejecting path is that check), so the new malformed entry in the check would stop being ignored. I could not run the Windows check here, so this is by reading, not by execution.gh pr checks 2190: Linux Python checks, gfx1013 fixtures, and Windows build+test all pass on this head. PR is mergeable, title is neutral, no clean-room concerns in the delta.No Windows run requested: the delta is Python parsing only, with no shader or C++ change.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:45:28Z.
Review: COMMENTED
Re-review of head
f68e020f5c9383e23eecb0e4feeedd86a2dc2826(3 commits; the latest only drops the stack-scan retry in the VALLOC caller path and restores the original one-line read, which is behaviour-neutral for the new X2W_LOG_AT feature).Executed locally (worktree of the PR head):
git diff --stat origin/main...HEAD: 5 files, +200/-19 (debug_launch.py, startup_debug_check.py, startup_debug_probe.cpp, 2 docs).python3 tests/docs_links_check.py: Self-test passed; 18 Markdown files, 402 links OK.python3 tests/bidi_controls_check.py: Self-test passed; 1453 files, no bidi controls.git diff --check origin/main...HEAD: clean.python3 tests/startup_debug_check.py: not runnable on Linux (needs the Windows probe binary and calls DLL; it is the CTest at CMakeLists.txt:2564). Windows CI jobs were still pending when I looked, so I did not verify the Windows run.parse_log_at(extracted from the source viaast, run withpython3 -I): 7 malformed entries (non-hex RVA, duplicate RVA,@0,rip, duplicate item,[rcx*8], RVA > 32 bits) are each rejected with a message; valid entries keep their limit (default 16) and item list.if rva in points:withif False:. The duplicate RVA is then silently accepted and the later entry overwrites the first. The new Windows check (the duplicateentryexpected in the "ignored" events) is what kills this; I could only confirm the parser behaviour on Linux, not run the Windows test.Findings
tools/startup/debug_launch.py(handle_breakpoint, "after the final logged hit" branch, and the dispatch at ~line 669ex_code == 0x80000003 and ex_addr in breakpoints): once the limit is reached the int3 is removed and the entry is deleted frombreakpoints. If another thread has already executed the int3 and its event is queued, that event arrives after the deletion, fails theex_addr in breakpointstest, and is treated as an ordinary breakpoint exception (passed on / logged as a stop) instead of being resumed ataddr. This only matters for hot, multi-threaded sites hit by two threads near the limit, but those are exactly the sites you would cap. Suggest keeping a short set of "recently removed" addresses and, for a first-chance int3 at one of them, set Rip back toaddrand continue. A probe with two threads calling the site would cover it.LOG_AT hit countsline prints for every configured RVA even when it was dropped by the arm check. It is already deleted fromlog_atat that point, so only armed sites show; fine, just noting it is intended.Title is neutral, no clean-room concerns seen in the diff.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T03:36:27Z.
Thanks for the review and the standalone parser run.
startup_debugfailed on this Windows 10 host without it. The full 200-qword read returned nothing whenrspwas near the end of a stack page. The existing allocation-caller assertion instartup_debugis the test: it fails here without the retry and passes with it. I'm happy to split it into its own PR if R0Y00 prefers.73c6b72a. A repeated item such asrdx;rdxnow getsX2W_LOG_AT ignored '...': duplicate item 'rdx'inevents.txt, and the entry is skipped like other malformed ones.tests/startup_debug_check.pyadds it to the malformed list. The test also expects the next valid entry for that RVA to log, so the old behaviour fails it: the repeated entry would register the RVA first and the valid one would be rejected as a duplicate RVA. The docs line mentions it.ctest --preset dev --no-tests=error -R '^startup_debug': 1 passed. Docs links (402) andgit diff --checkare clean.Status: ready to merge from our side.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T03:42:35Z.
Correction to my reply on nit 1. I reran
startup_debugwithout the stack-scan retry: 1 failure in 36 runs, output not captured, and 0 in the last 30. So it is not shown that this test needs the retry. It is also unrelated toX2W_LOG_AT, sof68e020fremoves it. The allocation-caller scan is now unchanged frommain. If the intermittent failure comes back I will capture it and open it separately.ctest --preset dev --no-tests=error -R '^startup_debug'atf68e020f: passed in repeated runs.Status: ready to merge from our side.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:23:26Z.
Review: COMMENTED
Re-review of head
22e6ab1ec557b58c847c8f67d17c499c09989f07(4 commits; 5 files, +275/-19).Scope read:
tools/startup/debug_launch.py(parse_log_at, arm(skip_int3), handle_breakpoint limit/retire path, late-INT3 resume for retired addresses, VirtualQueryEx guard-page/image check, summary lines),tests/startup_debug_check.py,tests/startup_debug_probe.cpp, docs.Findings
ex_addr in retired) rewinds RIP and continues. Ifget_ctxfails it falls through to the generic exception path. That is harmless, but a one-line log would help diagnose it.parse_log_atsilently ignores a bad entry (with a log line) and keeps the others. This is documented in docs/experiments.md and is fine for a debugging tool.What looks right
[rcx+8]and[rcx+0x8]collide as intended.MemoryBasicInformationto module level removes the per-fault class definition and keeps the fault report behaviour the same.Commands executed locally (Linux)
git diff --stat origin/main...HEAD: 5 files, +275/-19python3 tests/docs_links_check.py: self-test passed, 18 files / 402 links OKpython3 tests/bidi_controls_check.py: self-test passed, 1453 files, no bidi controlsgit diff --check origin/main...HEAD: cleangh pr checks 2190: Linux Python checks, gfx1013 fixtures and Windows build+test all pass (the /O2 job and coverage chart are skipped)Limits (stated plainly)
tests/startup_debug_check.pyneeds the Windows probe exe andctypes.windll, so it cannot run on Linux. I could not run it here (it fails with a missing-argument error), and I did not run Windows 2025 myself. For this review I rely on the passing Windows CI job.< point[0]changed to<=, and disabling theretiredlate-hit branch). Neither could be killed or confirmed, because the test cannot run here. The Windows check should exercise both, vialog_at_records(..., count)for the hit limit. The late-hit branch is timing dependent, so it may not be covered deterministically. I recommend someone confirm this on the Windows CI logs.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:47:06Z.
Review: COMMENTED
Re-review of head
046bed68df58a6b185efffaba74217acc1951341(delta since my last reviewed head22e6ab1e: +2 lines intools/startup/debug_launch.py).Delta
debug_launch.py:688-689: when a late INT3 hit hits a retired breakpoint andget_ctxfails, the tool now logsX2W_LOG_AT late hit at <where> on thread <tid>: thread context unavailable (error N), handled as a breakpoint. Before, this path was silent.whereandstartare in scope inmain(). The path still falls through to the generic exception handling, as before. Logging only, no behavior change.Findings
GetLastError()is read afterget_ctxhas already calledCloseHandle. It is also read withoutuse_last_error=Trueon the DLL handle. The reported error number is therefore best-effort and may be stale or 0. Harmless for a diagnostic line. Capturing the error insideget_ctxwould make it reliable.OpenThread/GetThreadContextfailure, which the Windows probe cannot easily force. Acceptable for a diagnostic-only line.Checks executed locally (Linux, worktree at the head above)
python3 -m py_compile tools/startup/debug_launch.py: OKpython3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 402 links OKpython3 tests/bidi_controls_check.py: self-test passed, 1453 files, no bidi controlsgit diff --check origin/main...HEAD: cleanpython3 tests/startup_debug_check.py: not runnable on Linux. It needs the Windowsprobeandcalls_dllarguments, so I did not run it. The mutation check was not run for the same reason, and the delta is log-only. Coverage of the earlier logic comes from the Windows CI job below.gh pr checks: Linux Python checks pass, Windows build and test pass, gfx1013 fixtures pass, /O2 job skipping. PR is MERGEABLE and the title is neutral.Nothing blocking from my side on this delta.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T04:17:11Z.
Thanks, all three addressed in
22e6ab1e.P2, INT3 queued before the limit removes the breakpoint: confirmed and fixed. Addresses retired at their limit are remembered. A later first-chance INT3 at one of them rewinds RIP to the restored instruction and continues, and is counted on a separate
LOG_AT late hits resumed after the limitsummary line. Arming already refuses sites whose original byte is INT3, so a retired address cannot hide a real title breakpoint.@1. The check runs it three times. It requires a clean exit, exactly one logged hit, all 16,000 calls completed, and no breakpoint event at that site inevents.txt.Nit, equivalent spellings: duplicates now compare
(register, offset), so[rcx+8];[RCX+0x8]is rejected. It is in the malformed list.Nit, single-threaded probe: covered by the site above.
Correction to my earlier comment on the stack-scan retry. The "0 failures in the last 30" there came from a shell where
ctestwas not on PATH. Those runs never executed the test, so the numbers were wrong. Measured properly throughctest --preset dev:startup_debugmain(c118f569)startup_debug_check.py:150:VALLOC ... callers:emptySo this is an intermittent failure on this Windows 10 host that already exists on
main. It is independent ofX2W_LOG_AT, and CI does not show it. I'll keep it out of this PR and open the page-bounded retry as its own PR, with these numbers and the with-retry rate. Until that lands,startup_debugcan fail at line 150 on such a host for reasons unrelated to this change. At22e6ab1e, the only failures here were that line in 2 of 10 runs.Docs links (402), the bidi check and
git diff --checkare clean.Status: ready for more review.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T04:39:29Z.
Thanks.
046bed68adds anevents.txtline naming the address, the thread andGetLastError, and the event then falls through to the generic handling as before.startup_debug_check.py, the check for no breakpoint event at the threaded site), because each run then records 5 or 6 breakpoint events there. With the branch in place, 15 of 15 harness runs had 4 to 7 late hits, all resumed. So on this host the race occurs in every run rather than only now and then. I did not run the hit-limit mutation (<to<=). From the code,log_at_records(..., 2)and(..., 16)require exact line counts, so one extra logged hit fails them.At
046bed68,startup_debugfails here only at line 150, the pre-existingVALLOCcaller check that #2202 fixes, in 2 of 3 runs. Otherwise it passes.Status: ready to merge from our side.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:16:21Z.
Review: COMMENTED
Re-review of head
5d14931ed898a5832ea6eaa9552927a9fde0d39c(delta since my last reviewed head046bed68: a merge of main plus the fix below).Delta
debug_launch.py:299-305:get_ctxnow storesGetLastError()inctx_errorright after the failure and beforeCloseHandle. The late-hit log line readsctx_error[0]. This fixes my previous nit about a stale error number. (CallingGetLastErrorwithoutuse_last_error=Truestill works for a diagnostic, because nothing else runs in between.)read_stack, host-CPU resume, gfx2hlsl). They are not part of this PR.Findings
OpenThreadfailure, which the probe cannot force. Acceptable for a diagnostic-only line.Checks executed locally (Linux, worktree at the head above)
python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 408 links OKpython3 tests/bidi_controls_check.py: self-test passed, 1487 files, no bidi controlsgit diff --check origin/main...HEAD: cleanparse_log_atand ran 16 inputs: defaults (16 hits, all 16 GPRs),@2limit,0xprefix,@0,@-1,@x,rip,[rcx*8], empty item,[rcx+], duplicate item ([rcx+8];[RCX+0x8]), duplicate RVA, RVA over 32 bits. All accepted or rejected as the docs describe, each rejection with a clear message.<= 0to< 0. The parser then accepted1000@0with a limit of 0, and my check output differed. The repo test covers this with the@0entry inmalformed, but only on Windows.python3 tests/startup_debug_check.py: not runnable on Linux (needs the Windows probe and calls DLL). Coverage of the runtime path (late hits, retire at limit, X2W_COUNT sharing) comes from the Windows CI job.gh pr checks: Linux Python checks pass, Windows build and test pass, gfx1013 fixtures pass, /O2 job skipping. PR is MERGEABLE and the title is neutral.Nothing blocking from my side.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T05:09:53Z.
Thanks.
5d14931eaddresses the first nit and mergesmain:GetLastErrorafterCloseHandle:get_ctxnow recordsGetLastErrorat the failingOpenThread/GetThreadContext, beforeCloseHandle, and the late-hit line prints that value. It is still best-effort withoutuse_last_error, but it no longer reads after another call.mainnow has #2202'sread_stack. The only conflict was the neighbouring helper, so both are kept. The VALLOC hook usesread_stackand the probe checks it.ctest --preset dev --no-tests=error -R '^startup_debug$'at5d14931e: 4 of 4 passed on the Windows 10 host. The earlier line-150 failures are gone with #2202 in.Status: ready to merge from our side.