libbacktrace patch committed: Trace through shared libraries

Jakub Jelinek jakub@redhat.com
Tue Oct 9 21:03:00 GMT 2012


On Tue, Oct 09, 2012 at 01:43:06PM -0700, Ian Lance Taylor wrote:
> On Tue, Oct 9, 2012 at 11:32 AM, Basile Starynkevitch
> <basile@starynkevitch.net> wrote:
> >
> > You could provide an extra API to register dlopen & dlclose to libbacktrace, if that helps you
> > (of course, I would prefer avoiding that)
> 
> I would prefer avoiding that as well.
> 
> Calling dl_iterate_phdr can tell libbacktrace reliably the set of
> shared libraries that are currently loaded.  The trick is knowing when
> to call it.  It may simply be OK to call it every time we look up a PC
> value, in which case we can look at the dlpi_adds and dlpi_subs field.
>  I'm not sure.

See unwind-dw2-fde-dip.c how it uses it.  I think for all PC queries from
one backtrace you should get away with using a cache of last looked up
library even without calling dl_iterate_phdr.  PCs in the backtrace
can't go away from under you in a properly written application (but only
those, not others).  In between different backtrace calls you need to call
dl_iterate_phdr (primarily to lock the ld.so lock and prevent dlopen/dlclose
from other threads), but can use a cache there and use dlpi_adds/dlpi_subs
to find out when to invalidate the cache.

	Jakub



More information about the Gcc-patches mailing list