在用Visual Studio Code调试C/C++文件时,程序流从main函数的'}'行按'step over'或'step into'键进入crtexe.c。
但是,当在 crtexe.c 中继续调试时,流程仅在 if (!managedapp)
行停止并且不会返回到 main() 函数。
如果我在 main() 的 '}' 行中按下 'step out' 键,则会出现错误消息 “无法跳出。操作失败,错误代码为 0x80004004”。
我在另一个 IDE(如 CLion 或 NetBeans)中测试了相同的代码,但没有出现这些问题。
我正在使用 MinGW-w64 GCC 和 GDB。我该如何解决这个问题?
示例代码(main.c):
#include <stdio.h>
int main()
{
printf("Call main()\n");
int num1 = 1;
int num2 = 20;
int num3 = num1 + num2;
printf("%d\n", num3);
return 0;
}
启动.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "GDB Launch",
"type": "cppdbg",
"request": "launch",
"program": "C:/Users/.../main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:/Users/...",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys2/mingw64/bin/gdb.exe",
"sourceFileMap": {
"/c/": "C:/"
}
}
]
}
最佳答案
从图像中我看到条件之前的调用:
mainret = main(argc, argv);
你声明了主函数:
int main();
由于程序链接成功,程序是C语言的。因此,堆栈帧在 main
退出后损坏。在 Windows 上,默认调用约定是被调用函数负责从堆栈中清除函数参数,并且调用方在 main
之后获取无效堆栈帧(堆栈寄存器)。您应该正确声明 main 函数:
int main(int argc, char** argv);
关于crtexe.c - 关于在 VSCode 中调试 C/C++ 文件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50083082/