命令参考
步进
cont,c- 继续执行next,n- 下一步step,s- 介入out,o- 退出介入pause- 暂停执行代码(类似开发者工具中的暂停按钮)
断点
setBreakpoint(),sb()- 在当前行设置断点setBreakpoint(line),sb(line)- 在指定行设置断点setBreakpoint('fn()'),sb(...)- 在函数体的第一条语句设置断点setBreakpoint('script.js', 1),sb(...)- 在 script.js 的第一行设置断点clearBreakpoint('script.js', 1),cb(...)- 清除 script.js 第一行的断点
也可以在一个尚未被加载的文件(模块)中设置断点:
$ ./node debug test/fixtures/break-in-module/main.js
< debugger listening on port 5858
connecting to port 5858... ok
break in test/fixtures/break-in-module/main.js:1
1 var mod = require('./mod.js');
2 mod.hello();
3 mod.hello();
debug> setBreakpoint('mod.js', 23)
Warning: script 'mod.js' was not loaded yet.
1 var mod = require('./mod.js');
2 mod.hello();
3 mod.hello();
debug> c
break in test/fixtures/break-in-module/mod.js:23
21
22 exports.hello = () => {
23 return 'hello from module';
24 };
25
debug>
信息
backtrace,bt- 显示当前执行框架的回溯list(5)- 显示脚本源代码的 5 行上下文(之前 5 行和之后 5 行)watch(expr)- 向监视列表添加表达式unwatch(expr)- 从监视列表移除表达式watchers- 列出所有监视器和它们的值(每个断点会自动列出)repl- 在所调试的脚本的上下文中打开调试器的REPL进行评估exec expr- 在所调试的脚本的上下文中执行一个表达式
执行控制
run- 运行脚本(调试器开始时自动运行)restart- 重新启动脚本kill- 终止脚本
杂项
scripts- 列出所有已加载的脚本version- 显示 V8 引擎的版本号