如何调试nodejs的二进制模块? [英] How to debug binary module of nodejs?
问题描述
我有一个用C ++编写的node.js模块,为C ++库提供了一些绑定。该库崩溃与SIGSEGV,所以我需要调试它与GDB,并找出什么问题。
我已经有模块的源在 ./ node_modules / somelib /
,如果我去那个文件夹并输入 npm install
,编译库就可以通过require 'somelib')from node.js。我可以附加gdb到节点并重现错误,但在stacktrace我只看到 node_modules / somelib / Release / somelib.node
。
我不知道这是否重要,但是库是使用 node-gyp
>
- 问题1:如何加载源代码或将gdb指向源代码?
- 问题2:如何配置
node-gyp
以产生调试符号? - Question 1: How do I load the source code or point gdb to the source code?
- Question 2: How do I configure
node-gyp
to produce debug symbols?
我在 node-gyp
文档中找到了答案。解决方案是使用 - debug
标志来调用构建过程。这意味着调用 node-gyp configure --debug
和/或 node-gyp build --debug
。然后代替 Release
文件夹,将创建一个 Debug
文件夹。 gdb会自动加载源文件。
I have a node.js module written in C++ that provides some bindings for a C++ library. The library crashes with SIGSEGV, so I need to debug it with GDB and find out what goes wrong.
I already have the source for the module in ./node_modules/somelib/
and if I go to that folder and type npm install
the library is compiled and can be used through a require('somelib') from node.js. I can attach gdb to node and reproduce the error, but in the stacktrace I just see node_modules/somelib/Release/somelib.node
.
I'm not sure if this is important but the library is compiled using node-gyp
.
I just found the answer to this in the node-gyp
documentation. The solution is to invoke the build process with the --debug
flag. That means to invoke node-gyp configure --debug
and/or node-gyp build --debug
. Then instead of a Release
folder a Debug
folder will be created. gdb will then automatically load the source files.
这篇关于如何调试nodejs的二进制模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!