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