ltrace is a library call tracer. It is a debugging utility in Linux, used to display the calls a userland application makes to shared libraries.
Description:
ltrace
is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls
executed by the program.
Package:
ltrace
Usage:
Check out the manpage for complete list of options and their usage.
Prototype Library Discovery:
When a library is mapped into the address space of a traced process, ltrace
needs to know what the prototypes are of functions that this library implements. For purposes of ltrace
, prototype really is a bit more than just type signature: it's also formatting of individual parameters and of return value. These prototypes are stored in files called prototype libraries.
After a library is mapped, ltrace
finds out what its SONAME
is. It then looks for a file named SONAME.conf
e.g. Prototype library for libc.so.6
would be in a file called libc.so.6.conf
. When such file is found, ltrace
reads all prototypes stored therein.
- When a symbol table entry point (such as those traced by
-x
) is hit, the prototype is looked up in a prototype library corresponding to the library where the hit occurred. - When a library call (such as those traced by
-e
and-l
) is hit, the prototype is looked up in all prototype libraries loaded for given process. That is necessary, because a library call is traced in a PLT table of a caller library, but the prototype is described at callee library.
If a library has no SONAME
, basename of library file is considered instead. For the main program binary, basename is considered as well (e.g. prototype library for /bin/echo
would be called echo.conf
).
If a name corresponding to soname (e.g. libc.so.6.conf) is not found, and the
module under consideration is a shared library, ltrace also tries
partial matches. ltrace
snips one period after another, retrying the
search, until either a protolib is found, or X.so is all that's left.
Thus libc.so.conf would be considered, but libc.conf not.
When looking for a prototype library, ltrace
potentially looks into
several directories. On Linux, those are $XDG_CONFIG_HOME/ltrace
,
$HOME/.ltrace
, X/ltrace
for each X
in $XDG_CONFIG_DIRS
and
/usr/share/ltrace
. If the environment variable XDG_CONFIG_HOME
is
not defined, ltrace
looks into $HOME/.config/ltrace
instead.
There's also a mechanism for loading legacy config files. If
$HOME/.ltrace.conf
exists, it is imported to every loaded prototype
library. Similarly for /etc/ltrace.conf
. If both exist, both are
imported, and $HOME/.ltrace.conf
is consulted before
/etc/ltrace.conf
.
If -F
contains any directories, those are searched in precedence to
the above system directories, in the same order in which they are
mentioned in -F
. Any files passed in -F
are imported similarly to
above legacy config files, before them.
References:
- http://man7.org/linux/man-pages/man1/ltrace.1.html
- http://en.wikipedia.org/wiki/Ltrace
- http://linux.die.net/man/1/ltrace
man ltrace
on a Linux machine.