Skip to content

Commit

Permalink
doc: add conditional example for setBreakpoint()
Browse files Browse the repository at this point in the history
The `node-inspect` debugging client supports passing an optional third
parameter as a string to be evaluated when the breakpoint is hit. If the
condition evaluates to `true` in the current context, the breakpoint
pauses execution; otherwise the execution continues.

This was raised as an issue in
nodejs/node-inspect#68, but the client already
supports that functionality, so I thought it'd be helpful to add it to
the node documentation.

PR-URL: #35823
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
  • Loading branch information
copperwall authored and targos committed Nov 3, 2020
1 parent dd3cbb4 commit 5e8d821
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions doc/api/debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ To begin watching an expression, type `watch('my_expression')`. The command
functions body
* `setBreakpoint('script.js', 1)`, `sb(...)`: Set breakpoint on first line of
`script.js`
* `setBreakpoint('script.js', 1, 'num < 4')`, `sb(...)`: Set conditional
breakpoint on first line of `script.js` that only breaks when `num < 4`
evaluates to `true`
* `clearBreakpoint('script.js', 1)`, `cb(...)`: Clear breakpoint in `script.js`
on line 1

Expand Down Expand Up @@ -145,6 +148,42 @@ break in mod.js:22
debug>
```

It is also possible to set a conditional breakpoint that only breaks when a
given expression evaluates to `true`:

```console
$ node inspect main.js
< Debugger listening on ws://127.0.0.1:9229/ce24daa8-3816-44d4-b8ab-8273c8a66d35
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in main.js:7
5 }
6
> 7 addOne(10);
8 addOne(-1);
9
debug> setBreakpoint('main.js', 4, 'num < 0')
1 'use strict';
2
3 function addOne(num) {
> 4 return num + 1;
5 }
6
7 addOne(10);
8 addOne(-1);
9
debug> cont
break in main.js:4
2
3 function addOne(num) {
> 4 return num + 1;
5 }
6
debug> exec('num')
-1
debug>
```

### Information

* `backtrace`, `bt`: Print backtrace of current execution frame
Expand Down

0 comments on commit 5e8d821

Please sign in to comment.