Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I debug a core generated by a C++ binary without debug symbols using the same binary recompiled with debug symbols

Tags:

c++

gdb

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 !

like image 463
Abhishek Rai Avatar asked Sep 24 '10 19:09

Abhishek Rai


People also ask

How do I debug a core file without symbols?

Try running a "pmap" against the core file (if hp/ux has this tool). This should report the starting addresses of all modules in the core file. With this info, you should be able to take the address of the failure location and figure out what library crashed.

What are debug symbols used for?

A set of special characters generated when a program is compiled and containing information about the location of variables and functions in the resulting binary file, plus other service information. This data set can be used for step-by-step debugging of the program or examining third-party code.

How do I add debug symbols?

Enabling debug symbolsChoose Project > Properties > QNX C/C++ Project. In the Build Variants tab, expand the listings for all architectural variants that you want to build. Check the debug boxes for all variants that you want to debug. Click OK to confirm the settings and exit the properties window.

How do you know if binary is debug or Release?

If it is debug, it will display all the actual source code call you do. If it is release, it will just display the founded symbol from the symbol table.


1 Answers

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
like image 160
Employed Russian Avatar answered Oct 16 '22 08:10

Employed Russian