-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging the debugger
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 :)
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.
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)
- start hello.js
node --debug test/hello.js
- browse to (1) http://localhost:8124
- start node-inspector
node --debug=7878 bin/inspector.js
- browse to (2) http://localhost:8080
- start another node-inspector
node bin/inspector.js --web-port=9090
- 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).
To debug both front-end and back-end together, just combine the above methods for a total of 4 pages.
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 :)