【问题标题】:Debugging nodejs nbind c++ addons调试节点js绑定c++插件
【发布时间】:2018-05-25 12:13:17
【问题描述】:

我目前正在尝试使用nbinduniversal example 编写一个C++ NodeJS 插件。构建和运行该示例可以完美运行。现在我有两个问题,第一个与一般调试有关,第二个与我的问题有关。

我添加了 RF24 库。构造一个 RF24 对象也可以,但是在 Nodejs 中调用例如 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 Zero W (Arm v6)。我当前位于 ./build/native 中的 binding.gyp 如下所示

{
  "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 函数调用中都会出现该错误?

【问题讨论】:

    标签: c++ node.js debugging node-gyp


    【解决方案1】:

    对于第一个问题,我得到了解决方案。 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 权限。

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      相关资源
      最近更新 更多