visual studio code离线安装C&C++调试插件ms-vscode.cpptools调试nodejs c++插件

visual studio code离线安装C&C++调试插件ms-vscode.cpptools调试nodejs c++插件


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

前言

编写C/C++ 代码一般是离不开调试环境的,那么在没有互联网的机器上如何调试C/C++代码呢?以下将介绍如何解决这个问题。

1.下载vscode离线插件

下载地址:

https://github.com/microsoft/vscode-cpptools/releases

https://hub.fastgit.org/microsoft/vscode-cpptools/releases

安装包平台
cpptools-linux.vsixLinux 64-bit
cpptools-linux-armhf.vsixLinux ARM 32-bit
cpptools-linux-aarch64.vsixLinux ARM 64-bit
cpptools-osx.vsixmacOS
cpptools-win32.vsixWindows 64-bit & 32-bit
cpptools-win-arm64.vsixWindows ARM64
cpptools-linux32.vsixLinux 32-bit (0.27.0版本开始支持)

注意:
cpptools对vscode版本有要求。

cpptoolsVS Code
1.2.2(2021-02-26)1.52.0及以上
1.1.3(2020-12-04)1.49.0及以上
1.0.1(2020-09-22)1.44.0及以上

2. 安装离线插件

Linux

code --install-extension cpptools-linux.vsix

windows

code --install-extension cpptools-win32.vsix

3. 安装必要调试软件

3.1 Linux

gcc g++ gdb

3.2 windows

visual studio

https://code.visualstudio.com/docs/cpp/config-msvc
https://blog.csdn.net/heilone6688/article/details/91050508

MinGW-w64

4.测试代码

代码目录结构:

.
+--- .vscode
|   +--- launch.json
+--- addon.cc
+--- binding.gyp
+--- test.js

4.1 C++代码addon.cc

// addon.cc

// node v12.13.0

#include <node.h>

namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;

using v8::Number;

void helloMethod(const FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  
  args.GetReturnValue().Set(
      String::NewFromUtf8(isolate, "hello world", NewStringType::kNormal)
          .ToLocalChecked());
}

void Initialize(Local<Object> exports) {
  NODE_SET_METHOD(exports, "hello", helloMethod);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)

} // namespace demo

4.2 js代码test.js

//test.js

var addon = require('./build/Debug/addon.node');

console.log('JS output : ',addon.hello()); // hello world

4.3 编译C++生成.node

node-gyp编译文件binding.gyp

{
  'targets': [
    {
      'target_name': 'addon',
      'sources': [ 'addon.cc' ]
    }
  ]
}

使用node-gyp编译

node-gyp configure build --debug

这里使用–debug是为了可以进行单步调试

4.4 运行js文件test.js

$ node test.js 
JS output :  hello world

5.配置vscode调试.node

启动配置文件.vscode/launch.json (F5 -> Select Environment -> C++(GDB/LLDB))

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "/usr/local/bin/node",
            "args": ["${workspaceFolder}/test.js"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

调试C++代码

在C++源码中打断点之后,按F5可以调试.node的C++源码

License

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

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


Reference:
NULL

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

itas109

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

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

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

打赏作者

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

抵扣说明:

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

余额充值