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
略过
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