Repository navigation
WIP: fix(traps): skip the function epilogue's trap restores on the fatal -e unwind (DEBUG over-report, Refs #2546) - #2548
Merged
Conversation
…e unwind Refs #2546 (regression introduced by #2506) Root cause: #2506 taught the EXIT-trap window that commands inside the action take DEBUG re-presentation firings (correct for an ARMED trap: GNU execute_cmd.c:4506 calls run_debug_trap unconditionally for simple commands, and the running_trap gate at :4498 covers only the the_printed_command_except_trap refresh). But the funnel then consulted a trap table rubash had already re-armed: the function epilogue restored the entry-saved DEBUG action unconditionally, while GNU restores it via the uw_maybe_set_debug_trap unwind protect (execute_cmd.c:5276, registered next to uw_maybe_set_error_trap at :5286 and uw_maybe_set_return_trap at :5301) — and the fatal ExitCode/LastpipeExit unwind under live errexit longjmps past every one of those protects. The EXIT action therefore executes in the dying scope, where an untraced function had disarmed the DEBUG trap at entry (execute_cmd.c:5278 restore_default_signal), so run_debug_trap (trap.c:1275, `sigmodes[DEBUG_TRAP] & SIG_TRAPPED`) never fires — GNU prints no DEBUG record for the failing command. The frame-stack half of the same protect skip was already modeled (#2506's leaked frames, gated on exit_unwind); the trap-table half was missed, so master printed one extra `DEBUG cmd=[echo ${u2482bad}]`. Fix: hoist the epilogue's existing exit_unwind condition (Err(ExitCode | LastpipeExit) && errexit_enabled, the #2506 frame-leak gate) above the restores and skip the DEBUG/ERR/RETURN restores on that path — one invariant for the whole protect family, not a print-surface patch. With `-e` off the DISCARD unwind still runs the protects (sig.c:387 top_level_cleanup -> run_unwind_protects) and the restore rightly happens, so the action's first command keeps its re-presentation firing. Verification (WSL GNU bash 5.3.20 oracle, script files): - Both issue forms (p2482b function action, p2482c string action): stdout+stderr+exit byte-identical, extra DEBUG line gone. - Counting-law matrix 10/10 byte-identical: success/failure x function/top-level x DEBUG/EXIT/RETURN x functrace x -e off x nested x exit-builtin; the armed cells (top-level failure, functrace, -e off, success baseline) keep every re-presentation firing. - tests/issue2546_debug_overreport.rs 12/12; #2506 pins stay green (issue2482_trap_unwind_stack 8/8, issue2482_err_trap_pipeline 8/8, issue2212_bats_remainder_regressions 14/14); trap family (37 files) and cargo test --lib match pristine master exactly (the 6 trap-family and 2 lib failures reproduce on clean master).
Member
Author
|
[win-acceptance] #2548 PASS — new pin Environment: Windows 10 19045 real machine, MSVC Rust debug build of master 2ce27e6 (contains this merge), oracle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP: fix(traps): skip the function epilogue's trap restores on the fatal -e unwind
Refs #2546 (regression introduced by #2506) — do not merge while draft
Symptom
set -eu+ armed DEBUG/EXIT traps + nounset failure inside an untraced function printed one extra DEBUG record (DEBUG cmd=[echo ${u2482bad}]) that GNU bash 5.3.20 does not print — both issue forms (function-valued EXIT actionp2482b.sh, string-valuedp2482c.sh). pre-#2506 (d529b35) matched GNU byte-for-byte.Root cause (GNU C citations)
execute_cmd.c:5270-5278 execute_function: an untraced function body runs with the DEBUG trap disarmed (restore_default_signal (DEBUG_TRAP)clearsSIG_TRAPPED); the restore is registered as the unwind protectuw_maybe_set_debug_trap(trap.c:756), alongsideuw_maybe_set_error_trap(:5286) anduw_maybe_set_return_trap(:5301).uw_restore_funcarray_stateframe pops) — so the EXIT action executes in the dying scope, where DEBUG is still disarmed, andrun_debug_trap(trap.c:1275,sigmodes[DEBUG_TRAP] & SIG_TRAPPEDgate) never fires for the action's commands.src/executor/function_calls.rs) restored the entry-saved DEBUG (and ERR/RETURN) actions unconditionally, re-arming the trap before the EXIT funnel; WIP: fix(traps): #2482 fatal-unwind stack + ERR-in-pipeline (faces a/b); #2483/#2484 analysis #2506's (correct) re-presentation firing for in-action commands then over-reported by one line per dying untraced frame chain.The frame-stack half of the protect skip was already gated (
exit_unwind); the trap-table half was missed. This PR hoists that same gate above the three restores — one invariant for the whole protect family, no print-surface patch. With-eoff the DISCARD unwind runs the protects (sig.c:387 top_level_cleanup), the restores correctly happen, and the action's first command keeps its re-presentation firing.A/B (WSL GNU bash 5.3.20 oracle, script files, stdout+stderr+exit)
-eoff (DISCARD,set -u)exitbuiltin in fnVerification
FN=f).tests/issue2546_debug_overreport.rs: 12/12 — both issue forms + the "+0 counting law" matrix with explicit DEBUG-line counts.issue2482_trap_unwind_stack8/8,issue2482_err_trap_pipeline8/8,issue2212_bats_remainder_regressions14/14 (incl. issue2212_13 re-presentation pin).9348b8d9(pre-existing: issue85/86/290 trio, issue524 sourced-exit, issue797 preexec transcript, issue_1511).cargo test --lib: 1126/2 — both failures identical on pristine master.fmt disclosure (the os-206 pitfall)
Whole-crate
cargo fmt --checkfails on this machine in every checkout (incl. pristine master): cargo-fmt feeds the crate's ~900 test targets to rustfmt in one command line and CreateProcess fails with os error 206 — and independently, master already carries rustfmt drift in files this PR does not touch (src/debugger/wiring_tests.rs,src/executor/assignment_expansion.rs, ...). Per the crew protocol (206 pitfall → per-file + disclosure): both files in this PR were formatted and verified clean with per-filerustfmt --check --edition 2021(exit 0), and the commit went through the pre-commit hook's owncargo not founddegradation branch. No--no-verifywas used.