3 V8 comes with an extensive debugger which is accessible out-of-process via a
4 simple [TCP protocol](http://code.google.com/p/v8/wiki/DebuggerProtocol).
5 Node has a built-in client for this debugger. To use this, start Node with the
6 `debug` argument; a prompt will appear:
8 % node debug myscript.js
9 < debugger listening on port 5858
11 break in /home/indutny/Code/git/indutny/myscript.js:1
13 2 setTimeout(function () {
17 Node's debugger client doesn't support the full range of commands, but
18 simple step and inspection is possible. By putting the statement `debugger;`
19 into the source code of your script, you will enable a breakpoint.
21 For example, suppose `myscript.js` looked like this:
25 setTimeout(function () {
31 Then once the debugger is run, it will break on line 4.
33 % node debug myscript.js
34 < debugger listening on port 5858
36 break in /home/indutny/Code/git/indutny/myscript.js:1
38 2 setTimeout(function () {
42 break in /home/indutny/Code/git/indutny/myscript.js:3
44 2 setTimeout(function () {
46 4 console.log("world");
49 break in /home/indutny/Code/git/indutny/myscript.js:4
50 2 setTimeout(function () {
52 4 console.log("world");
54 6 console.log("hello");
56 Press Ctrl + C to leave debug repl
63 break in /home/indutny/Code/git/indutny/myscript.js:5
65 4 console.log("world");
67 6 console.log("hello");
73 The `repl` command allows you to evaluate code remotely. The `next` command
74 steps over to the next line. There are a few other commands available and more
75 to come. Type `help` to see others.
79 You can watch expression and variable values while debugging your code.
80 On every breakpoint each expression from the watchers list will be evaluated
81 in the current context and displayed just before the breakpoint's source code
84 To start watching an expression, type `watch("my_expression")`. `watchers`
85 prints the active watchers. To remove a watcher, type
86 `unwatch("my_expression")`.
88 ### Commands reference
92 * `cont`, `c` - Continue execution
93 * `next`, `n` - Step next
94 * `step`, `s` - Step in
95 * `out`, `o` - Step out
96 * `pause` - Pause running code (like pause button in Developer TOols)
100 * `setBreakpoint()`, `sb()` - Set breakpoint on current line
101 * `setBreakpoint(line)`, `sb(line)` - Set breakpoint on specific line
102 * `setBreakpoint('fn()')`, `sb(...)` - Set breakpoint on a first statement in
104 * `setBreakpoint('script.js', 1)`, `sb(...)` - Set breakpoint on first line of
106 * `clearBreakpoint`, `cb(...)` - Clear breakpoint
110 * `backtrace`, `bt` - Print backtrace of current execution frame
111 * `list(5)` - List scripts source code with 5 line context (5 lines before and
113 * `watch(expr)` - Add expression to watch list
114 * `unwatch(expr)` - Remove expression from watch list
115 * `watchers` - List all watchers and their values (automatically listed on each
117 * `repl` - Open debugger's repl for evaluation in debugging script's context
119 #### Execution control
121 * `run` - Run script (automatically runs on debugger's start)
122 * `restart` - Restart script
123 * `kill` - Kill script
127 * `scripts` - List all loaded scripts
128 * `version` - Display v8's version
132 The V8 debugger can be enabled and accessed either by starting Node with
133 the `--debug` command-line flag or by signaling an existing Node process