Search code examples
gdbbacktracedebug-backtrace

How to interpret backtrace addresses for debugging with GDB


I am using backtrace() and backtrace_symbols() to output backtrace on SIGSEGV and other signals in format like this:

0: [0xb750818]
1: /opt/server/libQtScript.so.4(+0x6f42a) [0xb782c42a]
2: /opt/server/libQtScript.so.4(+0x7bffc) [0xb7838ffc]
3: /opt/server/libQtScript.so.4(+0x86946) [0xb7843946]
4: /opt/server/libQtScript.so.4(+0x7c4bc) [0xb78394bc]
5: /opt/server/libQtScript.so.4(+0x86946) [0xb7843946]
6: /opt/server/libQtScript.so.4(+0x9603e) [0xb785303e]
7: /opt/server/libQtScript.so.4(_ZN12QScriptValue4callERKS_RK5QListIS_E+0x2e7) [0xb7891647]

In this particular case, frame #7 is fine for me, though frame 1-6 gives me some kind "+x" addresses.

How to get exact line in disassemble for "+0x6f42a" and other addresses in GDB? And what frame #0, without described module, means?


Solution

  • How to get exact line in disassemble for "+0x6f42a" and other addresses in GDB?

    gdb /opt/server/libQtScript.so.4
    (gdb) x/10i 0x6f42a
    

    Usually you'll want instructions that executed before 0x6f42a, so you'll do this:

    (gdb) x/20i 0x6f42a-30
    

    Ignore the first few instructions: you could be starting disassembly from a middle of one. Usually the disassembly will re-synchronize after a few instructions, and will start showing correct instruction stream after that.

    And what frame #0, without described module, means?

    Your library has been stripped of symbols, so the only symbols you see (e.g. _ZN12QScriptValue4callERKS_RK5QListIS_E) are the externally-visible (aka exported) ones.

    There are libQtScript.so.4.5.2.debug symbol file in QT_SOURCE/lib folder. So maybe I should copy .debug file near executable to get backtrace with full symbols?

    GDB should load symbols from libQtScript.so.4.5.2.debug automatically if you set debug-file-directory to $QT_SOURCE/lib.

    Update:

    I ment getting backtrace with symbols without attaching GDB

    I don't believe there is any support in backtace_symbols() for loading separate debuginfo files.