How to interpret backtrace addresses for debugging with GDB
Asked Answered
D

2

8

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?

Danika answered 10/4, 2012 at 13:40 Comment(0)
C
10

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.

Cosette answered 10/4, 2012 at 14:15 Comment(1)
debug-file-directory is for GDB, but I ment getting backtrace with symbols without attaching GDB. How to make sure backtrace_symbols() gets all the symbol data? Would placing .debug file be sufficient? These crashes are rare, so I can't just reproduce them in mine development environment.Danika
P
0

If you have libQTScript compiled with debug-symbols you will get a better backtrace with function names and parameter values. I don't know exactly how to extract the same information without debug symbols (although it should be possible if you have the correct map-file or symbol-table file of libQTScript).

But the easy way is to install libqt with debug symbols and run the backtrace again. If both the stripped and debug libs are installed and gdb chooses the stripped one, try to point gdb to the debug libs with LD_LIBRARY_PATH=path/to/debug/libs. (see this answer for another method to set the path How do I prepend a directory the library path when loading a core file in gdb on Linux)

Pleadings answered 10/4, 2012 at 13:46 Comment(3)
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?Danika
You can tell gdb to use that file as symbol table. Try the command add-symbol-file from inside gdb and see if it works. Then type bt again for backtrace.Pleadings
The add-symbol-file wants a memory address as argument. I think you can get the address by examining the output of the command: info sharedlibrary (start debugging, then issue the info command).Pleadings

© 2022 - 2024 — McMap. All rights reserved.