diff --git a/doc/api/debugger.md b/doc/api/debugger.md index 08664ff9677ec6..89980cfbd4a06f 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