tags:

views:

66

answers:

1

I am trying to debug a core file generated by a C++ binary without debug symbols. In order to do effective debugging, I need the debug symbols, so I've recompiled the same code with -g option in order to generate debug symbols in the recompiled binary. Can I now debug the same core file generated by the first binary (without debug symbols) using the second binary (has debug symbols, everything else is same) ?

Thanks a lot !

+4  A: 

If you compiled original executable with e.g. g++ -O2 ..., you can not (as you probably have discovered) use a new executable built with g++ -g ... to debug the core -- GDB needs the symbols to match, and they would not (due to difference in optimization levels).

What you can do is build the new executable with the same optimization as the original, but also with debug symbols: g++ -O2 -g ....

After you've built a new executable, run nm old.a.out > old.nm, nm new.a.out > new.nm and compare the outputs. They should be identical or very very close.

If they are, you should be able to debug a core produced by old.a.out using new.a.out.

In the future, you should always build your executable with debug symbols, then keep the full copy, but ship a copy without debug info:

cp a.out a.out.debug
strip --strip-debug a.out
# a.out is now good to send to customers
# keep a.out.debug for future debugging
Employed Russian