launch.json
首先进入调试环境,系统自动生成launch.json文件 ,对系统自动生成的json文件进行修改
program和preLaunchTask两个地方需要修改成自己的执行文件目录以及和tasks.json中的label对应的“Build”
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/build/my_cmake_exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
点击 Terminal 生成第二个json文件
将以下代码替换掉系统自动生成的内容
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence", // 按列出的顺序执行任务依赖项
"dependsOn":[
"cmake",
"make"
]
}
]
}
因为这里的label是对应Build 所以对launch.json文件中的preLaunchTask进行修改 (已经修改了)
到此为主 两个json文件都已经配置好了
打开main.cpp 进行调试环节 按F5键开始调试,会自动编译最新的文件
测试自动编译的效果