tooling: stop at a chosen assert, dump threads mid-run and log large allocations in the startup debugger #1292
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1299"
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 JohnConnorNPC on 2026-11-24T07:17:47Z.
Refs #870.
Problem
When a startup run under
tools/startup/debug_launch.pygoes wrong some time before it stops, the stop report describes the last fault, not the cause. Three questions kept coming up and had no switch:-ContinueAssertssteps over every main-image breakpoint, so the run only stops later, at the fault the assert led to.Change
Three environment switches, all off by default, read by
debug_launch.py:X2W_STOP_AT=<rva>[,...]--continue-assertswould step over it, and write every thread's stack tothreads_stop.txt.X2W_DUMP_AT=<seconds>[,...]threads_<seconds>.txtat those times.X2W_VALLOC_MIN=<hex bytes>NtAllocateVirtualMemory/NtAllocateVirtualMemoryExcall of at least that size tofiles.txtasVALLOC, with base, size, type, protection and the main-image and stand-in return addresses found on the caller's stack. Needs the file hooks (on by default with--offline 1).They reuse what the debugger already has:
dump_threads, the breakpoint hooks on ntdll and the existing caller scan. Nothing changes when they are unset.Evidence
Commit under test: the head of this branch, on
mainat93cb6a2a.New
tests/startup_debug_check.py, registered asstartup_debug, runs the debugger on a new source-built probe (tests/startup_debug_probe.cpp: two__debugbreak()sites in its own image, a 256 MiBMEM_RESERVE, a 3 s wait, exit 0):What it requires:
--continue-asserts 10: both sites are stepped over, exit code 0, nothreads_stop.txt, noVALLOCline. The two site addresses are read fromevents.txt, not hard-coded.X2W_STOP_AT=<second site>: the first site is still stepped over, the run stops at the second (first chance), andthreads_stop.txtnames the probe image.--continue-assertsthe run stops at the first site as before.X2W_DUMP_AT=1:threads_1.txtexists and holds stacks; the baseline has none.X2W_VALLOC_MIN=10000000: exactly one line withsize=0x10000000andtype=0x2000, and a caller in the probe image. Control:X2W_VALLOC_MIN=20000000logs nothing.Run on: CPython 3.12 for Windows under Wine 11.0 (Proton Experimental) on a Linux host, with the probe built by clang-cl against the Windows SDK. That is a translation-layer result, not Windows.
Also ran
python -B tests/docs_links_check.py(pass) andgit diff --check(clean).In use: these three switches are what located the cause behind #1290 (the first failing assert and its stack, then the one fixed-size block the executable reserves at start-up and who reserved it).
Not measured
VirtualAllocof 256 MiB reachesNtAllocateVirtualMemorywith that exact size, which holds under Wine.X2W_VALLOC_MINon a long run (every allocation call is a debugger round trip) is not measured; it is meant for short diagnostic runs.Overlap
#1274, #1251, #1280 and #1229 also touch
debug_launch.py, in other places. Whichever lands later will need a small rebase.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:28:35Z.
Review: COMMENTED
Dual-platform review at commit
8cccacdf737f000c4d2bd4d53860c0a66cb7bd95:Verification
git diff --check origin/main...HEAD: clean (exit 0)/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (16 Markdown files, 286 links)/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (1081 tracked files)--preset dev):cmake --build --preset dev --target startup_debug_probe -- -j 6(3.61s)ctest --preset dev -R '^startup_debug$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (15.74s:startup_debug15.68s)/O2(--preset release):cmake --build --preset release --target startup_debug_probe -- -j 6(0.98s)ctest --preset release -R '^startup_debug$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (15.72s:startup_debug15.66s)Code Review Notes
tools/startup/debug_launch.py:NtAllocateVirtualMemory/NtAllocateVirtualMemoryExregister/stack argument decoding (Rdx->&base,R9/R8->&size,[rsp+0x28]/R9->type,[rsp+0x30]/[rsp+0x28]->protect) matches the x64 Windows syscall ABI.X2W_STOP_AT,X2W_DUMP_AT, andX2W_VALLOC_MINare cleanly integrated withtests/startup_debug_check.pycovering positive and negative controls (non-matching RVA, no--continue-asserts, and higherX2W_VALLOC_MINthreshold).int(os.environ.get("X2W_VALLOC_MIN", "0"), 16)will raiseValueErrorifX2W_VALLOC_MIN=""is set in the environment (or "0"would guard against an empty string).baseinVALLOClogs the input*BaseAddressat syscall entry (which is0x0forVirtualAlloc(nullptr, ...)), rather than the returned allocation base.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:55:15Z.
Review: COMMENTED
Retest & dual-platform review at commit
c0aed1de4dc128b55007e32117b218fb8a223a05(since8cccacdf):Checks
git diff --check origin/main...HEAD: passedtests/docs_links_check.py: passed (16 Markdown files, 290 links)tests/bidi_controls_check.py: passed (1095 tracked files)--preset dev):cmake --build --preset dev --target startup_debug_probe -- -j 6(2.75s),ctest --preset dev -R '^startup_debug$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (18.77s)/O2(--preset release):cmake --build --preset release --target startup_debug_probe -- -j 6(0.25s),ctest --preset release -R '^startup_debug$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (18.74s)Verification of Prior Notes (
8cccacdf)X2W_VALLOC_MIN=""guard (tools/startup/debug_launch.py): Fixed —int(os.environ.get("X2W_VALLOC_MIN") or "0", 16)handles empty strings cleanly, andtests/startup_debug_check.pynow includes an explicitvalloc-emptycontrol.tools/startup/debug_launch.py,docs/startup-runtime.md): Fixed — renamed torequested=and documented as the requested address on syscall entry.No remaining issues found.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:13:57Z.
Review: APPROVED
Retested the updated launcher on Windows x64 using the source-built startup debug probe. The diagnostic and five controls pass, the short pointer fixture covers all incomplete widths, and the host CPU regression passes with 112 native SHA results. The documentation check resolved 313 links.