Skip to content

Debugging the debugger

tlrobinson edited this page Oct 2, 2011 · 3 revisions

Background

Node-inspector consists of two parts, front-end (browser) and back-end (node). The front-end consists of the web inspector code from WebKit and some adapter code that communicated with the back-end. The back-end code is a node process that proxies messages from the front-end and the node debugger back and forth. Either part can be debugged independently or simultaneously. Hold on, cuz things might get a little weird. And remember, the bug you’re debugging is also in the debugger you’re debugging with (just hopefully not at the same point in time). Good Luck :)

Debugging the front-end

This is the easiest to set up. Just start your browser’s debugger while on the node-inspector page. Node specific code is in the front-end/node folder, thats a good place to start.

Debugging the back-end

It’s easiest to explain this procedure with an example. NOTE: The npm installed node-inspector can’t be used as the debug target, but can be your working debugger. For simplicity this sample only uses a cloned git repo.

At the end you will have 3 pages running:

  • (1) the test app page
  • (2) instance 1 of node-inspector (debugging test/hello.js)
  • (3) instance 2 of node-inspector (debugging instance 1 back-end)
  1. start hello.js
    node --debug test/hello.js
  2. browse to (1) http://localhost:8124
  3. start node-inspector
    node --debug=7878 bin/inspector.js
  4. browse to (2) http://localhost:8080
  5. start another node-inspector
    node bin/inspector.js --web-port=9090
  6. browse to (3) http://localhost:9090

The second node-inspector (3) will also attach to test/hello.js but you don’t want this. Disconnect by clicking the blue check icon in the lower left corner. You should now see an empty panel with an input field for the port number to connect to. Change this value to 7878 and click ‘Connect to Node’. Your second node-inspector is now connected to the back-end of the first node-inspector.

Use (3) to set breakpoints on (2). Interact with (2) to hit your breakpoints. Setting breakpoints on (2) will debug (1).

All the way

To debug both front-end and back-end together, just combine the above methods for a total of 4 pages.

Fin

With all that mess, you can debug node-inspector debugging another app. For the full “meta” experience try this while travelling at a sufficiently ludicrous speed and watch yourself debugging the debugger thats debugging your app :)