Windows下VSCode中GDB调试器执行Step Over后停止响应
C++调试器Step Over卡顿无响应问题
问题详情
在Windows环境下,使用VS Code 1.93.1、GDB 15.1、g++ 14.2.0开发C++程序时,设置断点后点击Step Over按钮,调试器会停止响应但不会终止。已多次重装编译器和调试器,其他调试功能正常。
复现条件
在以下代码的第8行设置断点,执行Step Over即可触发问题:
#include <bits/stdc++.h> using namespace std; int mod (int b, int p, int m) { if (p==0) return 1; if (p%2==0) // 在此行设置断点 { int r = mod(b,p/2,m); return (r*r)%m; } else { return (b%m*mod(b,p-1,m))%m; } } int main() { int T; scanf("%d", &T); while (T--) { int b,p,m; cin >> b >> p >> m; printf("%d\n", mod(b,p,m)); } }
输入示例
1 18132 17 17
配置文件
tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe build active file", "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
launch.json
{ "configurations": [ { "name": "C/C++: g++.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe build active file" } ], "version": "2.0.0" }
解决建议
- 切换到外部控制台调试:将
launch.json中的externalConsole改为true,避免内置控制台的交互冲突。 - 降级GDB版本:尝试使用GDB 14.x版本,新版本可能存在与VS Code调试插件的兼容性问题。
- 关闭美化打印功能:注释掉
setupCommands中的-enable-pretty-printing命令,该功能在递归场景下可能导致卡顿。 - 增强调试信息:编译时将
-g替换为-ggdb3,生成更详细的调试数据,提升调试器识别度。 - 更新C/C扩展:确保VS Code的C/C插件(ms-vscode.cpptools)为最新版本,修复已知bug。
内容的提问来源于stack exchange,提问作者Termin
相关产品推荐
相关产品推荐

