c++linuxgcc

Infering the source line number from C++ core dump


I have a stripped down linux system for which i have to cross compile all the applications i need, on another system. These applications core often and the only information i get from it is the function which cored and the instruction offset. If i have no other option, i do an objdump on the executable, and try to guess the source code from the instruction offset and assembly snippets. This is my life.

Note: The applications are cross-compiled using g++ and are stripped down. So gdb have not helped me much

Question: Since the compiler/gcc has converted the source lines to assembly instructions, wouldnt there be some option which would give a correlation between the instruction offset and the line?


Solution

  • Create build with -g, then get symbol map out of it. Save it somewhere (i would recommend saving binary with debugging symbols too - it's easier that way), then strip debugging symbols out (with strip program) and deploy resulting binary to target system. Here is howto: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html

    After it crashes, either restore dump with -g-compiled binary or with release binary and separate debug file. If you have crash address and binary with debugging symbols and you want to map it to source code line - you could use addr2line -e your_binary crash_address instead of gdb.