Repository navigation
Conversation
c243bdb to
4469914
Compare
kawaii-shakal
left a comment
There was a problem hiding this comment.
Reviewed by Claude Code (AI-assisted) on my behalf. Approving: this is the report I was missing when the title
faults.
- The fault and the faulting thread are printed first, before the compile waits and the cache write, so they come
out even if the cache write hangs. - The other threads are sampled the safe way: only system calls while a thread is suspended, and labels are
allocated before sampling. - The faulting thread is unwound on its live stack inside the
__tryofunwind_frame. That is fine from the filter.
Non-blocking ideas, which I'm happy to do as a follow-up on top of this:
- Registers of the faulting context (rip, rsp and the GPRs). With
module+RVAalone it is hard to tell which
pointer was bad. - The parameters of exceptions other than access violations, e.g. 0xE06D7363 (a C++ throw) carries the thrown
type's info. - A crash log file next to the saves or logs that keeps the report after the console window closes, plus a line
with the CPU brand and the Windows build. Intel vs AMD decides which emulated Zen 2 instructions run. - The filter now allocates (
std::string,std::vector, module lookup) where before it only printed. If the fault
came from inside the heap or while the loader's lookup mutex was held, that can hang instead of exiting. A nested
fault insidecall_oncewould block too, though that risk was already there. Not a reason to hold the PR, maybe
one comment saying so.
Not built or run here: Windows-only, so this review is from reading the code.
Generated by Claude Code
|
Verified on Windows 11 (
AI-assisted. |
|
Duplicate check (diff reading only, no build): not a duplicate. #2306 is stacked on this PR ( Heads-up: #2276 and #2306 both conflict in AI-assisted (Claude Code). |
timbot103
left a comment
There was a problem hiding this comment.
Static audit of 446991464 only. No builds, tests, or GPU runs.
- [MAJOR]
runtime/src/thread_stacks.cpp:235— If a runtime DLL load takes an unhandled access violation while adding a range underranges_mutex_(runtime/src/pe_loader.cpp:1731), the filter callsmodule_offseton that same thread before unwinding.Loader::find_addressthen waits for shared ownership of the lock the faulting thread already holds exclusively (runtime/src/pe_loader.cpp:1587). This stalls before the fault details, cache save, and filter chaining. Capture raw fault data and frame addresses in fixed storage. Use prepublished immutable data for in-filter names and move heap-allocating thread snapshots outside the filter. - [MINOR]
runtime/test/thread_stacks_test.cpp:246— The prefix assertion passes for both0 threadsandthread list failed. Keep a synchronized helper alive during the fault and verify its thread ID and a known frame in the snapshot.
AI-assisted.
|
RUN of #2276 (runtime: print the call chain of a fatal fault), local validation, nothing pushed. Heads: PR head 4469914, main c22a0a7. Commands (RelWithDebInfo, Ninja, LEONIDA_REQUIRE_VULKAN=ON, static SDL3): Green (merged): thread_stacks passes, 22 checks, 0 failures (0.25 s). gta6rt builds. The test is a CPU test (it faults on purpose and reads its own stderr capture), not a GPU one. Other tests whose source the PR touches: none (thread_stacks_test is the only target that compiles thread_stacks.cpp besides gta6rt). Red:
Link: no new imports vs main (gta6rt.exe, 703 DLL!symbol entries from dumpbin /imports, identical lists). Note for the maintainer: #2276 (and #2306, which contains it) conflicts with #2555 in runtime/src/main.cpp (checked with git merge-tree of the two heads: CONFLICT in runtime/src/main.cpp). Both add a crash report with registers and stack to the fatal-exception filter, so only one of the two can go in as is, and the maintainer must pick one. The review of timbot103 on this head (the filter calls module_offset, which takes the loader's shared lock, on the faulting thread) was not tested here: this run only shows the new test and the build pass. Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44. |
A run that ended in an unhandled exception saved the pipeline caches but said nothing about where the title faulted: the log had the exception code and no call chain. print_fault_stacks names the access and the address, walks the faulting thread's own chain from the exception context (the filter runs on that thread, so its stack is live), and snapshots the other threads as LEONIDA_STACKS does. On the retail package this unwound a faulting chain of six title frames out of the title's worker pool and named the read that faulted, which no earlier log did. thread_stacks_test covers it with a guarded null read captured to a file.
The faults that end a run follow pointers to garbage, and a faulting address computed base+index says nothing about which pointer was wrong: only the registers still hold the operands. Print the faulting context's registers, then the bytes near each one that points at committed readable memory (the fault's own address first, 48 bytes each, ten lines at most), so the title's data next to the bad pointer can be read out of the log.
print_fault_stacks asked the module registry for a name, which takes g_lookup_mutex and then Loader::find_address's shared ownership of ranges_mutex_: a thread that faults in the DLL load path, holding that mutex exclusively, waits on itself and never reaches the fault line, the cache save or the title's filter. It also allocated, and took a snapshot of every other thread, in the one place where the heap may be what broke. A fatal report now names an address only from a fixed table published as images are mapped, writes with a raw stderr write instead of stdio, and leaves the other threads to print_thread_stacks_now. The whole report runs under __try, so a fault of its own says so instead of re-entering the filter's call_once.
4469914 to
e480a5e
Compare
|
Agreed on the MAJOR — that's the thing I'd want fixed before this lands.
The branch is now rebased onto current main; the fix is the last of three commits (the first two are the reviewed call-chain and registers output, ported as-is), and it is built with MSVC and covered by Plan:
[MINOR] at On #2555: same insertion point, complementary output (RVA, registers, vtable, against a real unwind of the faulting thread and the other threads — and this branch now also prints the faulting context's registers and a hexdump of what they point at, which is idea 1 from the review). We don't contest the item name. Either rebase this onto #2555 and keep only the unwinding, or merge the two reports — your call. One dependency: #2306 is stacked on this branch, so it needs a base either way. |
|
Verified with a negative control, and the result is worth knowing: the tests pass with the header reverted, so they do not observe the change. 1. It applies and builds. merge-tree clean onto main 2. With the branch: 3. The control - revert only the source change, keep the test, rebuild: What that says: the per-thread stack capture is not observed by $(System.Collections.Hashtable.test). The test keeps passing when both the header and its wiring in main.cpp are put back to main's versions. What I am not saying: that the change is wrong. Two readings are possible and I did not choose between them - the test may be a unit test of a header whose behaviour is unchanged in the cases it covers (in which case green either way is correct and the change is elsewhere), or it may be a test that was written beside the change rather than against it. What would settle it in one case: a test that drives the path through the new code - e.g. for this one, the per-thread stack capture with an input that only the new code handles - and asserts on the result. If no such input exists, the change is additive and the control is expected to be green, which is also a useful thing to write in the pull request. Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name, run them, then revert only the source change. A green control is a real result, and it is the one a reviewer cannot get from the diff. Written with an AI assistant. |
|
Independent check on Windows (not the author), at
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711. AI-assisted: yes (opencode). |
A run that ends in an exception nothing handles saves the session pipeline cache but says nothing about where the fault was: the log has
unhandled exception 0xc0000005and no call chain, so a fault in the title or one of its DLLs stays a guess. This prints the fault, what the faulting context's registers held, and the faulting thread's call chain before the caches are written.Item: none listed yet -- claimed in #1608 (see the comment linked below).
Three commits; the third answers the review's MAJOR (reconciliation in the comment below).
[rt] fault fatal: read of 0xf at <module>+0x...), or the exception code otherwise.[rt] fault fatal regs: rip ... rsp ... rbp ... rax ..., plus for each register pointing at committed readable memory a 48-byte hexdump of what it points at ([rt] fault fatal mem rax 0x...:...). A faulting read followed a pointer; the pointers still in the registers say which one, and the bytes say what the title was reading there.ranges_mutex_norg_lookup_mutex, allocates nothing, and writes through_write(_fileno(stderr))instead of stdio. A thread that faults in the DLL load path, where it already holds the loader's lock exclusively, therefore still reports instead of waiting on itself. Addresses in no published range print as bare hex.call_oncealready serialises the writers), no other-thread snapshot -- that allocates and suspends every thread; the report prints[rt] stacks fatal: other threads not sampledinstead -- and the whole report runs under__try, so a fault of the report's own printsthe report itself faultedrather than re-enteringcall_once.LEONIDA_STACKSsnapshot (snapshot_threads) still runs on the non-fatal paths (assert, device loss), where the registry and the filter's own mutex are safe to take and the title's worker pool is worth having in the same log.thread_stacks_testgains a guarded null read with stderr redirected to a temp file: the fault line names the access and the instruction, frame #0 is that same instruction, the chain unwinds out of the function the fault happened in to the function that called it, a published range names the fault's place and becomes a bare number once its owner revokes it, the other-thread line carries a synchronised helper's tid and a known frame, and the non-fatal path still names through the registry and snapshots the other threads. 39 checks, no game data.thread_stacks_teston Windows (MSVC,/W4, 0 warnings), retail run to follow.