1. 安装c/c++插件

2. 编写debug配置文件
- 点击debug按钮,然后点击 create a launch.json file 链接 ,如下图所示

2, vs code 会创建 launch.json 文件

- 点击 add configuration 按钮

- 点击 gdb launch 后, vs code会自动补全配置

补全后如下所示
1{
2 // Use IntelliSense to learn about possible attributes.
3 // Hover to view descriptions of existing attributes.
4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 "version": "0.2.0",
6 "configurations": [
7 {
8 "name": "(gdb) Launch",
9 "type": "cppdbg",
10 "request": "launch",
11 "program": "enter program name, for example ${workspaceFolder}/a.out",
12 "args": [],
13 "stopAtEntry": false,
14 "cwd": "${fileDirname}",
15 "environment": [],
16 "externalConsole": false,
17 "MIMode": "gdb",
18 "setupCommands": [
19 {
20 "description": "Enable pretty-printing for gdb",
21 "text": "-enable-pretty-printing",
22 "ignoreFailures": true
23 },
24 {
25 "description": "Set Disassembly Flavor to Intel",
26 "text": "-gdb-set disassembly-flavor intel",
27 "ignoreFailures": true
28 }
29 ]
30 }
31
32 ]
33}
- 在json中设置好程序的路径和参数和程序工作路径
1{
2 "program": "程序路径",
3 "args": ["参数1", "参数2", "..."],
4 "cwd":"程序工作路径"
5}
- 点击菜单栏的Run菜单下面的Start Debugging 调试即可

- 使用技巧
- 打断点后,鼠标右键点击断点可以编辑条件断点
- debug console 中 输入 -exec <gdb command> 可以执行gdb调试命令