1

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?

2
  • Why .so rather than .dll? Not sure if it matters. Or perhaps this trick doesn't work on Windows in the first place, and you need a main(). Commented Aug 2, 2023 at 21:10
  • You need to compile with -g and possibly -ggdb Commented Aug 2, 2023 at 21:17

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a ton - that was it; I went over to having an exe, and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.