Skip to content

runtime: keep Debug startup tracing allocation-free on C++ exceptions (BUILD-3308) - #8898

Closed
channa317 wants to merge 1 commit into
ProjectLeonida:mainfrom
channa317:codex/debug-startup-trace-oom
Closed

channa317 wants to merge 1 commit into
ProjectLeonida:mainfrom
channa317:codex/debug-startup-trace-oom

Conversation

@channa317

@channa317 channa317 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as BUILD-3308. Original claim · Coordination board

Depends on: #5805, #6410, #7189, #7423, #7503, #7514, #7524, #7723, #7824, #8002

The entries above flag rebase conflicts for merge coordination. Three-way comparisons found overlaps in the trace header (#6410, #7189, #7503, #7524, #7723, #7824, #8002), shim registry (#7189), shim declarations (#7514), PE loader (#5805) and Windows trace tests (#7423). This commit builds directly on main@867d922f. #8506 was where the Debug failure was first observed. The regression here runs independently of XMem.

What and why

With --trace enabled, a catchable std::bad_alloc could terminate an MSVC x64 Debug process. During first-chance exception dispatch, the tracer constructed an empty lookup string. The Debug STL attempted to allocate an iterator proxy inside its noexcept constructor. Under sustained allocation failure this reached std::terminate, then the CRT waited in its abort dialog before the caller could catch the original exception.

The C++ exception path now walks up to 16 frames and formats addresses in fixed storage. JSON retains code, cpp, at and stack, including guest basenames and host:<basename>+0x<RVA> for host frames. The loader publishes immutable module ranges for allocation-free lookup. If the guest registry is busy, the tracer can fall back to a raw address. If another writer owns the exception buffer or the output lock, the handler skips that event and lets dispatch continue.

Tested

  • On the parent commit, the new allocation-failure case reached the test's terminate handler (exit 76). With this change the caller caught the original exception. A separate sweep of 40 failure positions completed 40/40 with symbolized JSON and zero formatter calls to operator new.
  • Built gta6rt in Debug and RelWithDebInfo. The native startup_trace CTest passed 15 consecutive runs in each configuration, 39 checks per run. It checks the exact host and guest RVAs, persistent allocation failure, registry reentry, and continued logging after sink contention. The loader, module_names, unimplemented_policy and int3_skip tests passed in both builds. The Python boot trace reader passed all 22 tests.
  • Exercised the gta6rt --dry-run --trace CLI with a synthetic DLL and a missing file in both builds. The process returned the expected exit codes (0 and 1). The exception JSONL parsed with contiguous sequence numbers and contained symbolized runtime frames. The Debug XMem regression from xmem: roll back physical page allocation on metadata exhaustion (BUILD-3078) #8506 also passed 3 runs of 243 checks against this tracer.
  • On this PR alone, the full translator suite ran 5,957 tests across 447 files. Two baseline files remained red (test_image_atomics_guard and test_image_store_d16). In a separate integration run with tests/semantic: three image test files red on main (stale after #4473 and #6805; LLVM_MC on Windows) #7284 at 6a591b77, the same suite reported zero failures and 33 skips. The three Python files from tests/semantic: three image test files red on main (stale after #4473 and #6805; LLVM_MC on Windows) #7284 are outside this PR.
  • git diff --check and the repository's no-game-data check passed for all six changed files.

Test environment

Windows 11 Pro for Workstations 26H2 x64 (26300.9711), Intel Core i9-14900K (24 cores / 32 threads), 128 GiB RAM, NVIDIA GeForce RTX 4090 (24 GB), driver 621.14. The native tests used the CPU and synthetic inputs. Visual Studio 2022 Build Tools 17.14.39, MSVC 19.44.35228.0 (v143, x64, C++20), Windows SDK 10.0.26100.0, CMake/CTest 3.31.6-msvc6, Ninja 1.12.1 and Python 3.12.10.

AI-assisted: yes, with OpenAI Codex.

Checklist

  • No game data, keys or decryption in this contribution.

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified head c725e9c27 merged onto main (867d922f0) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo):

  • python -I scripts/check_no_game_data.py on all 6 changed files: clean (exit 0)
  • cmake --build runtime/build --target startup_trace_test loader_test --parallel: built cleanly
  • ctest --test-dir runtime/build -R '^(startup_trace|loader)$' --output-on-failure -V: 2/2 passed (loader: 88 checks, 0 failed; startup_trace: 39 check(s), 0 failed)

AI-assisted.

@RAINighty

Copy link
Copy Markdown

Tested c725e9c27 merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, MSVC 19.44.35228, RelWithDebInfo (Ninja): pass.

  • startup_trace passes with this PR.
  • Control: this PR's startup_trace_test.cpp with main's registry.cpp, shims.h, startup_trace.h, pe_loader.cpp and pe_loader.h does not compile (format_trace_address is not a member of rt::shims), so there is no pass or fail to compare.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

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

The allocation-free C++ exception path is coherent: fixed-frame capture, fixed-buffer symbolization, sink try-lock, and the registry reentry guard all match the claim. Added tests cover refused allocations, reentry, and sink contention; the Python boot-trace suite remains 22/22 and no game-data issues were found. The C++ changes are diff-review only here because no local C++ compiler is available.

AI-assisted (OpenCode).

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