Hi -
I am writing an application which involves obtaining a backtrace, so
I tried to find an easy way to get the backtrace for the running
program. I used the glibc backtrace() function to get the return
addresses from the stack. However, I need to convert those addresses
into meaningful information (such as function name, file name and
line number). I tried to use the addr2line code, but ran into
problems when using dynamically loaded libraries, because the
addresses (the one returned by backtrace(), and the actual address
in the library -- the one returned by gdb, for instance) didn't
match.
No offline debuginfo parser library can perform this address mapping
by itself since the shared library address data is only available at
run time. When you store your backtrace() output, you should also
store your shared library address map (e.g. /proc/self/maps). With
all that information available, elfutils can let you work with such
addresses to get correct debuginfo address matching. One has to be
aware that there are several additive/subtractive mappings in play
(and some of them have buggy implementations in some versions of
elfutils) so getting it just right is tricky.
- FChE