nodejs,如何使用GDB进行调试

u_p*_*ess 8 gdb node.js

在谷歌搜索后,我找到了以下方法在nodejs应用程序上执行gdb,使用./configure --debug选项构建节点然后执行

  gdb --args ~/node_g start.js
Run Code Online (Sandbox Code Playgroud)

使用这个我试图调试一个小程序,但在设置断点后,我无法看到它在该函数中断,

我的简单程序gdb_node.js如下所示:

 function abc() {
    console.log("In abc");
 }

 function bcd() {
    abc();
    console.log("Done abc");
 }

 bcd();
Run Code Online (Sandbox Code Playgroud)

现在我发布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  
Run Code Online (Sandbox Code Playgroud)

++++ .............................................. .................................................. ..........................................完成

 In abc
 Done abc

 Program exited normally.
 (gdb) 
Run Code Online (Sandbox Code Playgroud)

有人可以让我知道我在这里失踪了吗?

问候,-M-

And*_*rov 10

gdb尝试bcd在从c ++源生成的调试信息中查找符号.看来你真的想调试javascript而不是c ++.

V8内置调试器,node.js具有调试器协议的客户端

使用附加到程序的调试器客户端启动node.js:

node inspect test.js
Run Code Online (Sandbox Code Playgroud)

您可以使用调试器命令设置断点:

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>
Run Code Online (Sandbox Code Playgroud)

或使用debugger关键字:

 function abc() {
    console.log("In abc");
 }

 function bcd() {
    debugger;
    abc();
    console.log("Done abc");
 }

 bcd();
Run Code Online (Sandbox Code Playgroud)

=

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>
Run Code Online (Sandbox Code Playgroud)

V8调试器还有GUI客户端:node-webkit-agent,node-inspector,eclipse