VSCode调试C程序故障求助:无法断点/变量不显示
VSCode调试C程序故障排查请求
已安装微软C/C++ Intellisense v1.16.3扩展,调试C程序时遇到两个问题:
- 调试时“Variables”面板无法显示变量
- 无法使用断点,点击“Debug C/C++ File”后程序卡顿并退出
操作流程
- 终端>运行生成任务
- 在.c源文件中设置断点
- 运行“Debug C/C++ File”
测试代码(input_validation.c)
// input_validation.c #include <stdio.h> int main(void) { int num = 0; printf("Enter a number between 1-10: "); scanf("%d", &num); if (num > 0 && num <= 10) printf("Input accepted!\n"); else printf("Error: number must be between 1-10.\n"); return 0; }
.vscode配置文件
1. launch.json
{ "configurations": [ { "name": "C/C++: gcc.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:\\cygwin64\\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++: gcc.exe build active file" } ], "version": "2.0.0" }
2. tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\cygwin64\\bin\\gcc.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" }
3. c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:\\cygwin64\\bin\\gcc.exe", "cStandard": "c99", "intelliSenseMode": "${default}" } ], "version": 4 }
使用的工具版本(Cygwin环境)
PS C:\Users\leeyo\Desktop\Udemy\C> gdb --version GNU gdb (GDB) (Cygwin 12.1-1) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. PS C:\Users\leeyo\Desktop\Udemy\C> gcc --version gcc (GCC) 11.4.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. PS C:\Users\leeyo\Desktop\Udemy\C> which gcc /usr/bin/gcc PS C:\Users\leeyo\Desktop\Udemy\C> which gdb /usr/bin/gdb
调试输出
调试控制台输出截图:
期望与实际表现
期望
- 能够设置断点
- 能够单步执行代码
- 能够在“运行和调试”视图中查看变量
实际表现
- 以上功能均无法正常工作
内容的提问来源于stack exchange,提问作者togomi
相关产品推荐
相关产品推荐

