Skip to content

runtime: a fatal fault's report names its registers and host, and is kept in a crash log (RT-CRASH-LOG) - #2306

Open
Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-crash-log
Open

Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-crash-log

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-CRASH-LOG (#1608 (comment))

Depends on: #2276

What and why

This is @kawaii-shakal's crash-log branch (commit 4be6853, their finding in #1608), built and tested on Windows. Their commits are kept as they are; this PR adds only a merge of current main.

kawaii-shakal's work (4be6853, on top of #2276's print_fault_stacks): a fatal fault's report from #2276 went to stderr only, so it was lost once the console closed, and it lacked the registers, the host and what a non-access-violation exception carries. With this:

  • the faulting context's registers (rax..r15, rip, eflags) and a host line (Windows build from RtlGetVersion, CPU brand from CPUID) are printed as [rt] fault lines;
  • an exception other than an access violation prints its parameters: a C++ throw's object, throw info and mangled type name (read under __try), an in-page error's status, or the raw parameters;
  • the whole report, after a dated header, is appended and flushed to %LOCALAPPDATA%\Leonida\crashes.log (Win32 calls only), or to the file LEONIDA_CRASH_LOG names; LEONIDA_CRASH_LOG=0 turns the file off;
  • the text is built in the portable src/crash_report.h and checked by crash_report_test; thread_stacks_test points the crash log at a temp file and checks its content; the variable is documented in runtime/README.md.

Windows fixes on top: none were needed. MSVC 19.52 compiles thread_stacks.cpp, thread_stacks_test.cpp, crash_report_test.cpp and gta6rt with no errors and no warnings in these files at /W4 /permissive-.

Tested

Windows 11 (10.0.26300), MSVC 19.52.37029, Ninja RelWithDebInfo, AMD Ryzen 7 9800X3D:

  • ctest -R "thread_stacks|crash_report": 2/2 pass. thread_stacks_test takes a real null read through print_fault_stacks and checks the temp crash log holds the dated header, the fault, the faulting thread's chain and the other threads.
  • A throwaway program (not committed) linking thread_stacks.cpp, with an unhandled-exception filter calling print_fault_stacks and returning EXCEPTION_CONTINUE_SEARCH, run with LOCALAPPDATA pointed at a temp folder:
    • an unhandled access violation (exit 0xc0000005) creates Leonida\crashes.log under it with the header, read of 0x14 at host:fault.exe+0x..., the registers, host: Windows 10.0.26300, CPU AMD Ryzen 7 9800X3D 8-Core Processor and the chain;
    • an unhandled C++ throw (exit 0xe06d7363) appends a second report with C++ exception: object ..., throw info ..., type .?AUMyError@@;
    • with LEONIDA_CRASH_LOG=0 the report still goes to stderr and no file is created.
  • tests/test_ctest_registration.py and scripts/check_no_game_data.py pass.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code). The original branch was also written with Claude Code, as kawaii-shakal noted in #1608.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

OldSalty and others added 3 commits November 26, 2026 22:15
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.
…kept in a crash log (RT-CRASH-LOG)

On top of print_fault_stacks (ProjectLeonida#2276):
- the faulting context's registers (rax..r15, rip, eflags) and a host line
  (Windows build from RtlGetVersion, CPU brand from CPUID), as [rt] fault lines;
- for an exception other than an access violation, what its parameters say:
  a C++ throw's object, throw info and mangled type name (read under __try),
  an in-page error's status, or the raw parameters;
- the whole report, after a dated header, is appended and flushed to
  %LOCALAPPDATA%\Leonida\crashes.log, or to LEONIDA_CRASH_LOG (0: no file),
  with Win32 calls only, so it outlives the console.

The text is built in src/crash_report.h, pure and portable, and checked by
crash_report_test on every platform. thread_stacks_test points the crash log
at a temporary file and checks its content.

Idea from Marvisak/VIctory (crates/victory-loader/src/crash.rs, GPL-3.0); no
code of it is used.

Changes made by Claude Code (AI-assisted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3

@lixonik lixonik 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.

Windows 11/MSVC: crash_report and thread_stacks both passed using the repo's fixtures. A title boot and actual title crash were outside this run.

AI-assisted.

@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. Comment, not an approval: the code is my commit 4be6853,
unchanged. The diff against my crash-log branch is only the merge of main, so an approval from me would be
approving my own code.

Thanks for taking it over and for the Windows run, which was the part I could not do. MSVC 19.52 at
/W4 /permissive-, thread_stacks_test and crash_report_test passing, and the manual AV and C++-throw reports
checked in the log were exactly what was missing. lixonik's run confirms the tests too.

Two known limits:

  1. The filter allocates (std::string, the module lookup, the thread snapshot), as #2276 already did. A fault inside
    the process heap, or while the loader's lookup mutex is held, can hang there instead of ending the process. A
    nested fault inside call_once would block too. Not worse than #2276, but worth knowing when a crash "hangs".
  2. read_thrown_type follows the throw info without checking the magic in parameter 0 (0x19930520..0x19930522). A
    foreign 0xE06D7363 with garbage parameters is caught by __try and gives no type, so it fails safe, but checking
    the magic first would skip the reads.

Neither blocks. A maintainer or another reviewer should give the approval.


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 + c2dc711333 (claim #2570#issuecomment-7239309422):

  • Line-by-line diff audit: Clean (runtime/CMakeLists.txt, runtime/README.md, runtime/src/crash_report.h, runtime/src/main.cpp, runtime/src/thread_stacks.cpp, runtime/src/thread_stacks.h, runtime/test/crash_report_test.cpp, runtime/test/thread_stacks_test.cpp); adds portable register/exception/host formatting, RtlGetVersion + __cpuid host diagnostics, SEH-guarded MSVC ThrowInfo type-name inspection, live faulting-thread stack unwinding, and flushed LEONIDA_CRASH_LOG / %LOCALAPPDATA%\Leonida\crashes.log persistence. check_no_game_data.py and test_docs_encoding.py clean.
  • Red (d48a957bb + PR test): Fails to build (rc=2, error C2039: 'print_fault_stacks': is not a member of 'rt').
  • Green (d48a957bb + c2dc711333 merge): Auto-merges cleanly (rc=0), compiles thread_stacks_test.exe and crash_report_test.exe with 0 warnings under /W4 /permissive-, passes thread_stacks_test.exe (23 checks, 0 failures, rc=0) and crash_report_test.exe (crash_report_test: all checks passed, rc=0), and compiles runtime/src/main.cpp cleanly (0 new warnings).
  • Non-blocking notes: Supersedes/extends #2276 and overlaps #2555 on main.cpp fatal-exception reporting. Two minor nits in thread_stacks.cpp: line 401 could call crash_report::access_kind(...) so unexpected ExceptionInformation[0] values format as "access" rather than "execute", and read_thrown_type (lines 309-315, safely inside __try) reads 32-bit x64 ThrowInfo RVAs as signed int32_t rather than uint32_t (which would sign-extend RVAs >= 0x80000000 in >2 GiB images).

AI-assisted.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
@TheGeogeo

Copy link
Copy Markdown
Contributor

Duplicate check (diff reading only, no build): not a duplicate of #2276. It is stacked on it (it contains #2276's commit) and adds the registers, the host and the crash log file (crash_report.h, thread_stacks.cpp). It needs a rebase (needs rebase).

Heads-up: this PR and #2276 both conflict in runtime/src/main.cpp with #2555 (git merge-tree). #2555 also prints a fatal exception's registers and stack, so the two register reports overlap. Worth choosing one before merging.

AI-assisted (Claude Code).

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

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants