crtexe.c - Issue about debugging C/C++ files in VSCode

1

enter image description here

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.

enter image description here

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:/"
            }
        }
    ]
}
c
visual-studio-code
asked on Stack Overflow Apr 29, 2018 by EnDelt64 • edited Apr 29, 2018 by S.M.

1 Answer

0

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);
answered on Stack Overflow Apr 29, 2018 by S.M. • edited Apr 29, 2018 by S.M.

User contributions licensed under CC BY-SA 3.0