xcl run: dump the memory around an unhandled exception's pointers (XCL_FAULT_DUMP) #3027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3027"
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 ivall/xcl. Originally posted by tiagonleal on 2026-11-27T14:20:53Z.
Adds an opt-in switch,
XCL_FAULT_DUMP=1. When the title raises an unhandled exception, XCL logs the memory around the faulting address and around each register that holds a readable pointer, after the existingunhandled exceptionline, itspage oflines and the saved crash report. Off by default.Part of #505
Why
Crash reports on the retail title of #505 and #2867 carry register values only. On my machine a lab version of this dump is what showed that the bad values are not random: in several crashes the faulting field sits inside a run of 64-byte records whose dwords at +0x18, +0x24, +0x30 and +0x3c hold
0x7ffffffftriplets, written over live objects. That is not visible from registers. A second pattern it makes visible is a pointer whose upper 32 bits were overwritten: the title faults at the low half, and the dump shows the address it meant.Rebased onto
main1c8b5514(no conflicts; the earlier rebase ontod8bd9a38had these:) Conflicts: the README list of switches, andeh.rswheremainadded thepage oflines; the dump now runs after them.What is in it
crates/xcl/src/eh/fault_dump.rs(new): candidate selection and formatting, both pure and tested through a reader closure.<==. A line already printed for an earlier pointer is not printed again; when that line holds a later pointer, a<address>: shown above <==line marks it under the later pointer's header, so every pointer has a marked line (review in this thread).ReadProcessMemoryon the own process, so a page another thread frees meanwhile givesunreadable, not a second fault.try_lock): a fault while a report is being written gets none and does not count against the 2. The lock and the line sink are passed in (emit_one_at_a_time) so this path has a unit test.crates/xcl/src/eh.rs: calls it after the existing line, the page lines,report::write_finalandlog::flush, so a dump that hangs on a corrupted heap cannot cost the crash report (review in this thread); the register copy is made only when the switch is on. The dump lines are error level, which flushes on every write.README.md: the switch, next toXCL_DRED, with a note that the dump goes toxcl.logand can hold the title's stack and data.One commit: the earlier three (first version, safe reads and order, dump after the crash report) are squashed into it, with a message that describes the final code.
Line format (
fault dump:prefix, error level; the values here are made up to show the layout):Tested
RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, branch on
main06f90c19.9d86cd4f(one commit onmain1c8b5514, markers and lock test from this review), Rust 1.100.0, debug:cargo test -j 8 -p xcl --lib fault_dump: 12 passed, 0 failed (new:a_dump_while_another_is_written_is_skipped_and_not_counted;format_says_unreadable_and_skips_lines_already_shownnow checks theshown above <==line).cargo test -p xcl --lib eh::: 26 passed.9d86cd4f,cargo test -j 8 --workspace --no-fail-fast -- --test-threads=4: 2921 passed, 0 failed, 51 ignored, 24SKIPPEDtests (22 no wave64, 2 no heap windows). A first run had 3e2efailures because another job on this machine killed processes namedxcl.exe;cargo test -p xcl --test e2ealone then passed 5 of 5, and the full rerun above is clean.cargo test -j 6 -p xcl --lib fault_dump: 11 passed, 0 failed.cargo test -j 6 --workspace --no-fail-fast -- --test-threads=4: 1465 passed, 4 failed, 47 ignored, 25SKIPPEDlines (no wave64 on this card; some f16/f32 per-lane forms refused).gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState0x8007000E). They fail the same way onmainwithout this change.maind8bd9a38(headdd6ea919):cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4, one run: 2625 passed, 4 failed, 49 ignored (26SKIPPEDlines). The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3. The 4 are thefuzz_validate_and_gpu_*tests, which fail onmainhere too (#1919 fixes them);main's run had a fifth failure, the intermittent e2e check reported in #3382. Onmaind8bd9a38on this machine the same command gave 2613 passed, 5 failed, 49 ignored (26SKIPPEDlines). The other results in this section are from the earlier heads named in them.a5ac179b(rebased ontomain1c8b5514, dump moved after the crash report), Rust 1.100.0, debug:cargo test --workspace --no-fail-fast -- --test-threads=4: 2920 passed, 0 failed, 51 ignored, 24SKIPPEDtests (20 of them no wave64). Thefuzz_validate_and_gpu_*failures above came from the old base and are gone with #1919 inmain.Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e(Newer Retail Game), release builds of both commits in clean trees,main1c8b5514first, then this PR's head, one after the other. Both runs hadXCL_PREPARE=0and the same warm DXIL cache. On the head before this rebase, one run stopped after about 7 s with exit 0 and no crash or device removal; the head below ran its full 60 s on the first try.main(1c8b5514):This PR (
9d86cd4f):Not tested
try_lockpath) on a real crash; the unit test drives it with a lock held by another thread.AI use
Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing with the supervision of @tiagonleal.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:22:18Z.
Triage (#1607) – head
dd6ea91No open or merged PR makes the same change (#1186 names the faulting address's memory state, not its contents). No problems found in the diff: the dump is opt-in, reads through ReadProcessMemory, is capped at 300 lines for the first 2 faults, and has unit tests for the candidate and format logic.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T12:15:39Z.
merge-check
base:
493dbd3dd0head:
dd6ea9199amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+300). With
XCL_FAULT_DUMP=1, the last-chance crash handler writes the memory around each register that points into readable memory. Findings: (1) The dump runs before the crash report is saved.eh.rs~137 calls it ahead ofreport::write_finalandlog::flush(~138-139). If the crash came from heap corruption, the dump's allocations can hang on the broken heap and the main crash report is lost. Calling it after the flush avoids that. (2) It writes the stack and title memory intoxcl.log, which people attach to issues; a line in the README saying the dump can contain the title's data would be fair. (3) When two registers point close together, the second one's<==marker is missing (fault_dump.rsformat). Fine: off unless exactly1, reads go throughReadProcessMemoryso a bad pointer can't fault again inside the handler, and it runs fromSetUnhandledExceptionFilter, not the early handlers that also see faults the title handles. It writes at most 300 lines for each of the first two faults (about 30 KB each), and the pure logic is tested. No smoke run: it only acts on a crash.performance: no smoke run (the default path doesn't reach this change); not measured. Only runs on a crash with
XCL_FAULT_DUMP=1.verdict: safe to merge (off by default; calling the dump after
report::write_final/log::flushwould keep the crash report safe if the dump hangs on a corrupted heap)hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T10:13:07Z.
Moved the dump after
write_finaland the flush, so a dump that hangs cannot cost the crash report, and added a README sentence saying the dump goes toxcl.logwith the title's stack and data. Rebased ontomain1c8b5514; the suite and both smoke runs are in the description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:17:37Z.
Follow-up review (head
a5ac179b, sincedd6ea91, diff read, not a merge-check):fault_dump::lognow runs afterreport::write_finalandlog::flush(eh.rs~137-140), so a dump that hangs on a broken heap no longer loses the report.README.md~405-406).<==marker missing when two pointers are close: still open. A line already printed for an earlier pointer is skipped (eh/fault_dump.rs~86-92), so the later pointer gets a header and no marked line, and the test (~264) now asserts that. Since the rebased fault comes first, the register that supplied its upper half usually loses its marker.eh.rsfilter block, so whichever lands second rebases).New:
1f08d409anda5ac179brework code6d51758badded: on its own6d51758bchecks memory withreadableand then copies it withcopy_nonoverlapping(a page freed in between faults inside the filter) and waits onLOCK.lock(), and its message still describes that.git bisectcan land there; the three should be squashed with the final wording.try_lockpath is untested. Not tested says the concurrent-fault path is untested "outside unit tests", but no test callslog(~135-150), the only placetry_lockis used.Fine: off unless
XCL_FAULT_DUMPis exactly1; reads go throughReadProcessMemoryon the own process, so a bad pointer givesunreadableinstead of a second fault; the dump's lock is atry_lockand the only blocking lock is the log file's, which the crash line already takes; capped at 300 lines for the first 2 faults; the selection and formatting are unit-tested.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T15:23:20Z.
Thanks for the follow-up. All three are in the new head (
9d86cd4f):Missing
<==for a close second pointer: when a pointer's own line was already printed for an earlier pointer, its header is now followed by one<address>: shown above <==line, so every pointer has a marked line and no memory is printed twice. The test now checks rbx gets that line and that there are two markers.try_lockuntested:lognow hands its lock and a line sink toemit_one_at_a_time, anda_dump_while_another_is_written_is_skipped_and_not_countedholds the lock on one thread, calls it from another, and checks nothing is written and the fault is not counted. Once the lock is free the same call writes the dump.Fixup commits: squashed into one commit whose message describes the final code (ReadProcessMemory reads,
try_lock, dump after the crash report, the markers).Tiago
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T15:29:14Z.
Follow-up review (head
9d86cd4f, sincea5ac179b, diff read, not a merge-check):<==marker missing when two pointers are close: fixed. When a pointer's own line was already printed for an earlier one, ashown above <==line now marks it (eh/fault_dump.rs~89-97).try_lockpath untested: fixed by the commit's own account: the cap and thetry_lockpath take a reader and a lock and are unit-tested.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T12:42:58Z.
merge-check
base:
a815de932chead:
9d86cd4fb0merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3030 passed, 0 failed, 56 ignored; SKIPPED: 25, the same list as on main
395405e4(22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none. The 12fault_dumptests are among the passed.review: read the whole diff (3 files, +336). No blocking finding.
xcl run, debug build of the merge onto0c725d5d(main has only gained #3707 since, ingpu/dxil):XCL_FAULT_DUMP=1: the crash line, thenfault under rcx's upper half=0x3554321000as the first entry with the right words and the<==mark, then the registers. 164 lines, written within about 10 ms of the crash line.report.jsonhas the crash.XCL_FAULT_DUMP=0: the same crash line and report, no dump line.report.json, and the process ended by itself.write_finaland the log flush, so a dump that fails cannot cost the report. Reads go throughReadProcessMemory, so memory freed meanwhile givesunreadableand no second fault.eh.rs(Foniass noted it too), so whichever lands second needs a rebase.performance: none by default (reasoned): the code runs only in the unhandled-exception filter, and without the switch it stops at one check.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.