Skip to content

runtime: print the call chain of a fatal fault - #2276

Open
OldSalty wants to merge 1 commit into
ProjectLeonida:mainfrom
OldSalty:fault-stacks
Open

OldSalty wants to merge 1 commit into
ProjectLeonida:mainfrom
OldSalty:fault-stacks

Conversation

@OldSalty

Copy link
Copy Markdown

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 0xc0000005 and no call chain, so a fault in the title or one of its DLLs stays a guess. This prints the fault and the threads' call chains before the caches are written.

Item: none listed yet -- claimed in #1608 (see the comment linked below).

  • Fault line: the access and the address for an access violation ([rt] fault fatal: read of 0xf at <module>+0x...), or the exception code otherwise, with the module named by the same shims::module_offset the other traces use.
  • The faulting thread: its chain walked straight from the exception context. The filter runs on the faulting thread and that stack is live under it, so this needs no copy, unlike a sampled thread.
  • The other threads: the LEONIDA_STACKS snapshot (snapshot_threads), so what the title's worker pool and the compile pool were doing at the fault lands in the same log.
  • Order: it runs first in the filter, while the stacks are live, then the compile stop and the cache write as before; the exception still goes on to the previous filter, so the exit code is unchanged. Nothing happens unless a run dies.
  • Tests: thread_stacks_test gains 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, and the other threads are snapshotted. 19 checks, no game data.
  • Tested: on the retail package, where it named a faulting read and unwound six title frames out of the title's own job-worker pool -- a site two of three boots hit and no log had ever placed -- and thread_stacks_test on Windows (RelWithDebInfo).

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.

@kawaii-shakal kawaii-shakal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 __try of unwind_frame. That is fine from the filter.

Non-blocking ideas, which I'm happy to do as a follow-up on top of this:

  1. Registers of the faulting context (rip, rsp and the GPRs). With module+RVA alone it is hard to tell which
    pointer was bad.
  2. The parameters of exceptions other than access violations, e.g. 0xE06D7363 (a C++ throw) carries the thrown
    type's info.
  3. 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.
  4. 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 inside call_once would 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

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main d48a957bb + 4469914649 (claim #2570#issuecomment-7239117859):

  • Line-by-line diff audit: Clean (runtime/src/main.cpp, runtime/src/thread_stacks.cpp, runtime/src/thread_stacks.h, runtime/test/thread_stacks_test.cpp); adds noexcept rt::print_fault_stacks to log access-violation / exception details, unwind the live faulting CONTEXT directly on the crashing thread before save_caches_on_fatal_exception waits on pipeline compiles, and snapshot remaining threads. check_no_game_data.py clean.
  • Red (d48a957bb + PR test): thread_stacks_test.cpp fails to build (rc=2, error C2039: 'print_fault_stacks': is not a member of 'rt').
  • Green (d48a957bb + 4469914649 merge): Auto-merges cleanly (rc=0), compiles thread_stacks_test.exe with 0 warnings under /W4 /permissive- and passes (19 checks, 0 failures, rc=0), and compiles runtime/src/main.cpp cleanly (0 new warnings).

AI-assisted.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Duplicate check (diff reading only, no build): not a duplicate. #2306 is stacked on this PR (Depends on: #2276, and its head contains this commit), so #2276 lands first and #2306 after its rebase (it is labeled needs rebase).

Heads-up: #2276 and #2306 both conflict in runtime/src/main.cpp with #2555 (git merge-tree). #2555 also reports a fatal exception's place, stack and registers. Worth deciding which fatal report wins before merging either side.

AI-assisted (Claude Code).

@timbot103 timbot103 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 under ranges_mutex_ (runtime/src/pe_loader.cpp:1731), the filter calls module_offset on that same thread before unwinding. Loader::find_address then 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 both 0 threads and thread list failed. Keep a synchronized helper alive during the fault and verify its thread ID and a known frame in the snapshot.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants