Skip to content

Commit

Permalink
doc: update debugger.md description and examples
Browse files Browse the repository at this point in the history
The console captures in debugger.md are out of date, showing the
wrapper:

  function (exports, require, module, __filename, __dirname) {

That wrapper is no longer shown in debug sessions.

This also shortens and simplifies the description of the debugger in the
lede.

PR-URL: #39661
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and targos committed Sep 4, 2021
1 parent 9672bbf commit df1e20a
Showing 1 changed file with 46 additions and 35 deletions.
81 changes: 46 additions & 35 deletions doc/api/debugger.md
Expand Up @@ -6,20 +6,22 @@
<!-- type=misc -->

Node.js includes an out-of-process debugging utility accessible via a
[V8 Inspector][] and built-in debugging client. To use it, start Node.js
with the `inspect` argument followed by the path to the script to debug; a
prompt will be displayed indicating successful launch of the debugger:
Node.js includes a command-line debugging utility. To use it, start Node.js
with the `inspect` argument followed by the path to the script to debug.

```console
$ node inspect myscript.js
< Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
< Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
Break on start in myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
3 console.log('world');
<
ok
Break on start in myscript.js:2
1 // myscript.js
> 2 global.x = 5;
3 setTimeout(() => {
4 debugger;
debug>
```

Expand All @@ -44,28 +46,33 @@ Once the debugger is run, a breakpoint will occur at line 3:

```console
$ node inspect myscript.js
< Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
< Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
Break on start in myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
3 debugger;
<
ok
Break on start in myscript.js:2
1 // myscript.js
> 2 global.x = 5;
3 setTimeout(() => {
4 debugger;
debug> cont
< hello
break in myscript.js:3
1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
> 3 debugger;
4 console.log('world');
5 }, 1000);
debug> next
<
break in myscript.js:4
2 setTimeout(() => {
3 debugger;
> 4 console.log('world');
5 }, 1000);
6 console.log('hello');
2 global.x = 5;
3 setTimeout(() => {
> 4 debugger;
5 console.log('world');
6 }, 1000);
debug> next
break in myscript.js:5
3 setTimeout(() => {
4 debugger;
> 5 console.log('world');
6 }, 1000);
7 console.log('hello');
debug> repl
Press Ctrl+C to leave debug repl
> x
Expand All @@ -74,13 +81,15 @@ Press Ctrl+C to leave debug repl
4
debug> next
< world
break in myscript.js:5
3 debugger;
4 console.log('world');
> 5 }, 1000);
6 console.log('hello');
7
<
break in myscript.js:6
4 debugger;
5 console.log('world');
> 6 }, 1000);
7 console.log('hello');
8
debug> .exit
$
```

The `repl` command allows code to be evaluated remotely. The `next` command
Expand Down Expand Up @@ -129,11 +138,14 @@ is not loaded yet:

```console
$ node inspect main.js
< Debugger listening on ws://127.0.0.1:9229/4e3db158-9791-4274-8909-914f7facf3bd
< Debugger listening on ws://127.0.0.1:9229/48a5b28a-550c-471b-b5e1-d13dd7165df9
< For help, see: https://nodejs.org/en/docs/inspector
<
< Debugger attached.
<
ok
Break on start in main.js:1
> 1 (function (exports, require, module, __filename, __dirname) { const mod = require('./mod.js');
> 1 const mod = require('./mod.js');
2 mod.hello();
3 mod.hello();
debug> setBreakpoint('mod.js', 22)
Expand Down Expand Up @@ -239,6 +251,5 @@ Chrome DevTools doesn't support debugging [worker threads][] yet.
[ndb][] can be used to debug them.

[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
[V8 Inspector]: #debugger_v8_inspector_integration_for_node_js
[ndb]: https://github.com/GoogleChromeLabs/ndb/
[worker threads]: worker_threads.md

0 comments on commit df1e20a

Please sign in to comment.