7 V8 comes with an extensive debugger which is accessible out-of-process via a
8 simple [TCP protocol](http://code.google.com/p/v8/wiki/DebuggerProtocol).
9 Node has a built-in client for this debugger. To use this, start Node with the
10 `debug` argument; a prompt will appear:
12 % node debug myscript.js
13 < debugger listening on port 5858
15 break in /home/indutny/Code/git/indutny/myscript.js:1
17 2 setTimeout(function () {
21 Node's debugger client doesn't support the full range of commands, but
22 simple step and inspection is possible. By putting the statement `debugger;`
23 into the source code of your script, you will enable a breakpoint.
25 For example, suppose `myscript.js` looked like this:
29 setTimeout(function () {
35 Then once the debugger is run, it will break on line 4.
37 % node debug myscript.js
38 < debugger listening on port 5858
40 break in /home/indutny/Code/git/indutny/myscript.js:1
42 2 setTimeout(function () {
46 break in /home/indutny/Code/git/indutny/myscript.js:3
48 2 setTimeout(function () {
50 4 console.log("world");
53 break in /home/indutny/Code/git/indutny/myscript.js:4
54 2 setTimeout(function () {
56 4 console.log("world");
58 6 console.log("hello");
60 Press Ctrl + C to leave debug repl
67 break in /home/indutny/Code/git/indutny/myscript.js:5
69 4 console.log("world");
71 6 console.log("hello");
77 The `repl` command allows you to evaluate code remotely. The `next` command
78 steps over to the next line. There are a few other commands available and more
79 to come. Type `help` to see others.
83 You can watch expression and variable values while debugging your code.
84 On every breakpoint each expression from the watchers list will be evaluated
85 in the current context and displayed just before the breakpoint's source code
88 To start watching an expression, type `watch("my_expression")`. `watchers`
89 prints the active watchers. To remove a watcher, type
90 `unwatch("my_expression")`.
96 * `cont`, `c` - Continue execution
97 * `next`, `n` - Step next
98 * `step`, `s` - Step in
99 * `out`, `o` - Step out
100 * `pause` - Pause running code (like pause button in Developer Tools)
104 * `setBreakpoint()`, `sb()` - Set breakpoint on current line
105 * `setBreakpoint(line)`, `sb(line)` - Set breakpoint on specific line
106 * `setBreakpoint('fn()')`, `sb(...)` - Set breakpoint on a first statement in
108 * `setBreakpoint('script.js', 1)`, `sb(...)` - Set breakpoint on first line of
110 * `clearBreakpoint`, `cb(...)` - Clear breakpoint
114 * `backtrace`, `bt` - Print backtrace of current execution frame
115 * `list(5)` - List scripts source code with 5 line context (5 lines before and
117 * `watch(expr)` - Add expression to watch list
118 * `unwatch(expr)` - Remove expression from watch list
119 * `watchers` - List all watchers and their values (automatically listed on each
121 * `repl` - Open debugger's repl for evaluation in debugging script's context
123 ### Execution control
125 * `run` - Run script (automatically runs on debugger's start)
126 * `restart` - Restart script
127 * `kill` - Kill script
131 * `scripts` - List all loaded scripts
132 * `version` - Display v8's version
136 The V8 debugger can be enabled and accessed either by starting Node with
137 the `--debug` command-line flag or by signaling an existing Node process
140 Once a process has been set in debug mode with this it can be connected to
141 with the node debugger. Either connect to the `pid` or the URI to the debugger.
144 * `node debug -p <pid>` - Connects to the process via the `pid`
145 * `node debug <URI> - Connects to the process via the URI such as localhost:5858