-
-
Notifications
You must be signed in to change notification settings - Fork 85
node debug notes
Notes:
- This uses the older node protocol for version 6.2 and before. For the newer chrome v8 inspector protocol, see realgud-node-inspect.
- Because of difficulties in providing support to the stock nodejs debugger, I forked that older code and wrote trepanjs. Integration of trepanjs into realgud is better. The same thing needs to be done for the newer code. However even better would be use use websocket for emaacs using the v8 inspector protocol. Volunteers?
Please refer to the Node.js Debugger Manual & Documentation for more information about the built-in client debugger.
To invoke the realgud nodejs debugger: M-x realgud:node-debug
.
When prompted in the minibuffer, execute the command to attach to the Node.js running in debug mode. For example: Run node (like this): node debug localhost:5858
After the command is executed, there will be a new buffer created. This buffer will henceforth be known as the command buffer. If the debugger attached successfully, you should see the following output in the command buffer:
Current directory: <your_current_directory>
Command: <your_executed_command>
debug> connecting... ok
debug>
You are now ready to debug.
I'm sure you all know this, so recall then that debugger commands in nodejs use javascirpt syntax. As such, when a command needs a parameter, you give that as you would in JavaScript. For example you type:
setBreakpoint(5)
not:
setBreakpoint 5
Furthermore, commands that take parameters need to have the parenthesis, while those that don't should not have parenthesis. Some of this may get addressed in a future release of nodejs. I've addressed some of this in my fork off of that trepanjs.
A buffer containing your Node.js source code will henceforth be known as a source buffer.
Use the command buffer to debug Node.js. Issue command help
for a list of commands.
Enable nodejs-track-mode
to follow the debugger in the source buffers.
Enable realgud-short-key-mode
to make source buffers read-only and bind keys for debug commands.
In order to set breakpoints with realgud:nodejs-set-breakpoint
in the source buffer, a command buffer must first associate itself with a source buffer. Command buffers do not associate themselves with any source buffers until you happen to be stopped inside that Javacript source (and output is displayed which shows where in the source code you are). There is also currently no interactive function to associate a command buffer with a source buffer implemented for the nodejs debugger.
To associate a command buffer with a source buffer:
- Enable
nodejs-track-mode
in the command buffer. - Set a breakpoint either using a
debugger;
statement or setting a breakpoint in the command buffer. - Trigger the breakpoint.
Once the breakpoint is triggered, the command buffer arranges to pull up the source buffer and associate itself with that source buffer. After the association has been made, breakpoints can be set directly in the source buffer with realgud:nodejs-set-breakpoint
. The command buffer will continue to make associations with source buffers as you debug and visit new source buffers.