【vscode环境配置系列】vscode远程debug配置

VSCODE debug环境配置

插件安装

安装C/C++, C/C++ Runner

配置文件

在项目下建立.vscode文件夹,然后分别建立c_cpp_properties.json, launch.json,tasks.json,内容如下:

c_cpp_properties.json:

bash 复制代码
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "llvm-test/llvm-10.0/include",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "llvm-test/llvm-10.0/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json: (注意,debug时可以选择gdb/lldb,lldb需要安装额外插件)

bash 复制代码
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "preLaunchTask": "clang build active file",
      "setupCommands": [
          {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
          },
          {
              "description": "Set Disassembly Flavor to Intel",
              "text": "-gdb-set disassembly-flavor intel",
              "ignoreFailures": true
          }
      ]
    },

    {
      "name": "C/C++: Clang Launch (GDB)",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "preLaunchTask": "clang build active file",
      "setupCommands": [
          {
              "description": "Enable pretty-printing for gdb",
              "text": "-enable-pretty-printing",
              "ignoreFailures": true
          }
      ]
    }
  ]
}

tasks.json:

bash 复制代码
{
  "version": "2.0.0",
  "tasks": [
      {
          "type": "shell",
          "label": "clang build active file",
          "command": "llvm-test/llvm-10.0/bin/clang++",
          "args": [
              "-g", "-O3",
              "${file}",
              "-I/llvm-test/llvm-10.0/include",
              "-std=c++14",   "-fno-exceptions", "-fno-rtti", "-D_GNU_SOURCE", "-D__STDC_CONSTANT_MACROS", "-D__STDC_FORMAT_MACROS", "-D__STDC_LIMIT_MACROS",
              "-L/llvm-test/llvm-10.0/lib",
              "-lLLVMCore", "-lLLVMRemarks", "-lLLVMBitstreamReader", "-lLLVMBinaryFormat", "-lLLVMSupport", "-lLLVMDemangle",
              "-lrt", "-ldl", "-ltinfo", "-lpthread", "-lm",
              "-o",
              "${fileDirname}/${fileBasenameNoExtension}"
          ],
          "options": {
              "cwd": "${workspaceFolder}"
          },
          "problemMatcher": [
              "$gcc"
          ],
          "group": {
              "kind": "build",
              "isDefault": true
          }
      }
  ]
}

需要额外注意的是,lanch.json中通过"preLaunchTask": "clang build active file",预定义了debug之前需要进行的task,它巧妙地通过label "clang build active file"与task.json中的label进行关联,以在每次debug前重新编译。

debug

相关推荐
Eiceblue1 小时前
通过Python 调整Excel行高、列宽
开发语言·vscode·python·pycharm·excel
i_阿文1 小时前
如何在vscode 中打开新文件不覆盖上一个窗口
ide·vscode·编辑器
视觉小萌新2 小时前
VScode+opencv——关于opencv多张图片拼接成一张图片的算法
vscode·opencv·算法
ahadee3 小时前
蓝桥杯每日真题 - 第10天
c语言·vscode·算法·蓝桥杯
红中马喽9 小时前
JS学习日记(webAPI—DOM)
开发语言·前端·javascript·笔记·vscode·学习
jieshenai13 小时前
使用VSCode远程连接服务器并解决Neo4j无法登陆问题
服务器·vscode·neo4j
ahadee14 小时前
蓝桥杯每日真题 - 第11天
c语言·vscode·算法·蓝桥杯
ahadee18 小时前
蓝桥杯每日真题 - 第7天
c++·vscode·算法·蓝桥杯
牙买加_小杨21 小时前
用vscode编写verilog时,如何有信号定义提示、信号定义跳转(go to definition)、模块跳转这些功能
ide·vscode·编辑器