views:

102

answers:

1

I have a simple c++ program I am trying to debug, but gdb cannot find the object file for the libraries (or no debug info is available), and it does not seem able to find the debug symbols for my executable either.

I am on OSX 10.5.8, with macports, and I compile my code with

g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -I/opt/local/include -L/opt/local/lib -lgsl -static-libstdc++ MCMC-simplex.cpp -o mcmc

(there is only one file, and g++-mp-4.5 is the macports executable for gcc/g++ 4.5 )

When I try running gdb on the resulting executable, I get many error messages (at startup) of the form

warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_gcc45/work/build/i386-apple-darwin9/libgcc/trunctfdf2_s.o" - no debug information available for "../../../gcc-4.5.0/libgcc/../gcc/config/soft-fp/trunctfdf2.c".

which to me indicates that macports has a bug during its build (it seems like gdb is looking for the object files in the temporary build directory).

I should add that when I try to see my programs listing in gdb (the one provided by Apple), it tries to look for a random .s file in /var/tmp, which to me sounds like an assembler file. That is why I say it does not seem able to find the debug symbols for my program either.

When I try MacPorts gdb 7.1, I get

warning: `/var/folders/Xa/XaqHO9PeEC8K-Nrd0L9xWk+++TM/-Tmp-//cc2IvFto.o': can't open to read symbols: No such file or directory. (no debugging symbols found)...done.

and none of the many error messages that Apple's gdb gives out (although the end result is the same).

Has anyone come across this problem, and came up with a solution?

+1  A: 

Unlike other UNIXen, on MacOS the debug info is not linked into the executable. Instead, the executable has a list of object files which were linked into it, and the debugger looks for debug info in these individual object files.

If you remove the object files, then you can't debug.

When you compile and link the executable in "single step", GCC does this:

  1. Create assembly file /tmp/[random-string].s
  2. Assemble it into /tmp/[random-string].o
  3. Link /tmp/[random-string].o with crt0.o, libc, etc. into mcmc executable.
  4. Remove /tmp/[random-string].o and .s

It is that last step which prevents you from debugging.

Solution:

g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -c MCMC-simplex.cpp
g++-mp-4.5 MCMC-simplex.o -lgsl -static-libstdc++ -o mcmc

This will leave MCMC-simplex.o in the current directory, and will allow GDB to find debug info in it.

Employed Russian
Thanks! This enables me to debug my code, but I still get error of the typewarning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_gcc45/work/build/i386-apple-darwin9/libgcc/_powixf2_s.o': can't open to read symbols: No such file or directory.which I guess I should blame on MacPorts.
Marcus P S
It is the same issue as the russian said just that the .o file for the gcc library is not there. Do you want to enter into the gcc libs? You can tell macports to leave the compiler objects around. see macports.conf option portautoclean
Mark