dbg
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedbg Debugger
dbg 调试器
dbg@refsdbg@refsSupported Runtimes
支持的运行时
| Runtime | Language | Launch example |
|---|---|---|
| Node.js | JavaScript | |
| tsx / ts-node | TypeScript | |
| Bun | JavaScript / TypeScript | |
| LLDB | C / C++ / Rust / Swift | |
The runtime is auto-detected from the launch command for JS runtimes. For native code, use .
--runtime lldb| 运行时 | 语言 | 启动示例 |
|---|---|---|
| Node.js | JavaScript | |
| tsx / ts-node | TypeScript | |
| Bun | JavaScript / TypeScript | |
| LLDB | C / C++ / Rust / Swift | |
对于JS运行时,会自动从启动命令中检测运行时类型。对于原生代码,请使用参数。
--runtime lldbCore Debug Loop
核心调试流程
bash
undefinedbash
undefined1. Launch with breakpoint at first line
1. 在第一行设置断点启动
dbg launch --brk node app.js
dbg launch --brk node app.js
Or: dbg launch --brk bun app.ts
或者: dbg launch --brk bun app.ts
Or: dbg launch --brk --runtime lldb ./my_program
或者: dbg launch --brk --runtime lldb ./my_program
Or attach to a running process with the --inspect flag
或者附加到启用了--inspect标志的运行中进程
dbg attach 9229
dbg attach 9229
2. Set breakpoints at suspicious locations
2. 在可疑位置设置断点
dbg break src/handler.ts:42
dbg break src/utils.ts:15 --condition "count > 10"
dbg break src/handler.ts:42
dbg break src/utils.ts:15 --condition "count > 10"
3. Run to breakpoint
3. 运行到断点处
dbg continue
dbg continue
4. Inspect state (shows location, source, locals, stack)
4. 检查状态(显示位置、源代码、局部变量、调用栈)
dbg state
dbg state
5. Drill into values
5. 深入查看值
dbg props @v1 # expand object
dbg props @v1 --depth 3 # expand nested 3 levels
dbg eval "x + 1"
dbg props @v1 # 展开对象
dbg props @v1 --depth 3 # 展开嵌套3层
dbg eval "x + 1"
6. Fix and verify (JS/TS only)
6. 修复并验证(仅JS/TS支持)
dbg set count 0 # change variable
dbg hotpatch src/utils.js # live-edit (reads file from disk)
dbg continue # verify fix
undefineddbg set count 0 # 修改变量
dbg hotpatch src/utils.js # 实时编辑(从磁盘读取文件)
dbg continue # 验证修复效果
undefinedDebugging Strategies
调试策略
Bug investigation -- narrow down with breakpoints
Bug排查——通过断点缩小范围
bash
dbg launch --brk node app.js
dbg break src/api.ts:50 # suspect line
dbg break src/api.ts:60 --condition "!user" # conditional
dbg continue
dbg vars # check locals
dbg eval "JSON.stringify(req.body)" # inspect deeply
dbg step over # advance one line
dbg state # see new statebash
dbg launch --brk node app.js
dbg break src/api.ts:50 # 可疑代码行
dbg break src/api.ts:60 --condition "!user" # 条件断点
dbg continue
dbg vars # 检查局部变量
dbg eval "JSON.stringify(req.body)" # 深入查看内容
dbg step over # 单步跳过一行
dbg state # 查看新状态Native code debugging (C/C++/Rust)
原生代码调试(C/C++/Rust)
bash
dbg launch --brk --runtime lldb ./my_program
dbg break main.c:42
dbg break-fn main # function breakpoint (DAP only)
dbg continue
dbg vars # inspect locals
dbg eval "array[i]" # evaluate expression
dbg step into # step into functionbash
dbg launch --brk --runtime lldb ./my_program
dbg break main.c:42
dbg break-fn main # 函数断点(仅DAP支持)
dbg continue
dbg vars # 检查局部变量
dbg eval "array[i]" # 计算表达式
dbg step into # 单步进入函数Attach to running/test process
附加到运行中/测试进程
bash
undefinedbash
undefinedStart with inspector enabled
启动时启用调试检查器
node --inspect app.js
node --inspect app.js
Or: bun --inspect app.ts
或者: bun --inspect app.ts
Then attach
然后附加调试器
dbg attach 9229
dbg state
undefineddbg attach 9229
dbg state
undefinedTrace execution flow with logpoints (no pause)
使用日志点追踪执行流程(不会暂停)
bash
dbg logpoint src/auth.ts:20 "login attempt: ${username}"
dbg logpoint src/auth.ts:45 "auth result: ${result}"
dbg continue
dbg console # see logged outputbash
dbg logpoint src/auth.ts:20 "login attempt: ${username}"
dbg logpoint src/auth.ts:45 "auth result: ${result}"
dbg continue
dbg console # 查看日志输出Exception debugging
异常调试
bash
dbg catch uncaught # pause on uncaught exceptions
dbg continue # runs until exception
dbg state # see where it threw
dbg eval "err.message" # inspect the error
dbg stack # full call stackbash
dbg catch uncaught # 在未捕获异常处暂停
dbg continue # 运行至异常触发位置
dbg state # 查看异常抛出位置
dbg eval "err.message" # 检查错误信息
dbg stack # 查看完整调用栈TypeScript source map support
TypeScript源映射支持
dbg automatically resolves paths via source maps. Set breakpoints using paths, see source in output. Use to see compiled if needed.
.ts.ts.ts--generated.jsdbg会自动通过源映射解析文件路径。可以使用文件路径设置断点,输出中会显示源代码。如果需要查看编译后的代码,请使用参数。
.ts.ts.ts.js--generatedRef System
引用系统
Every output assigns short refs. Use them everywhere:
- -- variables:
@v1..@vN,dbg props @v1dbg set @v2 true - -- stack frames:
@f0..@fNdbg eval --frame @f1 "this" - -- breakpoints:
BP#1..N,dbg break-rm BP#1dbg break-toggle BP#1 - -- logpoints:
LP#1..Ndbg break-rm LP#1
Refs / reset on each pause. / persist until removed.
@v@fBP#LP#所有输出都会分配简短的引用标识,可在任意命令中使用:
- -- 变量:
@v1..@vN、dbg props @v1dbg set @v2 true - -- 调用栈帧:
@f0..@fNdbg eval --frame @f1 "this" - -- 断点:
BP#1..N、dbg break-rm BP#1dbg break-toggle BP#1 - -- 日志点:
LP#1..Ndbg break-rm LP#1
@v@fBP#LP#Key Flags
关键标志
- -- machine-readable JSON output on any command
--json - -- target a specific session (default: "default")
--session NAME - -- select debug adapter (e.g.
--runtime NAMEfor native code)lldb - -- bypass source maps, show compiled JS (on state/source/stack)
--generated
- -- 所有命令输出机器可读的JSON格式
--json - -- 指定目标会话(默认值:"default")
--session NAME - -- 选择调试适配器(例如,原生代码使用
--runtime NAME)lldb - -- 绕过源映射,显示编译后的JS代码(适用于state/source/stack命令)
--generated
Command Reference
命令参考
See references/commands.md for full command details and options.
完整的命令详情和选项请参考references/commands.md。
Tips
提示
- after stepping always shows location + source + locals -- usually enough context
dbg state - for source only,
dbg state -cfor vars only,-vfor stack only -- save tokens-s - supports
dbg eval-- useful for async inspection (JS/TS)await - -- skip stepping into dependencies
dbg blackbox "node_modules/**" - reads the file from disk -- edit the file first, then hotpatch (JS/TS only)
dbg hotpatch file - -- function breakpoints work with DAP runtimes (LLDB)
dbg break-fn funcName - Execution commands (,
continue,step,pause) auto-return statusrun-to - kills the debugged process and daemon
dbg stop
- 单步执行后使用,总会显示位置、源代码和局部变量——通常已足够提供上下文信息
dbg state - 使用仅显示源代码,
dbg state -c仅显示变量,-v仅显示调用栈——节省输出内容-s - 支持
dbg eval——对异步代码调试非常有用(仅JS/TS)await - -- 跳过进入依赖包代码的单步执行
dbg blackbox "node_modules/**" - 会从磁盘读取文件——请先编辑文件,再执行hotpatch命令(仅JS/TS)
dbg hotpatch file - -- 函数断点仅支持DAP运行时(LLDB)
dbg break-fn funcName - 执行类命令(、
continue、step、pause)会自动返回状态run-to - 会终止被调试的进程和守护进程
dbg stop