How to debug binary module of nodejs?

lanoxx picture lanoxx · Apr 22, 2014 · Viewed 12.1k times · Source

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.

  • 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?

Answer

lanoxx picture lanoxx · Apr 22, 2014

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.