gpt4 book ai didi

node.js - nodejs,如何使用 GDB 进行调试

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:27 24 4
gpt4 key购买 nike

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

  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-

最佳答案

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-agent , node-inspector , eclipse

关于node.js - nodejs,如何使用 GDB 进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16521071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com