'gdb error in tui mode only: "During startup program exited"

gdb works fine as long as I don't enter tui mode. For example I have the following c program:

#include <stdio.h>

int mp(int x, int y) {
    int res = 0;
    for (x; x>0; --x) {
        res += y;
    }
    return res;
}

int main() {
    int result = mp(5, 3);
    printf("%d\n", result);
    return 0;
}

I build the program with gcc -g main.c and invoke gdb with gdb .\a.exe. In this case I can debug the program fine using run. But as soon as I enter tui mode with tui enable and issuing the run command, it throws the following error:

(gdb) run
Starting program: C:\Users\justus\Coding\programmieren-in-c\a.exe
During startup program exited with code 0xc0000142.

What is the cause and how do I fix it?

gdb --version
C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 10.2
[...]
gdb


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source