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

3.安装vs code

略过

4.安装c++插件

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

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

5.代码

#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

©️2020 CSDN 皮肤主题: 成长之路 设计师:Amelia_0503 返回首页