VS Code中Ctrl+F5(不调试运行)C/C++代码仍启动GDB调试器问题求助
问题根因
该问题多为VS Code全局运行开关被误关闭,或是C/C++扩展无法正确区分调试/运行指令导致,可按以下步骤修复:
修复步骤
- 检查全局运行开关
打开VS Code设置(快捷键Ctrl+,),搜索debug.allowRunWithoutDebugging,确认对应选项的复选框处于勾选状态。该选项是「不调试运行」功能的总开关,关闭后所有场景下的Ctrl+F5都会触发调试流程。 - 调整launch.json配置
你当前仅配置了调试用的cppdbg规则,部分版本的C/C++扩展无法自动为运行指令追加免调试标记,可新增一套专门的运行配置,修改后的完整配置参考:
{ "version": "0.2.0", "configurations": [ { "name": "g++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++ build active file", "miDebuggerPath": "/usr/bin/gdb" }, { "name": "g++ build and run active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "preLaunchTask": "g++ build active file", "noDebug": true } ] }
修改完成后,在运行面板的下拉列表中选择对应配置即可:F5启动调试选带debug的配置,Ctrl+F5运行选带run的配置,后续触发快捷键时会自动匹配当前选中的配置。
3. 重置C/C扩展配置
如果完成前两步后问题仍然存在,右键扩展栏的「C/C」扩展,选择「扩展设置」,点击页面右上角的重置图标恢复所有默认配置,重启VS Code后即可恢复正常。
内容的提问来源于stack exchange,提问作者Jan
相关产品推荐
相关产品推荐

