【问题标题】:nodejs, how to do debugging using GDBnodejs,如何使用 GDB 进行调试
【发布时间】:2013-05-13 11:36:09
【问题描述】:

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

  gdb --args ~/node_g start.js

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

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

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

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

 bcd();

现在我发出 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  

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

 In abc
 Done abc

 Program exited normally.
 (gdb) 

有人可以告诉我我在这里缺少什么吗?

问候, -M-

【问题讨论】:

    标签: node.js gdb


    【解决方案1】:

    gdb 尝试在从 c++ 源代码生成的调试信息中查找 bcd 符号。看来您实际上是想调试 javascript 而不是 c++。

    V8 内置调试​​器,node.js 有client 用于调试器protocol

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

    node inspect test.js
    

    你可以使用调试器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>
    

    或者使用debugger关键字:

     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>
    

    还有用于 V8 调试器的 GUI 客户端:node-webkit-agentnode-inspectoreclipse

    【讨论】:

    • Node v8 推荐使用node inspect 而不是node debug
    【解决方案2】:

    试试Trepan-ni。它是一个基于 Node Inspector 的类似 GDB 的调试器。我已经用了一年多了,效果很好。我可以确认它适用于 NodeJS v8 到 v14。

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2020-03-11
      • 2015-06-13
      • 1970-01-01
      相关资源
      最近更新 更多