After searching in google, I found the below way to do gdb on nodejs application, build node with ./configure --debug option and then do
gdb --args ~/node_g start.js
Using this I am trying to debug a small program, but after setting the breakpoint, I am not able to see that it is breaking in that function,
My simple program gdb_node.js looks like this:
function abc() {
console.log("In abc");
}
function bcd() {
abc();
console.log("Done abc");
}
bcd();
Now I am issuing gdb:
(gdb) b bcd
Function "bcd" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (bcd) pending.
(gdb) run
Starting program: /Users/mayukh/node_g gdb_node.js
Reading symbols for shared libraries
++++......................................................................................................................................... done
In abc
Done abc
Program exited normally.
(gdb)
Can someone please let me know what I am missing here?
Regards, -M-
gdb
tries to lookup bcd
symbol in debugging information generated from c++ source. It seems that you actually want to debug javascript and not c++.
V8 has built in debugger, and node.js has client for debugger protocol
To start node.js with debugger client attached to program:
node inspect test.js
You can set breakpoints using debugger commands:
sh-3.2$ node inspect test.js
< debugger listening on port 5858
connecting... ok
break in test.js:10
8 }
9
10 bcd();
11
12 });
debug> sb(6)
5 function bcd() {
* 6 abc();
7 console.log("Done abc");
8 }
9
10 bcd();
11
12 });
debug>
Or use debugger
keyword:
function abc() {
console.log("In abc");
}
function bcd() {
debugger;
abc();
console.log("Done abc");
}
bcd();
=
sh-3.2$ node inspect test.js
< debugger listening on port 5858
connecting... ok
break in test.js:11
9 }
10
11 bcd();
12
13 });
debug> c
break in test.js:6
4
5 function bcd() {
6 debugger;
7 abc();
8 console.log("Done abc");
debug>
There are GUI clients for V8 debugger as well: node-webkit-agent, node-inspector, eclipse and others
Give Trepan-ni a try. It is a GDB-like debugger based on Node Inspector. I've been using it for over a year, and it works well. I can confirm it works with NodeJS v8 to v14.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With