0

I have downloaded the source of GMP library 5.02, and - as suggested here for maximum debuggability - I ran :

./configure --disable-shared --enable-assert --enable-alloca=debug --host=none CFLAGS=-g

and compiled it with make, then installed the library with make install. I then compiled my program like this: gcc -lgmp -std=c99 -g -c program.c and then I ran : ltrace ./a.out

However I realized that ltrace is not at all invoking the TRACE() functions I can find in the source code. I would like to trace the content that's in TRACE().

How should I go for that? Or is there any other straightforward way of debugging inside the GMP library? (I couldn't figure it out how to do it with gdb, it never wanted to step into gmp_printf)

Thanks.

EDIT: I tried to investigate further, and realized that I couldn't modify the GMP library although I had the sources. I inserted a printf("hello\n"); at the very beginning of the mpz_init2 function which I do call at the beginning of my program, I recompiled all GMP (even after a make clean) re-installed the library with make install, then I compiled and launched my program, but it never printed "hello". I also made sure, I wasn't using another installed GMP library (when I do make uninstall my program cannot compile as it does not find the library). Still, I insisted that gcc looks for the library in the GMP source folder with the -L option.

I don't know what I'm doing wrong :(

Tibor Vass
  • 157
  • 14

1 Answers1

0

Your final compile of a.out is not producing a statically linked a.out executable. So, even though as you state, during compilation of program.c the compiler is using your GMP library, at runtime it is picking up a shared library somewhere. You need to do one of two things:

  1. Compile with -Bstatic (or something similar; check man page for your compiler)
  2. Set the LD_LIBRARY_PATH (or something similar; check 'ld' or 'dyld' man pages)

I think #1 is actually your only choice given that you built only the static version of GMP. For #1 make sure you explicitly provide -L/path/to/gmplib in the compilation of program.c

GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Basically, I ended up doing `gcc program.c -lgmp -L/path/to/gmp` and then it worked. I was able to do printfs in the gmp library, recompile-it and debug like this. However, I find it a bit cumbersome to do it this way. It works, but debugging with gdb would have been much better I guess. – Tibor Vass Apr 26 '12 at 07:44
  • So the original problem is solved because you are compiling the proper GMP library in [Check mark for me!] and seeing your edits to GMP. And now you have another problem that the debugger doesn't work? Are you using GDB with the '-d' option to tell GDB where to search for source code files? Like 'gdb -d /path/to/gmpsrc a.out' – GoZoner Apr 26 '12 at 13:23