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

Open
github-bot wants to merge 1 commit from github-bot/gh-2276 into main AGit
Owner

@⁠OldSalty on GitHub · 2026-11-26 12:12 UTC · original
OldSalty:fault-stacks → main · +164 −3 · 4 files · 1 commits · open

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).
**@⁠OldSalty** on GitHub · 2026-11-26 12:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2276) `OldSalty:fault-stacks` → `main` · +164 −3 · 4 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:15:31 +00:00
github-bot force-pushed github-bot/gh-2276 from c243bdb02c to 4469914649 2026-11-26 12:21:03 +00:00 Compare
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-26 13:04 UTC · original · approved these changes

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

**@⁠kawaii-shakal** on GitHub · 2026-11-26 13:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2276#pullrequestreview-6074611600) · **approved these changes** 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](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2276/head:github-bot/gh-2276'
git switch 'github-bot/gh-2276'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2276'
git switch 'github-bot/gh-2276'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2276'
git switch 'github-bot/gh-2276'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2276'
git switch 'main'
git merge --squash 'github-bot/gh-2276'
git switch 'main'
git merge --ff-only 'github-bot/gh-2276'
git switch 'main'
git merge 'github-bot/gh-2276'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.