【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

相关推荐
白云千载尽15 小时前
ubuntu环境中安装latex并使用vscode
linux·vscode·ubuntu
你若盛开,清风自来!1 天前
在VSCode中安装jupyter跑.ipynb格式文件
vscode·jupyter·pyathon
大河qu1 天前
IDE/Mermaid + VSCode + Deepseek 生成可视化流程图和UML图
ide·vscode·mermaid·可视化图表·deepseek
LXY202305041 天前
模版语法vscode
ide·vscode·编辑器
循环渐进Forward1 天前
将VsCode变得顺手好用(1
ide·vscode·编辑器
╰⋛⋋⊱⋋翅膀⋌⊰⋌⋚╯1 天前
Windows配置添加右键菜单——在VSCode中打开
ide·windows·vscode
小巷折寒梅,唯影相陪2 天前
【Vscode 使用】集合1
ide·vscode·编辑器
SiYuanFeng2 天前
vscode设置自动换行
ide·vscode·编辑器
Bardb2 天前
06C语言——指针
c语言·vscode
半桔2 天前
C++入门
c语言·开发语言·数据结构·c++·vscode·青少年编程