Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Opperwall <copperwall@gmail.com>2020-10-26 23:15:30 +0300
committerRich Trott <rtrott@gmail.com>2020-10-29 15:12:09 +0300
commita3cc23923ac9d42f55952f482e1eeac8716eccbf (patch)
tree76e683eaf1995a3484917d00ee15caee8bbeb20a /doc/api/debugger.md
parentbec918fb9bbf3fa1d8f9f5fcd37a9ee5f719dd63 (diff)
doc: add conditional example for setBreakpoint()
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 https://github.com/nodejs/node-inspect/issues/68, but the client already supports that functionality, so I thought it'd be helpful to add it to the node documentation. PR-URL: https://github.com/nodejs/node/pull/35823 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
Diffstat (limited to 'doc/api/debugger.md')
-rw-r--r--doc/api/debugger.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/doc/api/debugger.md b/doc/api/debugger.md
index 08664ff9677..89980cfbd4a 100644
--- a/doc/api/debugger.md
+++ b/doc/api/debugger.md
@@ -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
@@ -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