词元之母TOK.MOM - 平台充值汇率 1:1 即 1 人民币充值到账 1 美元,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!
| 来源 | 内置(默认安装) |
| 路径 | skills/software-development/node-inspect-debugger |
| 版本 | 1.0.0 |
| 作者 | Hermes Agent |
| 许可证 | MIT |
| 平台 | linux, macos, windows |
| 标签 | debugging, nodejs, node-inspect, cdp, breakpoints, ui-tui |
| 相关 skill | systematic-debugging, python-debugpy, debugging-hermes-tui-commands |
console.log 不够用时,可以从终端以编程方式驱动 Node 内置的 V8 inspector。你可以使用真正的断点、单步执行(step in/over/out)、调用栈遍历、局部变量/闭包作用域转储,以及在暂停帧中执行任意表达式求值。node inspect — 内置,无需安装,CLI REPL(交互式命令行)。适合快速探查。ndb / CDP via chrome-remote-interface — 可从 Node/Python 脚本化调用;适合需要自动化设置大量断点、跨多次运行收集状态,或在 agent 循环中非交互式调试的场景。node inspect。 它始终可用,REPL 响应快。_SlashWorker、PTY bridge workers)行为异常console.log 获取console.log 就能解决的问题。断点调试开销较大,只在收益明显时使用。node inspect REPLdebug> 提示符接受以下命令:| 命令 | 操作 |
|---|---|
c 或 cont | 继续执行 |
n 或 next | 单步跳过 |
s 或 step | 单步进入 |
o 或 out | 单步跳出 |
pause | 暂停运行中的代码 |
sb('file.js', 42) | 在 file.js 第 42 行设置断点 |
sb(42) | 在当前文件第 42 行设置断点 |
sb('functionName') | 在函数被调用时中断 |
cb('file.js', 42) | 清除断点 |
breakpoints | 列出所有断点 |
bt | 回溯(调用栈) |
list(5) | 显示当前位置前后各 5 行源码 |
watch('expr') | 每次暂停时求值 expr |
watchers | 显示监视表达式 |
repl | 在当前作用域进入 REPL(Ctrl+C 退出 REPL) |
exec expr | 单次求值表达式 |
restart | 重启脚本 |
kill | 终止脚本 |
.exit | 退出调试器 |
repl 子模式中: 输入任意 JS 表达式,包括访问局部变量/闭包变量。Ctrl+C 返回 debug>。chrome-remote-interface:/tmp/cdp-debug.js):chrome-remote-interface 不在 ui-tui/package.json 中。如果不想污染项目,可将其安装到临时目录:ui-tui/package.json 有 npm run dev(tsx --watch)。直接运行 tsx 并添加 --inspect-brk:debug> 中:sb('dist/app.js', 220) # or wherever the suspect render is
contrepl → 检查 props、state 引用、useInput 处理器的值等。hermes --tuisb(...) 处暂停它。_SlashWorker / PTY 子进程python-debugpy skill。只有 Node 部分(Ink UI、tui_gateway client、ui-tui/ 下的 tsx-run 测试)使用本 skill。node inspect -p <pid>,然后 sb('src/app/foo.tsx', 42),cont。--no-file-parallelism(vitest)或 --runInBand(jest),确保只有一个 worker——调试 worker 池非常痛苦。HeapProfiler / Profiler:.ts 文件。解决方案:(a)在构建产物 dist/*.js 中设置断点,或(b)启用 sourcemap(node --enable-source-maps)并使用 sb('src/app.tsx', N) — 但仅限于支持 sourcemap 的 CDP 客户端。node inspect CLI 不支持。--inspect 与 --inspect-brk 的区别。 --inspect 启动 inspector 但不暂停;如果附加太晚,脚本会在你设置第一个断点之前就跑完。需要在任何代码运行前设置断点时,使用 --inspect-brk。9229。如果多个 Node 进程同时开启 inspector,传入 --inspect=0(随机端口)并从 /json/list 读取实际 URL:--inspect 不会 inspect 其子进程。使用 NODE_OPTIONS='--inspect-brk' node parent.js 将其传播到每个子进程;注意它们都需要唯一端口(继承 NODE_OPTIONS='--inspect' 时 Node 会自动递增端口号)。Ctrl+C 退出 node inspect,目标进程会保持暂停状态。请先执行 cont,或显式 kill 目标进程。node inspect。 它是一个 PTY 友好的 REPL。在 Hermes 中,使用 terminal(pty=true) 或 background=true + process(action='submit', data='...') 启动它。非 PTY 前台模式适用于单次命令,但不适合交互式单步调试。--inspect=0.0.0.0:9229 会暴露任意代码执行能力。除非处于隔离网络,否则始终绑定到 127.0.0.1(默认值)。curl -s http://127.0.0.1:9229/json/list 返回的正是预期目标--inspect-brk,或附加时执行已完成)repl 中执行 exec process.pid 返回你想附加的 PIDdebug> sb('suspectFn')
debug> cont
# paused on entry
debug> bt# Start with --inspect (no -brk), let it run to the hang, then:
debug> pause
debug> bt
# Now you see the stuck frame