【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

相关推荐
@才华有限公司11 小时前
vscode使用翻译插件分享
ide·vscode·编辑器
小蜗子15 小时前
vscode 侧边文件夹名字体大一点
ide·vscode·编辑器
HIT_Weston15 小时前
149、【OS】【Nuttx】【周边】效果呈现方案解析:VSCode 打开外部链接(二)
vscode·os·nuttx·文档渲染
我先去打把游戏先15 小时前
VSCode通过SSH连接到Ubuntu虚拟机失败“找不到ssh安装”问题解决
笔记·vscode·单片机·嵌入式硬件·学习·ubuntu·ssh
CSND74016 小时前
linux离线环境局域网远程ssh连接vscode
linux·vscode·ssh
UCoding16 小时前
我们来学AI编程 -- vscode开发java
java·vscode·ai编程
dyxal21 小时前
内网windows系统机器通过vscode ssh连接内网服务器,无网络导致的一系列无法正常连接问题
服务器·vscode·ssh
狠活科技1 天前
免登录!免安装ClI,Claude Code官方插件接入API使用教程
人工智能·vscode·ai编程
诗意地回家2 天前
工具: 下载vscode .vsix扩展文件方法
ide·vscode·编辑器
scorpion_V2 天前
VScode 中执行 npm 报错的问题
ide·vscode·npm