[Ltrace-devel] libs branch

Petr Machata pmachata at redhat.com
Mon Apr 23 23:36:24 UTC 2012


Hi list,

I'm wrapping up the "pmachata/libs" branch that I forked in February.
The changes that this should bring are:

* tracing of calls made from DSOs
* interface clarifications
* full support of PPC

The latter was rolled into the former as I needed to validate my code on
something else than x86's, and PPC is relatively widely deployed
(compared to ia64 and s390 anyway), and a worthy target to support well,
in my opinion.  It may have been a better option to use ARM instead,
seeing at how involved PPC ended up being, but oh well, at least we have
it fixed now.  I hope to get to ARM shortly, as there have been all
kinds of stir around that architecture lately, and it's currently
broken on master.


Primarily, ltrace now hooks into the dynamic linker and adds breakpoints
to PLTs (and entry points) of all libraries, not just of the main
binary.  We do it by hooking into libdl.  This is mostly based on dlopen
code that Joe Damato wrote in late 2010.

The syntax of -x and -e was extended to allow DSO selectors, and both
options are applied uniformly to symbols in all libraries and the main
binary.  dlopened libraries are not considered special (and in fact they
can't be: when we attach, the only thing that we see is a list of loaded
libraries.  We have no idea which of them were loaded by dlopen and
which are part of the initial bunch).

On the surface, the selector syntax is simple:
[symbol-pattern][@lib-pattern]

Symbol pattern is matched against symbol name, lib pattern against
SONAME.  You can have a chain of these, connected with +'s and -'s.  If
one of the patterns is missing, it's as if a wild card were there.  The
patterns are globs by default, but you can use regular expressions
instead by enclosing the pattern in slashes.  I described all this in
more detail in man page, so look there if you are interested.

As an example, the following would trace malloc and free calls, except
those done from libc:

./ltrace -e 'malloc+free- at libc.so*' ls

I made it support initial ! with the same meaning as before, but the new
way is to use +'s and -'s.  Initial - still means "everything but".

-x uses the same syntax as -e.  Presumably if I ever get around to
finishing the systemtap probe support, there will be yet another
commandline option that uses this filtering syntax.


When woring on the above, I fixed interfaces that I needed along the
way.  Breakpoints, libraries, symbols and processes have all a clear and
documented init, destroy and clone functions.  There's now an official
and documented way of extending those structures with arch-specific data
(we would still need something similar for os-specific data, but that
wasn't done yet, and it's not a pain point right now).  The ifdefs all
over the place were hidden in their proper back ends.


The PPC support means that we now really trace PLT entries on PPC.
Because PLT on PPCs is difficult to work with, we used to fake it and
traced entry points instead.  Additionally, now we properly support
old-style PPC32 BSS PLT as well, which was very broken on master.  The
test suite comes out almost clean in all thinkable combinations of
tracer and tracee.  There are a handful of failures left.  I think those
will be addressed by the changes on my revamp branch, and don't want to
fix them specially now.  The following line can be used to run the
testsuite in PPC32BSS mode:

$ make check RUNTESTFLAGS=CFLAGS_FOR_TARGET='-m32 -mbss-plt -Wl,--bss-plt'


I suspect there are remaining bugs with detach code, and I need to write
a couple test cases for the filtering stuff, and fill in change logs,
but otherwise this should be about ready for merge.

Thanks,
PM



More information about the Ltrace-devel mailing list