Nodejs how to do debugging with gdb

After searching google, I found the gdb way for nodejs below, build node c. / configure --debug and then run

gdb --args ~/node_g start.js 

Using this, I am trying to debug a small program, but after setting a breakpoint, I can’t see that it breaks in this function,

My simple gdb_node.js program 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'm missing here?

Regards, -M -

+6
source share
1 answer

gdb tries to search for a bcd character when debugging information received from a c ++ source. It seems like you really want to debug JavaScript, not c ++.

V8 has a debugger built in, and node.js has a client for the debugger protocol .

To start node.js with the debugger client connected to the program:

 node inspect test.js 

You can set breakpoints using the 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 the 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 also GUI clients for the V8 debugger: node-webkit-agent , node-inspector , eclipse and others

+9
source

Source: https://habr.com/ru/post/944870/


All Articles