startup: return the debugger's exit code from run.ps1 #1596
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1603"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T14:47:59Z.
Change
tools/startup/run.ps1never read$LASTEXITCODE, so it exited 0 whatevertools/startup/debug_launch.pyreturned. A caller or wrapper saw success when the debugger printedCreateProcess failed <error>and returned 2. Under PowerShell 7 the same held when the debugger ended with an uncaught Python exception.run.ps1now stores$LASTEXITCODEright after the debugger call, prints the first five lines of<LogDir>.outas before, and ends withexit $debuggerExit. Two added lines; parameters, environment switches and the debugger call itself are unchanged.tests/startup_run_ps1_check.py(cteststartup_run_ps1, registered next tostartup_triage_run; also added as one line aftertests/startup_triage_run_check.py \in the singletools/run_checks_parallel.pycommand of the platform-independent Python job). On Windows it copiesrun.ps1into a temporary tree whosedebug_launch.pyis a stub, with empty placeholder files for the eight stand-in DLLs and the executable, and runs it under every PowerShell found (powershellandpwsh). For stub exit codes 2, 0 and 7 it checks the script's exit code, that exactly the first five of the stub's seven lines are printed, that<LogDir>.outholds all seven, and that the debugger received<exe> <datadir> <logdir> --timeout 9 --memory-gib 3 --trace-files 1 --continue-asserts 4. On a host other than Windows, without a PowerShell, or with--text-only, it checks the text after the debugger call instead (a$LASTEXITCODEcapture, the log head, a finalexitof that variable). The call is found as the one statement that namesdebug_launch.py, however the interpreter is spelled. Three mutated copies of the script (no capture and no exit, a fixedexit 2, exit before the log head) must fail in whichever mode runs.docs/startup-runtime.mdgets one paragraph with the exit status and the check command.Not changed:
debug_launch.py. It returns 2 when the process cannot be created and 0 after a run it reported on, whatever the process did, sorun.ps1still exits 0 for such a run.Verification
Environment: Windows 11, Windows PowerShell 5.1.26100.9818, PowerShell 7.7.0, Python 3.14.5, base
a3ac47a9. The realdebug_launch.pywas never started; every run used a stub.Before (unmodified
run.ps1, stubimport sys; print("stub: CreateProcess failed 193"); sys.exit(2), run from the scratch tree):pwsh -NoProfile -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg7 -BuildDir bld: printsstub: CreateProcess failed 193, exit code 0.powershell -NoProfile -ExecutionPolicy Bypass -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg5 -BuildDir bld: same line, exit code 0.After (same commands): both print the same line and exit 2. Inside a session,
pwsh -NoProfile -Command "& ./tools/startup/run.ps1 ...; 'after=' + $LASTEXITCODE"printsafter=2in both shells, soexitends only the script; the same holds for.\tools\startup\run.ps1 ...and for a dot-sourced call. With-Commandand the script as the last statement, the host exits 1 (0 before).Checks after the change:
out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py:startup run.ps1 exit code: 0 failed (executed with powershell, pwsh), about 10 s.out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py --text-only:startup run.ps1 exit code: 0 failed (text only: requested). WithPATHreduced to the Python directory:0 failed (text only: no PowerShell found).cmake --preset dev -B out/build/dev -DINTAKE_PYTHON=<venv python>, thenctest --test-dir out/build/dev --no-tests=error -R "^startup_(run_ps1|triage_run)$": 2 of 2 passed (startup_run_ps111.24 s).[System.Management.Automation.Language.Parser]::ParseFileon the editedrun.ps1: 0 errors in both shells. The file keeps CRLF line endings, no byte order mark, ASCII only;git diff --statshows 2 insertions.tests/startup_triage_run_check.py:0 failed.tests/dev_ps1_sccache_check.py:ok (executed with pwsh).tests/docs_links_check.py: 16 Markdown files, 347 links.tests/bidi_controls_check.py: 1260 files, no bidirectional controls.ast.parse(source, feature_version=(3, 11))accepts the new check.Negative control 1, the new check on
run.ps1fromorigin/main:With
--text-only:FAIL text: the statement after the debugger call does not store $LASTEXITCODE, exit code 1. Only the exit code fails there: the log head,<LogDir>.outand the argument list already pass on the old script.Negative control 2, edited scratch copies of the fixed script:
exitline removed, orexit 0: the same fourexited 0failures; text mode:the script does not end with 'exit $debuggerExit'.exit 2:stub debugger exited 0, run.ps1 exited 2andstub debugger exited 7, run.ps1 exited 2in both shells.exitmoved beforeGet-Content:printed [] instead of the first 5 debugger linesfor all three codes in both shells.-TotalCount 3:printed ['stub debugger line 1', 'stub debugger line 2', 'stub debugger line 3'] instead of the first 5 debugger lines.Rebased onto
origin/mainata3ac47a9before opening this pull request and re-run there:tests/startup_run_ps1_check.py0 failed (executed with powershell, pwsh);tests/docs_links_check.py(16 Markdown files, 347 links) andtests/bidi_controls_check.py(1260 files) pass;tools/run_checks_parallel.py tests/startup_triage_run_check.py tests/startup_run_ps1_check.py tests/run_checks_parallel_check.pyall 3 checks passed; the check onrun.ps1fromorigin/mainfails with 4 failures (exited 0for stub exit codes 2 and 7 in both shells); on a trial merge with #1535 the check reports0 failedin both modes.Not run: the real
debug_launch.py(it starts a process under a debugger); a CMake build and the full test suite; the check on a real Linux or macOS host (the text mode was only run on Windows, on the CRLF file and on an LF-only copy of its text); Python 3.11 and 3.12 (syntax only, see above).Evidence and follow-up
Refs #1149 (a specific untested launcher behavior with a device-free control: the stub debugger).
& $python, the repository environment's interpreter when present) anddocs/startup-runtime.md; it does not touch the exit status. A trial merge of its head48a04876with this branch (git merge-tree --write-tree, ona3ac47a9) is textually clean. On the mergedrun.ps1the check passes in both modes (0 failed (executed with powershell, pwsh)and0 failed (text only: requested)), and each of the three mutants is still reported by the text mode and by both shells. On #1535's ownrun.ps1, without this change, the check fails the same way as onorigin/main.run.ps1(it adds arguments) and does not touch the exit status. A trial merge of its headad94c950with this branch conflicts inrun.ps1and inCMakeLists.txt(the test registration;docs/startup-runtime.mdand.github/workflows/windows.ymlmerge automatically): the two lines added here sit directly after the line it changes, so whichever lands second resolves a small conflict in each file. On a scratch copy of itsrun.ps1with these two lines added by hand, the check passes in both modes and the three mutants are reported; without-MapDrivethe debugger still receives exactly the argument list the check expects, under both shells..github/workflows/windows.yml: the open pull requests #1173 and #836 also edit it; trial merges of their heads (97a524a6,4b253aca) with this branch are textually clean.CMakeLists.txtanddocs/startup-runtime.mdare edited by many open PRs; the hunks here are 2 and 6 lines.startup_triage_runis not in theprtest preset, sostartup_run_ps1is not either. On pull requests only the text mode in the Linux job runs; the executing mode runs with the full Windows suite. Adding it to theprfilter needs no build target; the test took about 10 s on this PC.$ErrorActionPreference = "Stop"with*>turns the debugger's first stderr line into a terminatingNativeCommandError. With a stub that prints one line and raises, Windows PowerShell 5.1 exits 1 without printing the log head, before and after this change (4 of 4 runs each). PowerShell 7 prints the log head and exited 0 before, 1 after.AI-assisted.