Skip to content

runtime: a fatal exception names its place in the title: RVA, stack, registers (RT-FATAL-REPORT-RVA) - #2555

Open
kristofbarany wants to merge 1 commit into
ProjectLeonida:mainfrom
kristofbarany:leonida/fatal-report
Open

kristofbarany wants to merge 1 commit into
ProjectLeonida:mainfrom
kristofbarany:leonida/fatal-report

Conversation

@kristofbarany

Copy link
Copy Markdown

Claimed in the coordination issue as: RT-FATAL-REPORT-RVA (#1608 (comment))

What and why

gta6rt's fatal-exception filter printed only the exception code ([rt] unhandled exception 0x80000003: writing the session pipeline cache ...), so a title's soft assert (an int3 after a report call) could not be traced from the
log. It now also prints, once, before the pipeline cache is written:

[rt] fault at title +0x<rva>
[rt] title addresses on the stack (innermost first): +0x<rva> +0x<rva> ...
[rt] registers: rax=... rbx=... rcx=... rdx=... rsi=... rdi=... rbp=... rsp=... r8=... r9=... r12=... r13=... r14=... r15=...
[rt] rbx points at an object with vtable title +0x<rva>
  • The faulting address as an RVA of the title's image (or "outside the title image").
  • Up to 12 stack qwords that point into the image (likely return addresses), from the 512 above rsp.
  • The general registers, and the vtable RVA of an object in rbx when its first qword points into the image.
  • Reads go through ReadProcessMemory, so a bad stack pointer ends the walk instead of faulting again inside the
    handler (runtime/src/fatal_report.h). The image's base and size are recorded right after the title is loaded.

Found with it (the use that motivated it, see #2554): with the title's own upscaler forced on Series S, the title
stops about 30 s in at its out-of-memory report. The report gave the int3's RVA, the allocator call on the stack,
the request size in rdi (2.1 MiB) and the allocator object's vtable from rbx; reading that object's fields
then showed the full 1,277 MiB range.

Tested

  • fatal_report_test (new): a made-up exception record, context and stack over a stand-in image: the RVA, the image
    addresses in order with the limit, the registers, rbx's vtable, and a fault outside the image, an unknown image,
    an unreadable stack pointer and null exception pointers (no fault, a report). 7/7.
  • Full ctest on this branch (Windows 11, MSVC 2022, Ninja, RelWithDebInfo): 508 of 510 passed. The two failures,
    xbox_present (present failed (VkResult -11)) and d3d12_set_descriptor_heaps (recorded_commands check), are
    separate executables that do not build src/main.cpp or the new header, and fail the same way on the branch of
    runtime: LEONIDA_TITLE_PATCH, checked byte patches of the title from the environment (RT-TITLE-PATCH-ENV) #2554.
  • tests/test_docs_env_vars.py, test_ctest_registration.py, test_text_encoding.py: OK.
    scripts/check_no_game_data.py on the changed files: clean.
  • In the game: the same report code in a local build on an older runtime printed the lines above for the title's
    int3 (three runs, the same RVA each time). Not yet run in the game on this main.

GPUs tested: NVIDIA GeForce RTX 4070 12 GB, driver 621.40, Windows 11 (ctest)

AI-assisted: yes (Claude Code)

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)

…registers)

The fatal-exception filter printed only the code ("unhandled exception 0x80000003"), so a
title's soft assert (int3 after a report call) could not be traced from the log. It now
also prints the faulting address as an RVA of the title's image, the stack qwords that
point into the image (likely return addresses, innermost first), the general registers,
and the RVA of the vtable of an object in rbx. Reads go through ReadProcessMemory, so a
bad stack pointer ends the walk instead of faulting inside the handler
(runtime/src/fatal_report.h).

Found with it: the title's out-of-memory int3 when its own upscaler is forced on Series S
(the allocation size in rdi, the allocator's vtable from rbx).

Test: fatal_report_test (made-up exception record, context and stack over a stand-in image).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor

#2555 | head db0ecba | ctest -C RelWithDebInfo -R "^fatal_report$" (MSVC RelWithDebInfo; gta6rt also built) | red: n/a, the test includes the new src/fatal_report.h, so on main it does not compile (new diagnostic, not a fix of something main gets wrong) | green: main 02f71cc merged into the head, 7 checks, 0 failures, 1/1 passed | full suite: not run (a game boot was using the machine) | Windows 11, RTX 4070 SUPER, NVIDIA 621.01, Python 3.14 | AI-assisted: yes, Claude Code

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

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

Using ReadProcessMemory in rt::fatal_report::describe keeps the fatal-exception diagnostic safe against bad stack/object pointers, and the RVA/stack/register/vtable formatting and unit tests are clean.

Tests run

  • ctest --output-on-failure -R "^fatal_report$": 1/1 passed (fatal_report 0.02 s).
  • python -m unittest tests/test_ctest_registration.py: 7/7 passed (1.01 s).

AI-assisted (Antigravity, Gemini).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Native Windows 11 + MSVC 19.44 + Live Hardware int3 SEH Verification (db0ecbacec + origin/main adfb3821a2)

Verdict: PASS (0 blockers, 0 /W4 warnings in new code)

Environment & Merge Check

  • Host: Windows 11 (10.0.26200), MSVC 19.44.35228 (x64, /W4 /permissive- /utf-8 /O2 /EHsc)
  • Merge & Registration Hygiene: Clean merge onto origin/main (adfb3821a2, git merge-tree --write-tree rc=0); runtime/src/main.cpp compiles cleanly under /W4; test_ctest_registration.py, test_ci_registration.py, and test_text_encoding.py all OK.

Red -> Green & Live Hardware SEH Results

  • Red: runtime/src/fatal_report.h and fatal_report_test are absent on origin/main (C1083), where save_caches_on_fatal_exception logs only the exception code without RVA, stack, or register context.
  • Green (PR #2555 + origin/main):
    1. fatal_report_test.exe: PASS (7 checks, 0 failures, 0 /W4 warnings).
    2. Live Windows 11 x64 hardware int3 (__debugbreak()) SEH probe: Raised a real EXCEPTION_BREAKPOINT (0x80000003) inside nested non-inlined PE functions and passed GetExceptionInformation() into rt::fatal_report::describe against GetModuleInformation base/size — confirmed accurate fault RVA ([rt] fault at title +0x203a), innermost-first hardware stack return RVAs (+0x20fb +0x19560 ...), and live register dump (rc=0).

Diff Audit Notes (Non-Blocking Suggestions)

  • r10 and r11 (the two volatile x64 scratch/indirect-call registers) are omitted from the [rt] registers: format string between r9 and r12; including them could help when diagnosing indirect/CFG call faults.
  • describe() builds its output in std::string inside save_caches_on_fatal_exception; if a fatal exception ever occurs while the default process heap lock is held or corrupted, formatting stack-buffered lines directly to STD_ERROR_HANDLE (WriteFile / fputs on char buf[512]) would keep the diagnostic completely heap-free.

AI-assisted.

@enlight3d

Copy link
Copy Markdown
Contributor

Run of #2555 (fatal_report), red then green.

  • PR head: db0ecba (base 1a441d3). Current main: 1bc055e. git merge-tree --write-tree main <head> merges cleanly.
  • GPU/driver: NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by these CPU-only unit tests). OS: Windows 11 Pro 10.0.26300, MSVC 19.44 (VS 2022 Build Tools), CMake 3.31.6, Ninja 1.12.1, RelWithDebInfo.
  • Only the test target was built, not the whole runtime.

Commands (in a vcvars64 shell, build folder inside the worktree):

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build --target fatal_report_test -j 8
ctest -R "^fatal_report$" --output-on-failure

Green (PR head): builds, fatal_report Passed (1/1, 0.02 s).

Red (non-test changes reverted: runtime/src/fatal_report.h removed and runtime/src/main.cpp back to the base, test and CMake registration kept): the target does not build (C1083: cannot open include file '../src/fatal_report.h') and the same ctest ends fatal_report (Not Run), 0 of 1 passed. Since the PR adds a new header, red here is a build failure and not an assertion failure. The stale test executable from the green build was deleted before this ctest, so it could not pass by leftover.

Overlap (checked with git merge-tree): this PR conflicts with #2306 (which contains #2276) in runtime/src/main.cpp; both add a crash report with registers and stack, so only one of the two can go in as is.
Link check: merged into main 1bc055e, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

@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 db0ecbace against 48bae6cad. I found two issues.

  • runtime/src/fatal_report.h:37 and runtime/src/main.cpp:374: the top-level filter allocates and writes through CRT stderr before saving caches. A failed allocation can bypass the save and filter delegation, and a blocked report holds the existing call_once. Please format into a fixed-size buffer, bypass CRT stdio for the new output, and preserve cache saving and filter delegation when reporting fails.
  • runtime/src/fatal_report.h:45: ReadProcessMemory checks readability. A corrupt Rsp can still point into a readable non-stack page. Please bound the scan to the faulting thread's stack and cover readable non-stack memory and the upper stack boundary in the synthetic test.

AI-assisted.

@fiestorra

Copy link
Copy Markdown
Contributor

Verified on the C++ runtime here, because this one can be built and run without the game.

The branch is 1780 commits behind, so the question is whether it still applies at all. Applied onto origin/main 4364a4fa6:

4 files changed, no conflicts (runtime/CMakeLists.txt, runtime/src/fatal_report.h,
                                runtime/src/main.cpp, runtime/test/fatal_report_test.cpp)
cmake --build … --target fatal_report_test  -> built
fatal_report_test.exe                       -> 7 checks, 0 failures, exit 0
cmake --build … --target gta6rt             -> built (main.cpp is one of the files it changes)

So: it applies, its own test passes, and the whole runtime still compiles with the change - which matters more than usual here because main.cpp is where the fatal
path lives and a mistake there would show up as a build break rather than a test failure.

What this does not cover: anything that needs the game to run. I built gta6rt but did not launch it, so the part that prints an RVA and registers for a real
exception is unexercised - fatal_report_test drives the formatter with synthetic data, which is the testable half.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, MSVC 19.44.35226). It applies, builds and passes; the negative control is impossible by construction, and I say so rather than dress up a passing number.

1. It applies. merge-tree clean; db0ecbace cherry-picks onto main 0ae217ceb without a conflict. Four files, 161 insertions(+), 1 deletion(-): fatal_report.h (new), main.cpp, the test, and its CMake registration.

2. It builds and passes, three times: fatal_report_test.exe -> exit 0, 0, 0.

3. The negative control cannot be built. fatal_report.h is a new file and the test includes it (6 references); with the header removed the compile stops at:

fatal_report_test.cpp(14): fatal error C1083: Cannot open include file

So there is no main version of this test to run against - the same shape as #2651 and #2645. What that proves is that the test exercises the new reporting path; it does not prove the path is right.

A trap I fell into and caught in this same round: my first attempt reverted only main.cpp (the header does not exist on main, so git checkout origin/main -- … fails for it), Ninja reported "no work to do", and the binary from the previous build answered exit 0. That number was the old executable, not the reverted source. The .exe timestamp is what exposed it - 07:00:45, unchanged - and the compile failure above is the real result of the attempt.

What I did not test: a fatal exception in a real run. The test builds the report from a synthetic fault record; whether the RVA, stack and register block it prints point at the right place in the title needs a crash under the loader, which is the situation this reporting exists for and one this machine cannot stage.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

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 d367675c7.

2. With the branch:

ctest -R '^fatal_report'
100% tests passed, 0 tests failed out of the target's tests

3. The control - revert only the source change, keep the test, rebuild:

git checkout origin/main -- runtime/src/fatal_report.h runtime/src/main.cpp
cmake --build … --target fatal_report_test
ctest -R '^fatal_report'
100% tests passed, 0 tests failed           <- still green

What that says: the fault report written for an exception 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 fault report written for an exception 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.

@KelboLive

Copy link
Copy Markdown

Independent check on Windows (not the author), at db0ecbace.

  • Configured the branch's runtime and built fatal_report_test (MSVC 14.52.37025, Windows SDK 10.0.26100).
  • Ran it: 7 checks, 0 failures — RVA naming, ordered image addresses (limit 4), registers, vtable, outside/bad-stack, unknown image, and no exception pointers.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.

AI-assisted: yes (opencode).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Maintainer review: not ready to merge. Blockers: (1) gh pr checks reports no checks for the current head; the comments contain test runs, but no current CI result is available. (2) This PR overlaps the still-open #2306 crash-reporting change; the intended single implementation needs to be resolved before merge. (3) The latest independent review reports the new fatal path can allocate/use CRT stderr before cache saving and that the stack scan is not bounded to the faulting thread stack; no fix or response is present in the discussion. (4) A later negative-control report says fatal_report_test still passes after reverting the source change, so the test does not demonstrate the new behavior. Please address these points or explain why each is safe, then refresh validation.

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.

9 participants