cmake + vscode调试
cmake里设置程序编译为debug模式
这种方法每次会执行一次 cmake .. 和 make
tasks.json
// tasks.json
{
"version": "2.0.0",
"options": {
"cwd": "xxx/build" //build文件的位置
},
"tasks": [
{
"type": "shell",
"label": "cmake", //执行cmake..
"command": "cmake",
"args": [
".."
]
},
{
"label": "make", //执行make
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": []
},
{
"label": "Build", //把上面的两个动作绑定,命名为Build
"dependsOrder": "sequence",
"dependsOn": [
"cmake",
"make"
]
}
]
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 管道启动",
"type": "cppdbg",
"request": "launch",
// 指定可执行文件的路径和名称
"program": "xxx", //可执行程序的目录
"args": ["-t", "10", "-p", "8888"],// 执行可执行程序输入的参数
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "Build",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
也可以先编译出可执行程序,然后运行,使用附加模式进行调试。