Search code examples
cgdbmingw-w64msys2

How can I debug functions in shared object libraries with GDB in MINGW64?


I'm trying to reconstruct How can I debug functions in shared object libraries with GDB? answer https://stackoverflow.com/a/59690953/6197439 in MINGW64 gdb - and I cannot:

$ cat add.c
long add(long x, long y) {
    return x + y;
}

$ gcc -shared -o libadd.so -fPIC add.c

$ gdb
GNU gdb (GDB) 13.2
...

(gdb) file libadd.so
Reading symbols from libadd.so...

(gdb) starti
Starting program: C:\msys64\tmp\libadd.so
Error creating process C:\msys64\tmp\libadd.so, (error 193: unknown win32 error (193))

So, how would I go about calling a function in MINGW64 gdb, in an .so file like this one, compiled with MINGW64 gcc?


Solution

  • MINGW64 gdb - and I cannot:

    Your problem is not that you can't set a breakpoint; your problem is that you are trying to run a .so file.

    You need an actual executable (which either depends on your .so or loads it dynamically).

    The upvoted answer is wrong. The other answer is correct.