This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help using elfutils to get function and line number


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]