While debugging C/C++ files with Visual Studio Code, the program flow enters to crtexe.c when press 'step over' or 'step into' key from the line with '}' of main function.
However, when continue debugging in crtexe.c, the flow just stops at if (!managedapp)
line and doesn't go back to main() function.
If I press 'step out' key in the line '}' of main(), then a error message "Unable to step out. Operation failed with error code 0x80004004" comes out.
I tested same code in another IDE, like CLion or NetBeans, but these issues aren't occurred.
I'm using MinGW-w64 GCC and GDB. How to I resolve this issue?
Sample Code(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;
}
launch.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:/"
}
}
]
}
From the image I see the call before the condition:
mainret = main(argc, argv);
You declared the main function:
int main();
Since the program was successfully linked the program is in C language. Thus the stack frame is corrupted after main
exited. On Windows it is a default call convention that callee function is responsible for cleaning up function arguments from the stack and caller gets invalid stack frame (stack register) after main
. You should declare main function properly:
int main(int argc, char** argv);
User contributions licensed under CC BY-SA 3.0