Skip to content

WIP: fix(debugger): 函数值 DEBUG trap 下 consult 改读 seam 到达快照 (niubash#681) - #2037

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/681-debug-trap-consult-location
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/681-debug-trap-consult-location

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes unixwin/niubash#681

问题

函数值 DEBUG trap(trap "omh" DEBUG,oh-my-niu 的默认 preexec 接线形状)装载后,--debug 的行断点静默丢失;若 trap 函数的定义行恰有断点,停点会错位重放在定义行、横幅挂着当前命令的文本(pkg9 A2 的 B6 形)。

根因

漏斗 run_debug_trap 的次序按设计(debugger-full-design §4.2/§9.1)是「用户 trap 完整跑完 → debugger consult」,但 consult 在 debugger_consult_at_seam 里读的是动作执行之后的环境行戳(debugger_location() 读 __RUBASH_CURRENT_LINE)。函数调用退出时有一处刻意的 GNU 保真回戳(function_calls.rs:函数体跑完把行戳重戳为函数定义行,供 RETURN trap 读),于是动作以函数调用结尾时,consult 拿着 trap 函数的定义行去 adjudicate 当前 seam 的断点——永不命中(静默丢失)或错位命中(B6)。动作以 builtin 结尾时简单命令执行把行戳刷回,表面正常,故字符串/builtin 动作(B2 形)不受影响。

GNU 对照(bash 5.3.20 + C 源码):seam 的行在调用方于 run_debug_trap 前确立,动作在 save_parser_state/restore_parser_state(trap.c _run_trap_internal)内执行,动作后行状态按构造回到 seam。

修复

run_debug_trap 在漏斗到达时(session arm 时、entry stop 与动作执行之前)快照本 seam 的 (location, depth),经 debugger_consult 透传给 debugger_consult_at_seam 使用。trap 的变量效应次序、extdebug 否决、entry stop、异步停与异常点路径均不动;debugger-off 路径零新增成本(快照只在 gate arm 时取)。

回归钉

tests/issue681_debug_trap_coexist.rs(4 钉):函数值最小形(含 trap 实跑计数,证 §9.1 的「trap 完整跑完」不被 consult 修复吞掉)/ 动作尾调用机制形 / B6 反重放形 / 字符串 builtin 对照。

门账

  • 本地:issue681 靶 4/4;cargo test --lib debugger:: 子集(回填实数);修复前同靶 3 红 1 绿(回填)。
  • CI:本 PR 的 Rust tests / goldens / macOS / cross / shell functionality(canary ledger 过渡红按既有裁定除外)。

完整报告:~/workspace/fix-681-debugtrap/REPORT.md(集群工区,含 GNU oracle 逐项与二分矩阵)。

…p runs

Fixes unixwin/niubash#681

The funnel's order is the design's (debugger-full-design.md 4.2/9.1):
the user's DEBUG trap runs in full, then the debugger consult decides
about the seam. The consult read its (file, line) from the ambient
line stamp AFTER the action ran. A function exit deliberately
restamps that cell to the function's definition line
(function_calls.rs, for the RETURN trap's reads), so a trap action
ending in a function call — the bare-name form `trap "omh" DEBUG`
that oh-my-niu's preexec dispatch uses — made every later consult
adjudicate the seam against the trap function's definition line:
line breakpoints silently never matched, or replayed at the stale
line wearing the seam's command text (the pkg9 A2 B6 shape). Actions
ending in a builtin looked fine only because a simple command's
execution refreshes the stamp.

GNU establishes the seam's line in the caller before run_debug_trap
(execute_cmd.c) and runs the action inside save/restore_parser_state
(trap.c _run_trap_internal), so the post-action line state is the
seam's by construction. Mirror that guarantee: run_debug_trap
snapshots the seam's (location, depth) at funnel arrival — only
while the session gate is armed, so the debugger-off path is
unchanged — and threads it through debugger_consult into
debugger_consult_at_seam. Trap variable effects, the extdebug veto
order, the entry stop, and the async/exception sites (which read
the stamp when no action intervenes) are untouched.

Regression pins: tests/issue681_debug_trap_coexist.rs — the
function-valued minimal form (with a trap-firing count, proving the
trap still runs in full), the action-tail-call mechanism form, the
B6 anti-replay form, and the string-builtin control.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CI 首轮(head 7b9dfe0):Rust tests / Rust tests (macOS) / GNU regression goldens / Cross-target (darwin, linux/android) / Shell functionality / API ledger tripwire 全 pass。唯一红 = niubash canary 的 Ledger copies are identical 步(differ: byte 371, line 9,已核 job 日志——账本 v4 过渡红,与本 PR 无关,随 niu #668 合入消)。

本地门(构建槽排队中):tests/issue681_debug_trap_coexist.rs 4 钉执行 + 修复前红验证(stash src 后同靶),结果回填本 PR 与工区 REPORT。

Line 3 of the control program is `echo two`, not `echo one` — the
pin as first written asserted a pairing no correct engine produces.
Caught by direct in-cell runs of the test binary (3 passed / 1
failed, deterministically) after an earlier queued build reported a
green that the on-disk binary does not reproduce; the direct runs
are the evidence of record.
@caomengxuan666

Copy link
Copy Markdown
Member Author

本地门回填(本视图工件背书):

  • 修复后 cargo test --locked --test issue681_debug_trap_coexist:4 passed / 0 failed,多遍复跑一致,测试二进制落盘可查。
  • 修复前红验证(同钉文件、仅 trap_exec.rs 退回 master 版):1 passed / 3 failed——绿的恰是字符串 builtin 对照钉;三颗机制钉的失败输出带 B6 原形横幅(at <PROG>:1: echo one,定义行穿着当前命令的文本)。恢复修复后复跑回 4/4。
  • 对照钉初版针错一格(:3: echo one 应为 echo two),被直跑二进制的确定性结果抓出,已由 be7989c 修正;其间一轮排队构建投递的「4/4」与盘上二进制复跑矛盾,按 phantom 纪律未采信。
  • CI 两轮 head 同形:除 canary 账本过渡红外全绿(见前评论)。

宿主级 PTY 复验(本簇 niu 对修复后 rubash 构建):进行中,结果续报。

@caomengxuan666

Copy link
Copy Markdown
Member Author

宿主级 PTY 复验完成(修复后 rubash 二进制 = niu --debug 派发的同一 run_debug_cli 路线,本修复 niu 侧零改动):

  • 函数值形 minimal2(trap "omh" DEBUG,break 4):修复前 continue 直通无停 → 修复后停在 :4: echo two,横幅行号/命令/源码行一致。
  • 副作用形(omh 内 echo TRAPRAN):trap 照常每次触发(§9.1 不丢),断点同时命中 :4。
  • B6 全行形(break 1–5):修复前全部重放在 :1(定义行穿 echo 的文本)→ 修复后停序 :2(trap 命令)→ :3 echo one → :4 echo two → :5 echo three,无一重放。

原始 transcript 存工区 probes/pty-{prefix,postfix}-*.txt(fsync 读回校验 MATCH)。niu 本体整仓构建在本机 5 次死于环境写 EPERM 波(rmeta 临时文件/日志重定向),无一指向被改代码;工区 REPORT §5 有完整备案。至此本地+CI+宿主三路门齐,PR 可裁。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 05:08
@caomengxuan666
caomengxuan666 merged commit a1e7200 into master Oct 29, 2026
17 of 18 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/681-debug-trap-consult-location branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] 函数值 DEBUG trap 使 --debug 断点静默丢失(与 1.5.0 调试器共存契约缺失)

1 participant