实施以下步骤前,应确保 vscode 已安装对应插件,如 C/C++、C++ Intellisense、CMake、CMake Tools 等。
创建
launch.json文件- 按下
F5键 - 选择
C++(GDB/LLDB) - 选择
Default Configuration,生成launch.json文件 自定义
launch.json文件中的program项为可执行文件路径,一般以工作空间路径${workspaceFolder}为起始。其它配置项可视具体情况而定:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27{
// 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/CtApLaneFusion_EP21H2_SW025_x86_debug",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- 按下
程序中指定位置打断点
点击 vscode 下方工具栏的
CMake项,选择Debug模式点击 vscode 下方工具栏的
Build项,构建包含调试信息的可执行文件按下
F5键,进入Debug模式,vscode 侧边栏Debug窗口可以看到变量值、回调栈(Call Stack)等信息vscode 顶部会出现
Debug控制工具栏:F5:ContinueF10:Step OverF11:Step IntoShift + F11:Step OutCtrl + Shift + F5:RestartShift + F5:Stop