The backtrace() provides complete stacktrace. Using
backtrace_symbols(), stacktrace can be printed as:
./build/gtest(func1_name+0x129) [0x80484bd]
./build/gtest(func2_name+0x193) [0x8048527]
/lib/libc.so.6(__libc_start_main+0xbd) [0x400483c1]
here,
the first part:name of the binary
func1_name: mangelled func name in case of C++
0x129: is the offset in the function
0x80484bd: Actual address
if 0x80484bd is passed to addr2line, it returns filename:line no.
However, line no. is always the next line from the call.
so, if
23 foo()
24
25 int i=0;
I am expecting line no. of foo(), but it returns line on if int i=0;
Interestingly, gdb also provides same actual address and correct line
no. Therefore, it seems backtrace() is returning correct address. We
need to do something more to get correct line no.
Let me know if you have any ideas about how to get correct line no.
from backtrace() and addr2line.
Thanks,
Vinayak