nodejs在Linux下c++插件单步调试

nodejs在Linux下c++插件单步调试


如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033

环境:

Linux : ubuntu 16.04
nodejs : 10.15.2
node-gyp : 5.0.3
vs code : 1.36.1
vs code plugin(C/C++ ms-vscode.cpptools) : 0.24.1
GCC : 5.4.0
Python : 2.7

1. 安装nodejs

略过

参考:nodejs在Linux下的安装

2.安装node-gyp

略过

参考:nodejs在Linux下c++插件运行-安装node-gyp


node-gyp cmake-js node-addon-api离线安装工具【2022-03-16 add】

git clone https://github.com/itas109/node-gyp-offline-install

git clone https://gitee.com/itas109/node-gyp-offline-install

下载windows离线包

$ node index.js -p win32 -a x64 -v 16.14.0 -m https://npm.taobao.org/mirrors/node/

下载linux离线包

$ node index.js -p linux -a x64 -v 16.14.0 -m https://npm.taobao.org/mirrors/node/

3.安装vs code

略过

4.安装c++插件

vs code应用商店所有C/C++,其中Microsoft发布的就是,全名C/C++ for Visual Studio Code

源码:
https://github.com/microsoft/vscode-cpptools

5.代码

  • hello.cc
#include <node.h>
#include <v8.h>

using namespace v8;

void Method(const v8::FunctionCallbackInfo<Value>& args) 
{
  Isolate* isolate = Isolate::GetCurrent();
  HandleScope scope(isolate);
  args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}

void Init(Handle<Object> exports) 
{
  Isolate* isolate = Isolate::GetCurrent();
  exports->Set(String::NewFromUtf8(isolate, "hello"),
      FunctionTemplate::New(isolate, Method)->GetFunction());

}

NODE_MODULE(hello, Init)
  • binding.gyp
{
  "targets": [
    {
      "target_name": "hello",
      "sources": [ "hello.cc" ]
    }
  ]
}
  • hello.js
var addon = require('./build/Debug/hello.node');

console.log(addon.hello()); // 'world'

6.单步调试

6.1 tasks.json配置

配置任务可以自动重新编译.node

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "autobuild",
            "command": "node-gyp",
            "args": ["build"]
        }
    ]
}

6.2 lauch.json配置

通过lauch.json(调试 - 打开配置)来配置调试参数

{
    "version": "0.2.0",
    "configurations": [
        {
            //"type": "node",
            //"request": "launch",
            //"name": "Launch Program",
            // "program": "${workspaceFolder}/hello.js"
            "name": "C++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/usr/local/bin/node",  //node路径
            "args": ["${workspaceFolder}/hello.js"], //js路径
            "preLaunchTask": "autobuild", //配合tasks.json自动编译
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "linux": {
                "MIMode": "gdb",
                "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
            }
        }
    ]
}

6.3 调试

打断点,F5开始调试即可


觉得文章对你有帮助,可以扫描二维码捐赠给博主,谢谢!
在这里插入图片描述
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033


License

License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎


Reference:
1.http://nodejs.cn/api/addons.html
2.https://www.jianshu.com/p/8a9f4304557c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

itas109

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值