Repository navigation
fix(trap): DEBUG/RETURN/ERR trap actions carry source-name context (Refs #3327) - #3657
Merged
Merged
Conversation
…efs #3327) GNU _run_trap_internal (trap.c:1196-1198) does NOT set SEVAL_RESETLINE for the DEBUG, RETURN, or ERR trap, so each action parses at the caller's current line, and parse_and_execute tags the action with the trap's source name ("debug trap" trap.c:1288, "error trap" trap.c:1324, "return trap" trap.c:1340). Rubash re-parsed the three actions at line 1 without the context name, and propagated the re-parse error out of the runner, aborting the script with rc=2 and context-free diagnostics. - Tokenize the action at the firing/failed line via tokenize_with_initial_posix_and_line (same funnel as plain tokenize except the line base; lexer/mod.rs:289-296). The EOF error's line is last-token-line + 1 (parse_loop.rs eof_line_extra), so a one-line action firing at line L reports `line L+1 ... on line L`, as GNU does. The post-parse rebases in the RETURN/ERR runners are subsumed and deleted; the DEBUG runner's cached-AST rebase stays, with the fresh-parse recorded base changed from 1 to the start line. - Mirror the EXIT runner's __RUBASH_TRAP_CONTEXT insert/restore around tokenize+parse+execute in all three runners, so the diagnostic carries the trap's source name (parser_error_prefix_for_line, public_accessors.rs:4036). - Contain a parse failure of the action (take_parse_error() + parser_error_errexited, same shape as the EXIT runner): the diagnostic stands, the pending status is preserved, and the script continues. An errexit-class parse error keeps propagating. Regression pin: tests/issue3327_trap_action_source_context.rs (7 cells: 4 diagnostic pins GNU-oracle-verified on bash 5.3.20 + 3 valid-action locks). 本 PR 删除了什么:无。删除了 RETURN/ERR runner 中已由 tokenize 时行锚 取代的 parse 后 shift_trap_action_lines 重定基调用(两处死代码路径, 行为由新 tokenize 行锚承接)。
…3327) CI run 43672182309: E0502 at trap_exec.rs:1908 — active_trap_action_ref borrows env_vars for the action, and the __RUBASH_TRAP_CONTEXT insert needs it mutably. Clone the action to an owned String first; no semantic change (DEBUG already owns its action via comsub_body_alias_splice, ERR via get_trap_action returning String).
… 1 (Refs #3327) CI bisection for the two bashdb head-only regressions on run 43673700641 (bashdb_continue_numeric_location_hits_function_source_line, function_debug_trap_runs_inside_functrace_function_body). Only the DEBUG runner's tokenize call reverts to plain tokenize() with recorded base 1 (pre-fix shape); the __RUBASH_TRAP_CONTEXT insert and the take_parse_error() containment are kept, RETURN/ERR untouched. If the two cells go green, the tokenize/start_line half is the culprit; if still red, it is the context/containment half.
DEBUG action keeps the bisected shape (plain tokenize, base 1 + per-firing shift_trap_action_lines rebase): tokenize-time start_line broke the debugger frame via the stale first_word_end_line stamp (bisection CI run 43676036833 proved it — both bashdb cells green once the tokenize half was reverted). shift_trap_action_lines now also rebases the parse-error diagnostic VALUES (EOF_COMPOUND / EOF_SUBSHELL / NEAR / HD_WARN assignments) by the same delta, in the same walk: they are parse-time data the node-line rebase cannot see, and they carry the firing-line diagnostic the #3327 pins assert (command_execute.rs:958-1005 renders them via parser_error_prefix_for_line). Values track ast_base exactly like node lines, so the DEBUG cache stays consistent across firings; malformed values are left untouched. RETURN/ERR untouched (fresh parse per firing; values already firing-line-based). GNU: trap.c _run_trap_internal (debug trap trap.c:1288, return trap trap.c:1340, error trap trap.c:1324); no SEVAL_RESETLINE for these three (trap.c:1196-1198). Refs #3327
This was referenced Nov 15, 2026
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:
续作记录:本轮未动代码(按分工,FAIL 只发报告)。 |
…e (Refs #3327) The ERR and RETURN runners tokenize the trap action anchored at the firing line (tokenize_with_initial_posix_and_line start_line) but left ParseLoopOptions::source_line_offset at 0. parse_loop.rs maps token positions back to diagnostic-text lines via position - offset and computes the compound-EOF physical line as offset + newline count + 1, so every unclosed-compound diagnostic inside a trap action reported the action-relative line instead of the caller-anchored one (GNU trap.c _run_trap_internal keeps the caller's line_number for these traps). Pass start_line - 1, matching the eval runner's contract. Also normalize the script path in the pin for the MSYS /c/... form rubash prints for Windows drive paths.
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无(F1/F2 已修,F3 已修,F4 见上)。 续作记录:
未跑/VOID 的腿:无。 |
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.
UNVERIFIED-BY-CAPTAIN
根因 (rubash#3327)
GNU
_run_trap_internal(trap.c:1196-1198) does NOT setSEVAL_RESETLINEfor the DEBUG, RETURN, or ERR trap, so each action parses at the caller's
current line, and
parse_and_executetags the action with the trap'ssource name: "debug trap" (trap.c:1288), "error trap" (trap.c:1324),
"return trap" (trap.c:1340). Rubash re-parsed the three actions at line 1
without the context name, and propagated the re-parse error out of the
runner, aborting the script with rc=2 and context-free diagnostics.
GNU oracle (bash 5.3.20, re-measured this lane): a one-line action
if true; then echo SHOULD_NOT_PRINTfiring at line L reportsline L+1: syntax error: unexpected end of file from \if' command online L
, prefixed: :; the diagnostic stands, the pending$?is preserved, and the script continues. RETURN inside a function needsset -T` (functrace); without it GNU does not fire the RETURN trapinside a function at all (execute_cmd.c:5293) — that is inheritance, not
a bug.
修复 (
src/executor/trap_exec.rs, +129/−29)__RUBASH_TRAP_CONTEXT="debug trap"/"return trap"/"error trap"around tokenize+parse+execute in allthree runners, restore after — same insert/restore shape as
run_exit_trap_actionand the signal runner. The EOF diagnostic isprinted at EXECUTE time from the AST's
__RUBASH_PARSE_ERROR__assignments (command_execute.rs:958-1005), so the context must span
execution, not just the parse. The prefix is produced by
parser_error_prefix_for_line(public_accessors.rs:4036).tokenize_with_initial_posix_and_line(&action, false, start_line)with start_line =call_line(DEBUG/RETURN) orfailed_line(ERR), falling back to 1. Both entry points funnel totokenize_comsub_body_with_origin(..., false, false)(lexer/mod.rs:289-296), so this is identical to plain
tokenizeexcept the line base. The EOF line is last-token-line + 1
(
eof_line_extra, parse_loop.rs:2981), so a one-line action firingat line L reports
line L+1 ... on line L, exactly as GNU. Thepost-parse rebases in the RETURN/ERR runners are subsumed and
deleted; the DEBUG runner's cached-AST rebase stays, with the
fresh-parse recorded base changed from 1 to the start line. (A
post-parse rebase cannot fix parse-time diagnostics: the EOF error
node is built at parse time. This is why the executor: port line_number_for_err_trap for ERR-trap LINENO (Refs #3553) #3602 rebase alone did
not fix DEBUG/RETURN/ERR trap 动作重解析同样未置源名上下文(debug/return/error trap) #3327.)
take_parse_error()+parser_error_errexited.take(); on the parse-error class (and NOTerrexited) restore the pending status and continue (DEBUG: fall
through with the saved status; RETURN/ERR: return Ok(())). The
parse-error arm precedes the ERR unwind arms (same order as the EXIT
runner's match): GNU never executes an action that failed to parse.
An errexit-class parse error keeps propagating.
回归钉
tests/issue3327_trap_action_source_context.rs(7 cells, #2716-harnessshape): 4 diagnostic pins (DEBUG 3 firings, ERR, RETURN functrace,
RETURN sourced — each asserting the full GNU diagnostic line, exact
stdout, exact rc) + 3 valid-action regression locks (DEBUG/RETURN/ERR
actions still run, status preserved). Pin expectations are GNU-oracle
verified; the pin has NOT been executed yet — see Legs.
Legs — UNRUN (blocked by the build memory gate)
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins: UNRUNrustfmt --checkon the 2 touched files: CLEAN. UTF-8 boundaryhygiene (
scripts/check-utf8-boundary-hygiene.sh): CLEAN.PRs touch
src/executor/trap_exec.rs(fix(executor): adopt respawn provenance via fd/pipe proof for subreaper orphans (Refs #3300) #3652, fix(executor): close orphaned stdio fd on persistent fd close; retire dead coproc at pipe read (Refs #3633) #3634, exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) #3603, fix(executor): redirect-only exec binds every heredoc entry (Refs #3578) #3580,fix(exec): hand the exec'd image the shell's whole descriptor set (Refs #3311 #3312 #3313) #3552, fix(executor): seed compound stdin procsub diagnostics with the ambient line (Refs #3299) #3482, fix(executor): let a live fd-0 File endpoint outrank the FUNCTION_STDIN mirror in exec spawns (Refs #3046) #3461, fix(executor): open existing FIFO redirect targets via the cwd anchor in a deleted cwd #3363) — zero hunks inside the three runners,
zero within 200 lines (nearest fix(exec): hand the exec'd image the shell's whole descriptor set (Refs #3311 #3312 #3313) #3552 @@ -3661, ~367 lines past the
ERR runner end). PROCEED, no exemption needed.
Memory gate: MemAvailable stayed 485–930MB across two 30-minute polls
(round 3 + round 4); the 1.5G build gate never opened, so no build ran.
Legs to be run by the captain/reviewer when a window opens (or on X299,
per the platform-independent-leg routing). Base: master af4e689; head:
658ab58. Fix shape re-derived against the post-#3602/post-#3483 tree
and re-verified unchanged across the 659bd39 → af4e689 tip move
(
git diffontrap_exec.rsover that range is empty).本 PR 删除了什么
无产品代码删除。删除了 RETURN/ERR runner 中已由 tokenize 时行锚取代
的 parse 后
shift_trap_action_lines重定基调用(两处死代码路径,行为由新 tokenize 行锚承接)。