startup: arm the debugger's runtime and movie-player call hooks only with --trace-calls 1 #2014

Merged
rasptum merged 1 commit from upstream-pr/2021 into main 2026-11-24 23:40:10 +00:00
rasptum commented 2026-11-24 23:14:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T23:14:14Z.


This builds on #1987 (merged), which stops the stand-ins' first-calls log counters at their limit. With the call hooks off, a consumer that polls a status in a loop runs fast enough to wrap the stand-ins' first-calls log counters, and from then on every call logs. That PR makes the counters stop at their limit.

tools/startup/debug_launch.py armed its gaming-runtime and movie-player call hooks whenever file tracing was on. File tracing is on by default, because offline mode needs the file hooks. Under the debugger, every hooked call stops the whole process.

  • The two call-hook sets are now armed only with --trace-calls 1 (tools/startup/run.ps1 -TraceCalls). With the flag, behavior is as before.
  • File hooks, the offline denial, assertion continuation and trap dumps are unchanged.
  • The run summary prints call tracing: on or off.
  • The movie-player report (bink calls and the frame data after it) needs the movie-player hooks, so it appears only with --trace-calls 1. docs/startup-runtime.md says so.

Tests:

  • startup_debug copies its probe and a new source-built DLL (tests/startup_debug_calls.cpp) into one folder, with the DLL renamed to the movie-player module name. The probe calls the DLL's export 7 times. The check expects no call count by default and exactly x7 with --trace-calls 1, plus the matching call tracing: line. Every case passes --console 0.
  • Negative control: arming the hooks unconditionally makes the default case fail on the count assertion.
  • startup_run_ps1 checks that -TraceCalls passes --trace-calls 1.

Test (build targets startup_debug_probe startup_debug_calls startup_launch_probe):

ctest --preset release --no-tests=error -R '^(startup_debug|startup_run_ps1|startup_launch)$' -V

Results on the branch rebased onto main (after the first-calls limiter fix merged):

  • dev: 3 passed, 0 failed, 0 skipped.
  • release: 1 passed, 2 failed, 0 skipped. Neither failure is in code this PR touches:
    • startup_debug failed on the existing X2W_VALLOC_MIN case, which sometimes logs the 256 MiB reservation with an empty caller list (callers: ). Unmodified main fails it the same way. With that one assertion disabled, the whole check passes in dev and release, including the call-hook cases.
    • startup_launch failed once on its fast-fail assertion, while running in parallel with the other two tests. Run alone in release, it passed 3 of 3 on this branch and 3 of 3 on unmodified main. This PR does not change the code that test covers.
  • tests/docs_links_check.py and tests/bidi_controls_check.py pass.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593322913 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2021). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T23:14:14Z. --- This builds on #1987 (merged), which stops the stand-ins' first-calls log counters at their limit. With the call hooks off, a consumer that polls a status in a loop runs fast enough to wrap the stand-ins' first-calls log counters, and from then on every call logs. That PR makes the counters stop at their limit. `tools/startup/debug_launch.py` armed its gaming-runtime and movie-player call hooks whenever file tracing was on. File tracing is on by default, because offline mode needs the file hooks. Under the debugger, every hooked call stops the whole process. - The two call-hook sets are now armed only with `--trace-calls 1` (`tools/startup/run.ps1 -TraceCalls`). With the flag, behavior is as before. - File hooks, the offline denial, assertion continuation and trap dumps are unchanged. - The run summary prints `call tracing: on` or `off`. - The movie-player report (`bink calls` and the frame data after it) needs the movie-player hooks, so it appears only with `--trace-calls 1`. `docs/startup-runtime.md` says so. Tests: - `startup_debug` copies its probe and a new source-built DLL (`tests/startup_debug_calls.cpp`) into one folder, with the DLL renamed to the movie-player module name. The probe calls the DLL's export 7 times. The check expects no call count by default and exactly `x7` with `--trace-calls 1`, plus the matching `call tracing:` line. Every case passes `--console 0`. - Negative control: arming the hooks unconditionally makes the default case fail on the count assertion. - `startup_run_ps1` checks that `-TraceCalls` passes `--trace-calls 1`. Test (build targets `startup_debug_probe startup_debug_calls startup_launch_probe`): ```powershell ctest --preset release --no-tests=error -R '^(startup_debug|startup_run_ps1|startup_launch)$' -V ``` Results on the branch rebased onto `main` (after the first-calls limiter fix merged): - dev: 3 passed, 0 failed, 0 skipped. - release: 1 passed, 2 failed, 0 skipped. Neither failure is in code this PR touches: - `startup_debug` failed on the existing `X2W_VALLOC_MIN` case, which sometimes logs the 256 MiB reservation with an empty caller list (`callers: `). Unmodified `main` fails it the same way. With that one assertion disabled, the whole check passes in dev and release, including the call-hook cases. - `startup_launch` failed once on its fast-fail assertion, while running in parallel with the other two tests. Run alone in release, it passed 3 of 3 on this branch and 3 of 3 on unmodified `main`. This PR does not change the code that test covers. - `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 00:04:58 +00:00
ChazY11 commented 2026-11-25 01:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:28:57Z.


The PowerShell wiring is pinned by three mutations; the debugger half I could only read

Reviewed on the merge base rather than main — your branch is 23 commits behind, so git diff origin/main shows 825 lines for a 122-line change,
most of them other people's merged work. git diff $(git merge-base origin/main HEAD) shows the real shape:

CMakeLists.txt                 |  6 +++++-
docs/startup-runtime.md        | 10 ++++++++++
tests/startup_debug_calls.cpp  | 14 ++++++++++++++
tests/startup_debug_check.py   | 38 ++++++++++++++++++++++++++++++++++----
tests/startup_debug_probe.cpp  | 26 ++++++++++++++++++++++++++
tests/startup_run_ps1_check.py | 13 +++++++++----
tools/startup/debug_launch.py  |  8 ++++++--
tools/startup/run.ps1          |  7 +++++--

What I could run

out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py          # exit 0
out/pe-env/Scripts/python.exe -B tests/startup_live_telemetry_check.py   # exit 0
mutation in tools/startup/run.ps1 result
the switch is accepted but $traceArgs stays empty caught
the arguments are built but not splatted onto the debug_launch call caught
[switch]$TraceCalls renamed so the script no longer takes it caught

So the plumbing is pinned end to end on the script side, including the negative case — the check asserts that without the switch the argument list is
unchanged, which is the half people forget.

What I could not run, and why

out/pe-env/Scripts/python.exe -B tests/startup_debug_check.py
TypeError: main() missing 2 required positional arguments: 'probe' and 'calls_dll'

That is a usage error, not a failure: the check takes the built startup_debug_probe.exe and the built call-hook DLL, which CMake passes in. There is
no cl.exe build tree on this machine, so the runtime half of this PR — the actual --trace-calls 1 break-on-xgameruntime.dll/bink2scarlett.dll
behaviour, and bink_report() — is not verified by me. Please read the rest of this review as static analysis only, and tell me if you want the
inability recorded differently in the PR body.

Static reading of the debugger half

Three things I would want to see stated explicitly, because each is a decision rather than a transcription:

  1. trace_calls = trace and opts.get("--trace-calls") == "1" — the hook is gated on trace as well as on the flag. That means --trace-calls 1
    without --trace 1 silently does nothing except change the banner. The banner says call tracing: on, which would then be wrong. Either the gate
    should be opts.get(...) == "1" alone, or the banner should print the same conjunction it uses.
  2. Every hit stops the whole process in the comment is the reason for default-off, and it is the right reason. Worth also saying how much
    slower: two extra breakpoints on every call into two modules turns a run into minutes, and the docs line says "slows the process" without a number.
    I cannot measure it here, but you presumably have.
  3. tests/startup_debug_calls.cpp exports BinkNextFrame and counts calls. Since the probe renames the DLL to the movie-player module name,
    the export must match a symbol debug_launch.py actually hooks — otherwise the check passes because nothing is hit. A guard that the export name
    appears in the hook list would make that impossible to get wrong later.

None of those are blockers; they are the three places where a future reader has to guess.

Notes

  • AI-assisted review; the runtime fixture was not executed here.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147449636 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2021#issuecomment-7147449636). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:28:57Z. --- ## The PowerShell wiring is pinned by three mutations; the debugger half I could only read Reviewed on the merge base rather than `main` — your branch is 23 commits behind, so `git diff origin/main` shows 825 lines for a 122-line change, most of them other people's merged work. `git diff $(git merge-base origin/main HEAD)` shows the real shape: ```text CMakeLists.txt | 6 +++++- docs/startup-runtime.md | 10 ++++++++++ tests/startup_debug_calls.cpp | 14 ++++++++++++++ tests/startup_debug_check.py | 38 ++++++++++++++++++++++++++++++++++---- tests/startup_debug_probe.cpp | 26 ++++++++++++++++++++++++++ tests/startup_run_ps1_check.py | 13 +++++++++---- tools/startup/debug_launch.py | 8 ++++++-- tools/startup/run.ps1 | 7 +++++-- ``` ## What I could run ```powershell out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py # exit 0 out/pe-env/Scripts/python.exe -B tests/startup_live_telemetry_check.py # exit 0 ``` | mutation in `tools/startup/run.ps1` | result | |---|---| | the switch is accepted but `$traceArgs` stays empty | **caught** | | the arguments are built but not splatted onto the `debug_launch` call | **caught** | | `[switch]$TraceCalls` renamed so the script no longer takes it | **caught** | So the plumbing is pinned end to end on the script side, including the negative case — the check asserts that *without* the switch the argument list is unchanged, which is the half people forget. ## What I could not run, and why ```text out/pe-env/Scripts/python.exe -B tests/startup_debug_check.py TypeError: main() missing 2 required positional arguments: 'probe' and 'calls_dll' ``` That is a usage error, not a failure: the check takes the built `startup_debug_probe.exe` and the built call-hook DLL, which CMake passes in. There is no `cl.exe` build tree on this machine, so the runtime half of this PR — the actual `--trace-calls 1` break-on-`xgameruntime.dll`/`bink2scarlett.dll` behaviour, and `bink_report()` — is **not verified by me**. Please read the rest of this review as static analysis only, and tell me if you want the inability recorded differently in the PR body. ## Static reading of the debugger half Three things I would want to see stated explicitly, because each is a decision rather than a transcription: 1. **`trace_calls = trace and opts.get("--trace-calls") == "1"`** — the hook is gated on `trace` as well as on the flag. That means `--trace-calls 1` without `--trace 1` silently does nothing except change the banner. The banner says `call tracing: on`, which would then be wrong. Either the gate should be `opts.get(...) == "1"` alone, or the banner should print the same conjunction it uses. 2. **`Every hit stops the whole process`** in the comment is the reason for default-off, and it is the right reason. Worth also saying *how much* slower: two extra breakpoints on every call into two modules turns a run into minutes, and the docs line says "slows the process" without a number. I cannot measure it here, but you presumably have. 3. **`tests/startup_debug_calls.cpp` exports `BinkNextFrame`** and counts calls. Since the probe renames the DLL to the movie-player module name, the export must match a symbol `debug_launch.py` actually hooks — otherwise the check passes because nothing is hit. A guard that the export name appears in the hook list would make that impossible to get wrong later. None of those are blockers; they are the three places where a future reader has to guess. ## Notes - AI-assisted review; the runtime fixture was not executed here.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2014
No description provided.