调试节点js绑定c++插件
Debugging nodejs nbind c++ addons
我目前正在尝试使用 nbind with the universal example 编写 C++ NodeJS 插件。构建和 运行 示例完美运行。现在我有两个问题,第一个与一般调试有关,第二个与我的问题有关。
我添加了 RF24 库。构造一个 RF24 object 也可以,但是在 Nodejs returns 中调用例如 getChannel()
或 printDetails()
函数只是
terminated called after throwing an instance of 'int'
npm ERR! Test failed. See above for more details
我如何才能从错误中获取更多详细信息,例如文件和行号?我尝试添加 node-gyp configure --debug build --debug
标志,但构建也只生成一个 Release 文件夹。
我的构建命令如下,如通用示例中所建议的那样。
"build:native": "autogypi -r build && node-gyp -C build/native configure --debug build --debug && copyasm build/native dist"
我正在构建 RPi 零 W (Arm v6)。我当前的 binding.gyp 位于 。/build/native 看起来如下
{
"targets": [
{
"includes": [ "../auto.gypi" ],
"sources": [
"../../src/example.cpp",
"../../libs/RF24-master/RF24.cpp",
"../../libs/RF24-master/utility/RPi/bcm2835.cpp",
"../../libs/RF24-master/utility/RPi/interrupt.cpp",
"../../libs/RF24-master/utility/RPi/spi.cpp"
],
"include_dirs": [
"../../src",
"../../libs/RF24-master"
],
"cflags": [
"-std=c++11",
"-fpermissive"
],
"cflags_cc!": [ "-fno-rtti" ]
}
],
"includes": [
"../auto-top.gypi"
]
}
简化后的程序 example.cpp
看起来像
#include "RF24.h"
#include "example.h"
Example::Example(uint16_t cePin, uint16_t spiBus): cePin(cePin), spiBus(spiBus) {
this->radio = new RF24(cePin, spiBus);
}
uint8_t Example::getChannel() {
return this->radio->getChannel();
}
而对应的headerexample.h
看起来像
#ifndef EXAMPLE_H
#define EXAMPLE_H
class Example{
uint8_t cePin = 22, spiBus = 0;
RF24* radio;
public:
Example(uint16_t cePin, uint16_t spiBus);
uint8_t getChannel();
};
#endif
#include "nbind/nbind.h"
NBIND_CLASS(Example) {
construct<uint8_t, uint8_t>();
method(getChannel);
}
所以有两个问题
- 一般且更重要:如何为 nbind c++ 插件获得更舒适的调试选项?
- 更具体地针对我的问题并与 RF24 相关:为什么每次调用 RF24 函数时都会出现该错误?
第一个问题我找到了答案。 NodeJS 在 gdb 下运行良好。这样做
sudo gdb node
> run myscript.js
打印以下更详细的错误
Thread 1 "node" received signal SIGSEGV, Segmentation fault.
0xb4c15ff8 in bcm2835_peri_read () from /usr/local/lib/librf24.so.1
如果周围有人知道发生了什么或对如何进一步挖掘有想法,不客气。我使用 RF24 脚本创建共享库,而不是使用 node-gyp 构建它。它产生的错误完全一样。
编辑:我首先在没有 nodejs 的情况下构建了一个用于测试目的的解决方法。它在授予程序 root 权限时有效。由于它是一个独立的 rasbpi,没有连接到任何网络,root 不会成为问题。由于 SPI 和 GPIO,nodejs 插件需要 root 权限。
我目前正在尝试使用 nbind with the universal example 编写 C++ NodeJS 插件。构建和 运行 示例完美运行。现在我有两个问题,第一个与一般调试有关,第二个与我的问题有关。
我添加了 RF24 库。构造一个 RF24 object 也可以,但是在 Nodejs returns 中调用例如 getChannel()
或 printDetails()
函数只是
terminated called after throwing an instance of 'int'
npm ERR! Test failed. See above for more details
我如何才能从错误中获取更多详细信息,例如文件和行号?我尝试添加 node-gyp configure --debug build --debug
标志,但构建也只生成一个 Release 文件夹。
我的构建命令如下,如通用示例中所建议的那样。
"build:native": "autogypi -r build && node-gyp -C build/native configure --debug build --debug && copyasm build/native dist"
我正在构建 RPi 零 W (Arm v6)。我当前的 binding.gyp 位于 。/build/native 看起来如下
{
"targets": [
{
"includes": [ "../auto.gypi" ],
"sources": [
"../../src/example.cpp",
"../../libs/RF24-master/RF24.cpp",
"../../libs/RF24-master/utility/RPi/bcm2835.cpp",
"../../libs/RF24-master/utility/RPi/interrupt.cpp",
"../../libs/RF24-master/utility/RPi/spi.cpp"
],
"include_dirs": [
"../../src",
"../../libs/RF24-master"
],
"cflags": [
"-std=c++11",
"-fpermissive"
],
"cflags_cc!": [ "-fno-rtti" ]
}
],
"includes": [
"../auto-top.gypi"
]
}
简化后的程序 example.cpp
看起来像
#include "RF24.h"
#include "example.h"
Example::Example(uint16_t cePin, uint16_t spiBus): cePin(cePin), spiBus(spiBus) {
this->radio = new RF24(cePin, spiBus);
}
uint8_t Example::getChannel() {
return this->radio->getChannel();
}
而对应的headerexample.h
看起来像
#ifndef EXAMPLE_H
#define EXAMPLE_H
class Example{
uint8_t cePin = 22, spiBus = 0;
RF24* radio;
public:
Example(uint16_t cePin, uint16_t spiBus);
uint8_t getChannel();
};
#endif
#include "nbind/nbind.h"
NBIND_CLASS(Example) {
construct<uint8_t, uint8_t>();
method(getChannel);
}
所以有两个问题
- 一般且更重要:如何为 nbind c++ 插件获得更舒适的调试选项?
- 更具体地针对我的问题并与 RF24 相关:为什么每次调用 RF24 函数时都会出现该错误?
第一个问题我找到了答案。 NodeJS 在 gdb 下运行良好。这样做
sudo gdb node
> run myscript.js
打印以下更详细的错误
Thread 1 "node" received signal SIGSEGV, Segmentation fault.
0xb4c15ff8 in bcm2835_peri_read () from /usr/local/lib/librf24.so.1
如果周围有人知道发生了什么或对如何进一步挖掘有想法,不客气。我使用 RF24 脚本创建共享库,而不是使用 node-gyp 构建它。它产生的错误完全一样。
编辑:我首先在没有 nodejs 的情况下构建了一个用于测试目的的解决方法。它在授予程序 root 权限时有效。由于它是一个独立的 rasbpi,没有连接到任何网络,root 不会成为问题。由于 SPI 和 GPIO,nodejs 插件需要 root 权限。