Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 777
Vincas Dargis Avatar asked Apr 10 '12 13:04

Vincas Dargis


People also ask

How do you read a GDB backtrace?

To display the backtrace for several or all of the threads, use the command thread apply (see thread apply). For example, if you type thread apply all backtrace , gdb will display the backtrace for all the threads; this is handy when you debug a core dump of a multi-threaded program.

How do you analyze backtrace?

A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack. Print a backtrace of the entire stack: one line per frame for all frames in the stack.

How do I use backtrace code?

A backtrace is a list of the function calls that are currently active in a thread. The usual way to inspect a backtrace of a program is to use an external debugger such as gdb. However, sometimes it is useful to obtain a backtrace programmatically from within a program, e.g., for the purposes of logging or diagnostics.

What are debugging symbols in GDB?

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like: Program instruction ⇒ item name, item type, original file, line number defined.


1 Answers

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.

like image 168
Employed Russian Avatar answered Oct 21 '22 11:10

Employed Russian