Using BFD for generating detailed backtrace

Roberto Fichera kernel@tekno-soft.it
Mon May 17 17:22:00 GMT 2010


Hi All in the list,

I'm actually trying to write a glibc's backtrace_symbols() replacement
to improve the
backtrace readability of my applications. So far so good I started from the
addr2line utility contained within binutils in order to came into a function
that I could plug in my backtrace implementation. So, the implementation
at the end works ok for all the static binaries, but doesn't work for
shared library.
So my question is: how can I handle symbol resolution so such dynamic
object?
I guess the problem could be solved once I'm able to pass the right
offsets to the
bfd_find_nearest_line() function. Than the big question is how can I
convert the
addresses returned by the backtrace() function into the shared library
offset so that the bfd_find_nearest_line() could find the symbol's
information?

Thanks in advance.

P.S: Please reply me in CC since I'm not subscribed to the list.

Below you find the output of my test application

stack trace:
#0 0x40378e in print_stacktrace at /data/roberto/backtrace/demagle3.c++:226
#1 0x4039e4 in Nu::Alpha<int>::Beta::func(int) at /data/roberto/backtrace/demagle3.c++:289
#2 0x403983 in main at /data/roberto/backtrace/demagle3.c++:311
#3 0x355181eb1d in __libc_start_main at ??:0
#4 0x403139 in _start at ??:0
stack trace:
#0 0x40378e in print_stacktrace at /data/roberto/backtrace/demagle3.c++:226
#1 0x403a0d in Nu::Alpha<char*>::Beta::func(char*) at /data/roberto/backtrace/demagle3.c++:289
#2 0x403996 in main at /data/roberto/backtrace/demagle3.c++:312
#3 0x355181eb1d in __libc_start_main at ??:0
#4 0x403139 in _start at ??:0
stack trace:
#0 0x40378e in print_stacktrace at /data/roberto/backtrace/demagle3.c++:226
#1 0x403a33 in Nu::Alpha<Nu::Alpha<std::map<int, double, std::less<int>,
std::allocator<std::pair<int const, double> > > > >::Beta::func() at /data/roberto/backtrace/demagle3.c++:286
#2 0x4039a2 in main at /data/roberto/backtrace/demagle3.c++:313
#3 0x355181eb1d in __libc_start_main at ??:0
#4 0x403139 in _start at ??:0
stack trace:
#0 0x40378e in print_stacktrace at /data/roberto/backtrace/demagle3.c++:226
#1 0x403968 in void Nu::Gamma::unroll<0>(double) at /data/roberto/backtrace/demagle3.c++:304
#2 0x403ae8 in void Nu::Gamma::unroll<1>(double) at /data/roberto/backtrace/demagle3.c++:298
#3 0x403ac4 in void Nu::Gamma::unroll<2>(double) at /data/roberto/backtrace/demagle3.c++:298
#4 0x403aa0 in void Nu::Gamma::unroll<3>(double) at /data/roberto/backtrace/demagle3.c++:298
#5 0x403a7c in void Nu::Gamma::unroll<4>(double) at /data/roberto/backtrace/demagle3.c++:298
#6 0x403a58 in void Nu::Gamma::unroll<5>(double) at /data/roberto/backtrace/demagle3.c++:298
#7 0x4039b6 in main at /data/roberto/backtrace/demagle3.c++:313
#8 0x355181eb1d in __libc_start_main at ??:0
#9 0x403139 in _start at ??:0




More information about the Binutils mailing list