vscode配置c/c++调试
时间: 2023-10-08 13:13:05 浏览: 257
你可以按照以下步骤在VS Code中配置C/C++调试:
1. 确保你已经安装了C/C++扩展。打开VS Code,点击左侧的扩展图标(四个方块组成的图标),搜索并安装"C/C++"扩展。
2. 在你的C/C++项目文件夹中创建一个名为`.vscode`的文件夹(如果不存在),然后在该文件夹中创建一个名为`launch.json`的文件。你可以使用下面的配置作为模板,并根据你的项目进行相应的修改:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
```
3. 在`"program"`字段中,`${fileDirname}/${fileBasenameNoExtension}`指定了要调试的C/C++源文件路径。
4. 安装并配置GDB调试器。GDB是一个强大的命令行调试器,用于与C/C++程序进行交互。确保你已经安装了GDB,并将其添加到系统路径中。
5. 打开你的C/C++源文件,并在你想要设置断点的行上点击左侧的行号。这将在该行上设置一个红色的圆点,表示断点已成功设置。
6. 点击VS Code左侧的调试图标(类似于一个虫子),然后点击上方的绿色播放按钮(启动调试)。这将启动调试器,并在你设置的断点处暂停程序执行。
7. 使用调试器中提供的按钮和命令来控制程序的执行,例如继续、单步调试、查看变量值等。
希望这些步骤可以帮助你在VS Code中成功配置C/C++调试!如果有任何问题,请随时向我提问。
阅读全文
相关推荐


















