Stack dumps: unwind a copy of each thread's stack, LARP_STACKS_AT_KILL, LARP_TITLE_WATCHDOG (part c of #77) #140

Manually merged
github merged 4 commits from github-bot/gh-140 into gh-pr/140/base 2026-12-06 01:25:37 +00:00 AGit
Owner

@⁠kadiratesdev on GitHub · 2026-12-05 19:31 UTC · original
kadiratesdev:pr/split-c-stacks → main · +266 −14 · 7 files · 4 commits · merged 2026-12-06 00:07 UTC

This is part (c) of the split @⁠gamingwithhomie asked for on #77. It is independent of part (b) (diagnostics, #126) and part (a) (Agility/d3d12.dll loader). It touches no file those two touch, except the docs tables (separate rows, merged cleanly with both in a local trial merge). Based on the same main as #126 (334be94).

Per the review, do not merge before a LARP_STACKS stall-dump sanity run on a real machine: the stack walk is the part I have not been able to exercise in-game (see Testing).

What is in it

  • Stack walks unwind a copy (ported from VIctory-NVIDIA 43e89ba1). LARP_STACKS walked each suspended thread's live stack with RtlVirtualUnwind, which reads through a frame register that can hold anything where the thread was stopped, or through stack pages the thread never committed. In VIctory-NVIDIA that ended the process with an access violation inside ntdll.
    • frames_of now copies the stack (from rsp up, at most 512 KiB, zeros after) with ReadProcessMemory while the thread is suspended, resumes it, and unwinds the copy (crash::unwind_copy).
    • unwind_into, the crash handler's live walk, stops where a frame register lies outside the thread's stack.
    • Same output format as before.
  • LARP_STACKS_AT_KILL=1 (off by default; ported from VIctory-NVIDIA c6d5c4d7): when the title's 30 s watchdog kills the run (write to address 0, +0x23cf683), print every other thread's stack once, to show what the frame loop was stuck in.
  • LARP_TITLE_WATCHDOG=0 (off by default; ported from VIctory-NVIDIA aee4c45a): sets the watchdog's quit flag (bit 0 of the byte at title+0x71b6340) every half second, only on build 1.0.2.1 and only when the trap bytes at +0x23cf683 match. A 30 s stall that larp does not already feed the heartbeat for is then not ended as a crash. It is opt-in because a real hang then stays a hang. On any other build it prints that it left the watchdog alone.
  • Docs for both switches (environment-variables.md, and the +0x2215c35 / +0x23cf683 entry in troubleshooting-and-crashes.md).

Dependencies

  • None on (a) or (b).
  • With no switch set, the only behaviour change is the LARP_STACKS walk itself (and the crash handler's walk stopping at an off-stack frame register). Both only run when something is already dumping stacks or crashing.

Testing

  • Cross-built for x86_64-pc-windows-msvc. Same warning set as current main.
  • cargo test --release --workspace under Wine: everything passes except the one test that also fails on main (larp-game prompts::font::...within_its_advance).
  • LARP_STACKS stall-dump sanity run: in progress, not finished. I have not yet completed a 120 s run with LARP_STACKS=60,120 on Windows with this branch. Plan (results will be posted as a comment on this PR):
    • LARP_STACKS=60,120: start, keep the process running past 120 s (title screen is enough), confirm stderr contains larp: stacks of N threads twice, and that the game kept running afterwards.
    • Close through the game window (WM_CLOSE on the larp class window).
    • Optional: LARP_TITLE_WATCHDOG=0 shows the "told to quit" line on 1.0.2.1.
    • LARP_STACKS_AT_KILL=1 only prints when the 30 s watchdog really fires, so it cannot be checked on demand.
**@⁠kadiratesdev** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/gamingwithhomie/larp/pull/140) `kadiratesdev:pr/split-c-stacks` → `main` · +266 −14 · 7 files · 4 commits · merged 2026-12-06 00:07 UTC This is part (c) of the split @⁠gamingwithhomie asked for on #77. It is independent of part (b) (diagnostics, #126) and part (a) (Agility/d3d12.dll loader). It touches no file those two touch, except the docs tables (separate rows, merged cleanly with both in a local trial merge). Based on the same `main` as #126 (334be94). Per the review, **do not merge before a `LARP_STACKS` stall-dump sanity run** on a real machine: the stack walk is the part I have not been able to exercise in-game (see Testing). ## What is in it - **Stack walks unwind a copy** (ported from VIctory-NVIDIA 43e89ba1). `LARP_STACKS` walked each suspended thread's live stack with `RtlVirtualUnwind`, which reads through a frame register that can hold anything where the thread was stopped, or through stack pages the thread never committed. In VIctory-NVIDIA that ended the process with an access violation inside ntdll. - `frames_of` now copies the stack (from `rsp` up, at most 512 KiB, zeros after) with `ReadProcessMemory` while the thread is suspended, resumes it, and unwinds the copy (`crash::unwind_copy`). - `unwind_into`, the crash handler's live walk, stops where a frame register lies outside the thread's stack. - Same output format as before. - **`LARP_STACKS_AT_KILL=1`** (off by default; ported from VIctory-NVIDIA c6d5c4d7): when the title's 30 s watchdog kills the run (write to address 0, `+0x23cf683`), print every other thread's stack once, to show what the frame loop was stuck in. - **`LARP_TITLE_WATCHDOG=0`** (off by default; ported from VIctory-NVIDIA aee4c45a): sets the watchdog's quit flag (bit 0 of the byte at title+0x71b6340) every half second, only on build 1.0.2.1 and only when the trap bytes at `+0x23cf683` match. A 30 s stall that larp does not already feed the heartbeat for is then not ended as a crash. It is opt-in because a real hang then stays a hang. On any other build it prints that it left the watchdog alone. - Docs for both switches (`environment-variables.md`, and the `+0x2215c35` / `+0x23cf683` entry in `troubleshooting-and-crashes.md`). ## Dependencies - None on (a) or (b). - With no switch set, the only behaviour change is the `LARP_STACKS` walk itself (and the crash handler's walk stopping at an off-stack frame register). Both only run when something is already dumping stacks or crashing. ## Testing - Cross-built for `x86_64-pc-windows-msvc`. Same warning set as current `main`. - `cargo test --release --workspace` under Wine: everything passes except the one test that also fails on `main` (`larp-game prompts::font::...within_its_advance`). - **`LARP_STACKS` stall-dump sanity run: in progress, not finished.** I have not yet completed a 120 s run with `LARP_STACKS=60,120` on Windows with this branch. Plan (results will be posted as a comment on this PR): - [ ] `LARP_STACKS=60,120`: start, keep the process running past 120 s (title screen is enough), confirm stderr contains `larp: stacks of N threads` twice, and that the game kept running afterwards. - [ ] Close through the game window (`WM_CLOSE` on the `larp` class window). - [ ] Optional: `LARP_TITLE_WATCHDOG=0` shows the "told to quit" line on 1.0.2.1. - `LARP_STACKS_AT_KILL=1` only prints when the 30 s watchdog really fires, so it cannot be checked on demand.
LARP_STACKS walked each suspended thread's live stack with RtlVirtualUnwind,
which reads through a frame register that can hold anything where the
thread was stopped, or stack pages the thread never committed: in
VIctory-NVIDIA the same walk ended the process with an access violation
inside ntdll (its sampling profiler, 43e89ba1).

frames_of now copies the stack (from rsp up, at most 512 KiB, zeros after)
with ReadProcessMemory while the thread is suspended, resumes it, and
unwinds the copy (crash::unwind_copy). unwind_into, the crash handler's
live walk, stops where a frame register lies outside the thread's stack.
Ported from VIctory-NVIDIA 43e89ba1.
The title's watchdog ends a run whose frame loop stopped for 30 s by
writing to address 0 (+0x23cf683, docs/troubleshooting-and-crashes.md).
The first-chance report names only the watchdog thread; with the switch
the first such write also dumps every other thread's stack, to name what
the frame loop was stuck in. Off by default. Ported from VIctory-NVIDIA
c6d5c4d7 (there diagnostics-only; larp's dump_stacks is in every build).
The watchdog's quit flag (bit 0 at title+0x71b6340) is set every half
second, only on 1.0.2.1 and only when the trap bytes are where they were
found. larp already feeds the heartbeat while draws wait for pipelines;
this covers stalls outside those waits. Opt-in. Ported from VIctory-NVIDIA
aee4c45a (default-on there).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 19:32:09 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-12-05 19:31 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/gamingwithhomie/larp/pull/140#pullrequestreview-6205473345) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠gamingwithhomie on GitHub · 2026-12-05 20:43 UTC · original

Holding per your own note (needs a real LARP_STACKS stall-dump sanity run first). Post that run and we will test-merge part (c). Parts (b) #126 is already merged. Thank you!

**@⁠gamingwithhomie** on GitHub · 2026-12-05 20:43 UTC · [original](https://github.com/gamingwithhomie/larp/pull/140#issuecomment-7445050851) Holding per your own note (needs a real `LARP_STACKS` stall-dump sanity run first). Post that run and we will test-merge part (c). Parts (b) #126 is already merged. Thank you!
Author
Owner

@⁠kadiratesdev on GitHub · 2026-12-05 22:43 UTC · original

LARP_STACKS stall-dump run, RTX 3080 Ti (driver 621.47), Windows 11 build 26300. This PR's head 35d5c01, cross-built release, run from a scratch copy of bin with a scratch LARP_DATA_DIR. Both runs used run <game> --execute --console series-s -- -skipToIIS and were closed through the window (SC_CLOSE, exit code 0).

1. Stall-triggered dump (normal release build, no diagnostics feature), LARP_STALL_S=1

  • During loading (shader pipelines being made), the stall observer reported no frame begun for 1 s (frame 12070) with 7 threads of ours in PipelineMake.
  • At 3 s it printed stall: ...; every thread's stack follows (said once) and larp: stacks of 141 threads: 1535 frames in total.
  • Every thread was unwound, including the title's: 214 frames in the title executable's image (larp-image-<hash>.dll+rva), 53 threads started there, plus larp-c.exe, ntdll, nvwgf2umx/nvgpucomp64 and D3D12Core.
  • Exactly one dump for the run, as documented. An earlier 1 s stall at frame 1 did not dump.
  • The title went on afterwards: the DLSS feature was made 4 s later and it kept presenting until I closed it.

2. Scheduled dumps (--features diagnostics build of the same commit), LARP_STACKS=60,120

  • Two dumps, about 61 s and 121 s after process start: larp: stacks of 140 threads each, with 1268 and 1180 frames. The first has 241 frames in the title image.
  • In the first dump, every thread has at least one frame.
  • The title kept running at 60 fps after the second dump. The last report before closing showed a median of 16.7 ms between presents, 99th percentile 17.1 ms, longest 37.5 ms.
  • One note: the dump goes to stderr, and tracing lines from other threads can land in the middle of it (they did in the second dump). Grepping by thread still works.

Not tested: LARP_STACKS_AT_KILL=1 (no watchdog kill happened), LARP_TITLE_WATCHDOG=0, a real long hang in gameplay, Wine/Proton, and AMD. Each run lasted 2 to 4 minutes, up to the title's first screens.

**@⁠kadiratesdev** on GitHub · 2026-12-05 22:43 UTC · [original](https://github.com/gamingwithhomie/larp/pull/140#issuecomment-7447005843) `LARP_STACKS` stall-dump run, RTX 3080 Ti (driver 621.47), Windows 11 build 26300. This PR's head 35d5c01, cross-built release, run from a scratch copy of `bin` with a scratch `LARP_DATA_DIR`. Both runs used `run <game> --execute --console series-s -- -skipToIIS` and were closed through the window (`SC_CLOSE`, exit code 0). **1. Stall-triggered dump (normal release build, no `diagnostics` feature), `LARP_STALL_S=1`** - During loading (shader pipelines being made), the stall observer reported `no frame begun for 1 s (frame 12070)` with 7 threads of ours in `PipelineMake`. - At 3 s it printed `stall: ...; every thread's stack follows (said once)` and `larp: stacks of 141 threads`: 1535 frames in total. - Every thread was unwound, including the title's: 214 frames in the title executable's image (`larp-image-<hash>.dll+rva`), 53 threads started there, plus `larp-c.exe`, `ntdll`, `nvwgf2umx`/`nvgpucomp64` and `D3D12Core`. - Exactly one dump for the run, as documented. An earlier 1 s stall at frame 1 did not dump. - The title went on afterwards: the DLSS feature was made 4 s later and it kept presenting until I closed it. **2. Scheduled dumps (`--features diagnostics` build of the same commit), `LARP_STACKS=60,120`** - Two dumps, about 61 s and 121 s after process start: `larp: stacks of 140 threads` each, with 1268 and 1180 frames. The first has 241 frames in the title image. - In the first dump, every thread has at least one frame. - The title kept running at 60 fps after the second dump. The last report before closing showed a median of 16.7 ms between presents, 99th percentile 17.1 ms, longest 37.5 ms. - One note: the dump goes to stderr, and tracing lines from other threads can land in the middle of it (they did in the second dump). Grepping by thread still works. Not tested: `LARP_STACKS_AT_KILL=1` (no watchdog kill happened), `LARP_TITLE_WATCHDOG=0`, a real long hang in gameplay, Wine/Proton, and AMD. Each run lasted 2 to 4 minutes, up to the title's first screens.
github-bot changed target branch from main to gh-pr/140/base 2026-12-06 00:27:02 +00:00
github-bot referenced this pull request from a commit 2026-12-06 01:25:33 +00:00
github manually merged commit 35d5c01853 into gh-pr/140/base 2026-12-06 01:25:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.