【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

相关推荐
o(╥﹏╥)3 小时前
在 Ubuntu 上安装 VS Code
linux·运维·vscode·ubuntu·vs
18号房客4 小时前
macOS开发环境配置与应用开发教程(一)
vscode·macos·visualstudio·eclipse·intellij-idea·phpstorm·visual studio
weixin_423196175 小时前
VSCode+WSL作为IDE开发和管理深度学习项目
ide·vscode·编辑器
乐闻x5 小时前
VSCode 插件开发实战(八):创建和管理任务 Task
ide·vscode·编辑器
带电的小王1 天前
VSCode:VSCode安装 -- 最简洁的VSCode安装教程
ide·vscode·编辑器
sg_knight1 天前
VSCode如何修改默认扩展路径和用户文件夹目录到D盘
前端·ide·vscode·编辑器·web
GPT祖弘1 天前
【VScode】第三方GPT编程工具-CodeMoss安装教程
ide·vscode·gpt
乐闻x1 天前
VSCode 插件开发实战(五):实现新语言支持和语法高亮
ide·vscode·编辑器
Dontla1 天前
vscode怎么设置anaconda python解释器(anaconda解释器、vscode解释器)
ide·vscode·python
乐闻x1 天前
VSCode 插件开发实战(六):配置自定义状态栏
ide·vscode·编辑器