GeezerVison is showing github.com — doc: add conditional example for setBreakpoint() · nodejs/node@34d6ca3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/debugger.md +39Lines changed: 39 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -118,6 +118,9 @@ To begin watching an expression, type `watch('my_expression')`. The command |
118 | 118 | functions body |
119 | 119 | * `setBreakpoint('script.js', 1)`, `sb(...)`: Set breakpoint on first line of |
120 | 120 | `script.js` |
| 121 | +* `setBreakpoint('script.js', 1, 'num < 4')`, `sb(...)`: Set conditional |
| 122 | +breakpoint on first line of `script.js` that only breaks when `num < 4` |
| 123 | +evaluates to `true` |
121 | 124 | * `clearBreakpoint('script.js', 1)`, `cb(...)`: Clear breakpoint in `script.js` |
122 | 125 | on line 1 |
123 | 126 |
|
@@ -145,6 +148,42 @@ break in mod.js:22 |
145 | 148 | debug> |
146 | 149 | ``` |
147 | 150 |
|
| 151 | +It is also possible to set a conditional breakpoint that only breaks when a |
| 152 | +given expression evaluates to `true`: |
| 153 | + |
| 154 | +```console |
| 155 | +$ node inspect main.js |
| 156 | +< Debugger listening on ws://127.0.0.1:9229/ce24daa8-3816-44d4-b8ab-8273c8a66d35 |
| 157 | +< For help, see: https://nodejs.org/en/docs/inspector |
| 158 | +< Debugger attached. |
| 159 | +Break on start in main.js:7 |
| 160 | + 5 } |
| 161 | + 6 |
| 162 | +> 7 addOne(10); |
| 163 | + 8 addOne(-1); |
| 164 | + 9 |
| 165 | +debug> setBreakpoint('main.js', 4, 'num < 0') |
| 166 | + 1 'use strict'; |
| 167 | + 2 |
| 168 | + 3 function addOne(num) { |
| 169 | +> 4 return num + 1; |
| 170 | + 5 } |
| 171 | + 6 |
| 172 | + 7 addOne(10); |
| 173 | + 8 addOne(-1); |
| 174 | + 9 |
| 175 | +debug> cont |
| 176 | +break in main.js:4 |
| 177 | + 2 |
| 178 | + 3 function addOne(num) { |
| 179 | +> 4 return num + 1; |
| 180 | + 5 } |
| 181 | + 6 |
| 182 | +debug> exec('num') |
| 183 | +-1 |
| 184 | +debug> |
| 185 | +``` |
| 186 | + |
148 | 187 | ### Information |
149 | 188 |
|
150 | 189 | * `backtrace`, `bt`: Print backtrace of current execution frame |
|