VSCODE debug环境配置
- 插件安装
- 配置文件
- debug
插件安装
安装C/C++, C/C++ Runner
配置文件
在项目下建立.vscode文件夹,然后分别建立c_cpp_properties.json, launch.json,tasks.json,内容如下:
c_cpp_properties.json:
{
"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需要安装额外插件)
{
"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:
{
"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前重新编译。