Blame ltrace.1

Packit 0021fb
.\" -*-nroff-*-
Packit 0021fb
.\" Copyright (c) 2012, 2013 Petr Machata, Red Hat Inc.
Packit 0021fb
.\" Copyright (c) 1997-2005 Juan Cespedes <cespedes@debian.org>
Packit 0021fb
.\"
Packit 0021fb
.\" This program is free software; you can redistribute it and/or
Packit 0021fb
.\" modify it under the terms of the GNU General Public License as
Packit 0021fb
.\" published by the Free Software Foundation; either version 2 of the
Packit 0021fb
.\" License, or (at your option) any later version.
Packit 0021fb
.\"
Packit 0021fb
.\" This program is distributed in the hope that it will be useful, but
Packit 0021fb
.\" WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0021fb
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0021fb
.\" General Public License for more details.
Packit 0021fb
.\"
Packit 0021fb
.\" You should have received a copy of the GNU General Public License
Packit 0021fb
.\" along with this program; if not, write to the Free Software
Packit 0021fb
.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit 0021fb
.\" 02110-1301 USA
Packit 0021fb
.\"
Packit 0021fb
.TH LTRACE "1" "January 2013" "" "User Commands"
Packit 0021fb
.SH NAME
Packit 0021fb
ltrace \- A library call tracer
Packit 0021fb
Packit 0021fb
.SH SYNOPSIS
Packit 0021fb
.\"
Packit 0021fb
.\" ---------------------------------------------------------------------------
Packit 0021fb
.\"
Packit 0021fb
.PP
Packit 0021fb
.B ltrace
Packit 0021fb
.\"
Packit 0021fb
.\" What events to trace:
Packit 0021fb
.\"
Packit 0021fb
[\-e \fIfilter\fR|\-L] [\-l|\-\-library=\fIlibrary_pattern\fR]
Packit 0021fb
[\-x \fIfilter\fR] [\-S] [\-b|\-\-no-signals]
Packit 0021fb
.\"
Packit 0021fb
.\" What to display with each event:
Packit 0021fb
.\"
Packit 0021fb
[\-i] [\-w|\-\-where=\fInr\fR] [\-r|\-t|\-tt|\-ttt] [\-T]
Packit 0021fb
.\"
Packit 0021fb
.\" Output formatting:
Packit 0021fb
.\"
Packit 0021fb
[\-F \fIpathlist\fR]
Packit 0021fb
[\-A \fImaxelts\fR] [\-s \fIstrsize\fR] [\-C|\-\-demangle]
Packit 0021fb
[\-a|\-\-align \fIcolumn\fR] [\-n|\-\-indent \fInr\fR]
Packit 0021fb
[\-o|\-\-output \fIfilename\fR]
Packit 0021fb
.\"
Packit 0021fb
.\" Various:
Packit 0021fb
.\"
Packit 0021fb
[\-D|\-\-debug \fImask\fR] [\-u \fIusername\fR]
Packit 0021fb
.\"
Packit 0021fb
.\" What processes to trace:
Packit 0021fb
.\"
Packit 0021fb
[\-f] [\-p \fIpid\fR] [[\-\-] \fIcommand [arg ...]\fR]
Packit 0021fb
.\"
Packit 0021fb
.\" ---------------------------------------------------------------------------
Packit 0021fb
.\"
Packit 0021fb
.PP
Packit 0021fb
.BR ltrace " -c"
Packit 0021fb
.\"
Packit 0021fb
.\" What events to trace:
Packit 0021fb
.\"
Packit 0021fb
[\-e \fIfilter\fR|\-L] [\-l|\-\-library=\fIlibrary_pattern\fR]
Packit 0021fb
[\-x \fIfilter\fR] [\-S]
Packit 0021fb
.\"
Packit 0021fb
.\" Output formatting:
Packit 0021fb
.\"
Packit 0021fb
[\-o|\-\-output \fIfilename\fR]
Packit 0021fb
.\"
Packit 0021fb
.\" What processes to trace:
Packit 0021fb
.\"
Packit 0021fb
[\-f] [\-p \fIpid\fR] [[\-\-] \fIcommand [arg ...]\fR]
Packit 0021fb
.\"
Packit 0021fb
.\" ---------------------------------------------------------------------------
Packit 0021fb
.\"
Packit 0021fb
.PP
Packit 0021fb
.BR ltrace " \-V|\-\-version"
Packit 0021fb
.PP
Packit 0021fb
.BR ltrace " \-h|\-\-help"
Packit 0021fb
Packit 0021fb
.SH DESCRIPTION
Packit 0021fb
.B ltrace
Packit 0021fb
is a program that simply runs the specified
Packit 0021fb
.I command
Packit 0021fb
until it exits.  It intercepts and records the dynamic library calls
Packit 0021fb
which are called by the executed process and the signals which are
Packit 0021fb
received by that process.
Packit 0021fb
It can also intercept and print the system calls executed by the program.
Packit 0021fb
.PP
Packit 0021fb
Its use is very similar to
Packit 0021fb
.BR strace(1) .
Packit 0021fb
Packit 0021fb
.B ltrace
Packit 0021fb
shows parameters of invoked functions and system calls.  To determine
Packit 0021fb
what arguments each function has, it needs external declaration of
Packit 0021fb
function prototypes.  Those are stored in files called \fIprototype
Packit 0021fb
libraries\fR--see ltrace.conf(5) for details on the syntax of these
Packit 0021fb
files.  See the section \fBPROTOTYPE LIBRARY DISCOVERY\fR to learn how
Packit 0021fb
\fBltrace\fR finds prototype libraries.
Packit 0021fb
Packit 0021fb
.SH OPTIONS
Packit 0021fb
.PP
Packit 0021fb
.IP "\-a, \-\-align \fIcolumn"
Packit 0021fb
Align return values in a specific
Packit 0021fb
.IR column
Packit 0021fb
(default column is 5/8 of screen width).
Packit 0021fb
.IP "\-A \fImaxelts"
Packit 0021fb
Maximum number of array elements to print before suppressing the rest
Packit 0021fb
with an ellipsis ("...").  This also limits number of recursive
Packit 0021fb
structure expansions.
Packit 0021fb
.IP "\-b, \-\-no-signals"
Packit 0021fb
Disable printing of signals recieved by the traced process.
Packit 0021fb
.IP \-c
Packit 0021fb
Count time and calls for each library call and report a summary on
Packit 0021fb
program exit.
Packit 0021fb
.IP "\-C, \-\-demangle"
Packit 0021fb
Decode (demangle) low-level symbol names into user-level names.
Packit 0021fb
Besides removing any initial underscore prefix used by the system,
Packit 0021fb
this makes C++ function names readable.
Packit 0021fb
.IP "\-D, \-\-debug \fRmask\fI"
Packit 0021fb
Show debugging output of \fBltrace\fR itself.  \fImask\fR is a number
Packit 0021fb
with internal meaning that's not really well defined at all.
Packit 0021fb
\fImask\fR of 77 shows all debug messages, which is what you usually
Packit 0021fb
need.
Packit 0021fb
.IP "\-e \fIfilter"
Packit 0021fb
A qualifying expression which modifies which library calls to trace.
Packit 0021fb
The format of the filter expression is described in the section
Packit 0021fb
\fBFILTER EXPRESSIONS\fR.  If more than one \-e option appears on the
Packit 0021fb
command line, the library calls that match any of them are traced.  If
Packit 0021fb
no \-e is given, \fB@MAIN\fR is assumed as a default.
Packit 0021fb
.IP \-f
Packit 0021fb
Trace child processes as they are created by
Packit 0021fb
currently traced processes as a result of the fork(2)
Packit 0021fb
or clone(2) system calls.
Packit 0021fb
The new process is attached immediately.
Packit 0021fb
.IP "\-F \fIpathlist"
Packit 0021fb
Contains a colon-separated list of paths.  If a path refers to a
Packit 0021fb
directory, that directory is considered when prototype libraries are
Packit 0021fb
searched (see the section \fBPROTOTYPE LIBRARY DISCOVERY\fR).  If it refers to
Packit 0021fb
a file, that file is imported implicitly to all loaded prototype
Packit 0021fb
libraries.
Packit 0021fb
.IP "\-h, \-\-help"
Packit 0021fb
Show a summary of the options to ltrace and exit.
Packit 0021fb
.IP \-i
Packit 0021fb
Print the instruction pointer at the time of the library call.
Packit 0021fb
.IP "\-l, \-\-library \fIlibrary_pattern"
Packit 0021fb
Display only calls to functions implemented by libraries that match
Packit 0021fb
.I library_pattern.
Packit 0021fb
Multiple library patters can be specified with several instances of
Packit 0021fb
this option.  Syntax of library_pattern is described in section
Packit 0021fb
\fBFILTER EXPRESSIONS\fR.
Packit 0021fb
Packit 0021fb
Note that while this option selects calls that might be directed to
Packit 0021fb
the selected libraries, there's no actual guarantee that the call
Packit 0021fb
won't be directed elsewhere due to e.g. LD_PRELOAD or simply
Packit 0021fb
dependency ordering.  If you want to make sure that symbols in given
Packit 0021fb
library are actually called, use \fB-x @\fIlibrary_pattern\fR instead.
Packit 0021fb
.IP \-L
Packit 0021fb
When no -e option is given, don't assume the default action of
Packit 0021fb
\fB@MAIN\fR.
Packit 0021fb
.IP "\-n, \-\-indent \fInr"
Packit 0021fb
Indent trace output by \fInr\fR spaces for each level of call
Packit 0021fb
nesting. Using this option makes the program flow visualization easy
Packit 0021fb
to follow.  This indents uselessly also functions that never return,
Packit 0021fb
such as service functions for throwing exceptions in the C++ runtime.
Packit 0021fb
.IP "\-o, \-\-output \fIfilename"
Packit 0021fb
Write the trace output to the file \fIfilename\fR rather than to
Packit 0021fb
stderr.
Packit 0021fb
.IP "\-p \fIpid"
Packit 0021fb
Attach to the process with the process ID \fIpid\fR and begin tracing.
Packit 0021fb
This option can be used together with passing a command to execute.
Packit 0021fb
It is possible to attach to several processes by passing more than one
Packit 0021fb
option \-p.
Packit 0021fb
.IP \-r
Packit 0021fb
Print a relative timestamp with each line of the trace.  This records
Packit 0021fb
the time difference between the beginning of successive lines.
Packit 0021fb
.IP "\-s \fIstrsize"
Packit 0021fb
Specify the maximum string size to print (the default is 32).
Packit 0021fb
.IP \-S
Packit 0021fb
Display system calls as well as library calls
Packit 0021fb
.IP \-t
Packit 0021fb
Prefix each line of the trace with the time of day.
Packit 0021fb
.IP \-tt
Packit 0021fb
If given twice, the time printed will include the microseconds.
Packit 0021fb
.IP \-ttt
Packit 0021fb
If given thrice, the time printed will include the microseconds and
Packit 0021fb
the leading portion will be printed as the number of seconds since the
Packit 0021fb
epoch.
Packit 0021fb
.IP \-T
Packit 0021fb
Show  the  time  spent inside each call. This records the time difference
Packit 0021fb
between the beginning and the end of each call.
Packit 0021fb
.IP "\-u \fIusername"
Packit 0021fb
Run command with the userid, groupid and supplementary groups of
Packit 0021fb
.IR username .
Packit 0021fb
This option is only useful when running as root and enables the
Packit 0021fb
correct execution of setuid and/or setgid binaries.
Packit 0021fb
.IP "\-w, --where \fInr"
Packit 0021fb
Show backtrace of \fInr\fR stack frames for each traced function. This
Packit 0021fb
option enabled only if libunwind support was enabled at compile time.
Packit 0021fb
.IP "\-x \fIfilter"
Packit 0021fb
A qualifying expression which modifies which symbol table entry points
Packit 0021fb
to trace.  The format of the filter expression is described in the
Packit 0021fb
section \fBFILTER EXPRESSIONS\fR.  If more than one \-x option appears
Packit 0021fb
on the command line, the symbols that match any of them are traced.
Packit 0021fb
No entry points are traced if no \-x is given.
Packit 0021fb
.IP "\-V, \-\-version"
Packit 0021fb
Show the version number of ltrace and exit.
Packit 0021fb
Packit 0021fb
.SH FILTER EXPRESSIONS
Packit 0021fb
Packit 0021fb
Filter expression is a chain of glob- or regexp-based rules that are
Packit 0021fb
used to pick symbols for tracing from libraries that the process uses.
Packit 0021fb
Most of it is intuitive, so as an example, the following would trace
Packit 0021fb
calls to malloc and free, except those done by libc:
Packit 0021fb
Packit 0021fb
-e malloc+free-@libc.so*
Packit 0021fb
Packit 0021fb
This reads: trace malloc and free, but don't trace anything that comes
Packit 0021fb
from libc.  Semi-formally, the syntax of the above example looks
Packit 0021fb
approximately like this:
Packit 0021fb
Packit 0021fb
{[+-][\fIsymbol_pattern\fR][@\fIlibrary_pattern\fR]}
Packit 0021fb
Packit 0021fb
\fISymbol_pattern\fR is used to match symbol names,
Packit 0021fb
\fIlibrary_pattern\fR to match library SONAMEs.  Both are implicitly
Packit 0021fb
globs, but can be regular expressions as well (see below).  The glob
Packit 0021fb
syntax supports meta-characters \fB*\fR and \fB?\fR and character
Packit 0021fb
classes, similarly to what basic bash globs support.  \fB^\fR and
Packit 0021fb
\fB$\fR are recognized to mean, respectively, start and end of given
Packit 0021fb
name.
Packit 0021fb
Packit 0021fb
Both \fIsymbol_pattern\fR and \fIlibrary_pattern\fR have to match the
Packit 0021fb
whole name.  If you want to match only part of the name, surround it
Packit 0021fb
with one or two *'s as appropriate.  The exception is if the pattern
Packit 0021fb
is not mentioned at all, in which case it's as if the corresponding
Packit 0021fb
pattern were \fB*\fR.  (So \fBmalloc\fR is really \fBmalloc@*\fR and
Packit 0021fb
\fB@libc.*\fR is really \fB*@libc.*\fR.)
Packit 0021fb
Packit 0021fb
In libraries that don't have an explicit SONAME, basename is taken for
Packit 0021fb
SONAME.  That holds for main binary as well: \fB/bin/echo\fR has an
Packit 0021fb
implicit SONAME of \fBecho\fR.  In addition to that, special library
Packit 0021fb
pattern \fBMAIN\fR always matches symbols in the main binary and never
Packit 0021fb
a library with actual SONAME \fBMAIN\fR (use e.g. \fB^MAIN\fR or
Packit 0021fb
\fB[M]AIN\fR for that).
Packit 0021fb
Packit 0021fb
If the symbol or library pattern is surrounded in slashes (/like
Packit 0021fb
this/), then it is considered a regular expression instead.  As a
Packit 0021fb
shorthand, instead of writing \fB/x/@/y/\fR, you can write
Packit 0021fb
\fB/x@y/\fR.
Packit 0021fb
Packit 0021fb
If the library pattern starts with a slash, it is not a SONAME
Packit 0021fb
expression, but a path expression, and is matched against the library
Packit 0021fb
path name.
Packit 0021fb
Packit 0021fb
The first rule may lack a sign, in which case \fB+\fR is assumed.  If,
Packit 0021fb
on the other hand, the first rule has a \fB-\fR sign, it is as if
Packit 0021fb
there was another rule \fB@\fR in front of it, which has the effect of
Packit 0021fb
tracing complement of given rule.
Packit 0021fb
Packit 0021fb
The above rules are used to construct the set of traced symbols.  Each
Packit 0021fb
candidate symbol is passed through the chain of above rules.
Packit 0021fb
Initially, the symbol is \fIunmarked\fR.  If it matches a \fB+\fR
Packit 0021fb
rule, it becomes \fImarked\fR, if it matches a \fB-\fR rule, it
Packit 0021fb
becomes \fIunmarked\fR again.  If, after applying all rules, the
Packit 0021fb
symbol is \fImarked\fR, it will be traced.
Packit 0021fb
Packit 0021fb
.SH PROTOTYPE LIBRARY DISCOVERY
Packit 0021fb
Packit 0021fb
When a library is mapped into the address space of a traced process,
Packit 0021fb
ltrace needs to know what the prototypes are of functions that this
Packit 0021fb
library implements.  For purposes of ltrace, prototype really is a bit
Packit 0021fb
more than just type signature: it's also formatting of individual
Packit 0021fb
parameters and of return value.  These prototypes are stored in files
Packit 0021fb
called prototype libraries.
Packit 0021fb
Packit 0021fb
After a library is mapped, ltrace finds out what its SONAME is.  It
Packit 0021fb
then looks for a file named SONAME.conf--e.g. protolib for libc.so.6
Packit 0021fb
would be in a file called libc.so.6.conf.  When such file is found
Packit 0021fb
(more about where ltrace looks for these files is below), ltrace reads
Packit 0021fb
all prototypes stored therein.  When a symbol table entry point (such
Packit 0021fb
as those traced by -x) is hit, the prototype is looked up in a
Packit 0021fb
prototype library corresponding to the library where the hit occured.
Packit 0021fb
When a library call (such as those traced by -e and -l) is hit, the
Packit 0021fb
prototype is looked up in all prototype libraries loaded for given
Packit 0021fb
process.  That is necessary, because a library call is traced in a PLT
Packit 0021fb
table of a caller library, but the prototype is described at callee
Packit 0021fb
library.
Packit 0021fb
Packit 0021fb
If a library has no SONAME, basename of library file is considered
Packit 0021fb
instead.  For the main program binary, basename is considered as well
Packit 0021fb
(e.g. protolib for /bin/echo would be called echo.conf).  If a name
Packit 0021fb
corresponding to soname (e.g. libc.so.6.conf) is not found, and the
Packit 0021fb
module under consideration is a shared library, ltrace also tries
Packit 0021fb
partial matches.  Ltrace snips one period after another, retrying the
Packit 0021fb
search, until either a protolib is found, or X.so is all that's left.
Packit 0021fb
Thus libc.so.conf would be considered, but libc.conf not.
Packit 0021fb
Packit 0021fb
When looking for a prototype library, ltrace potentially looks into
Packit 0021fb
several directories.  On Linux, those are $XDG_CONFIG_HOME/ltrace,
Packit 0021fb
$HOME/.ltrace, \fIX\fR/ltrace for each \fIX\fR in $XDG_CONFIG_DIRS and
Packit 0021fb
/usr/share/ltrace.  If the environment variable XDG_CONFIG_HOME is not
Packit 0021fb
defined, ltrace looks into $HOME/.config/ltrace instead.
Packit 0021fb
Packit 0021fb
There's also a mechanism for loading legacy config files.  If
Packit 0021fb
$HOME/.ltrace.conf exists it is imported to every loaded prototype
Packit 0021fb
library.  Similarly for /etc/ltrace.conf.  If both exist, both are
Packit 0021fb
imported, and $HOME/.ltrace.conf is consulted before /etc/ltrace.conf.
Packit 0021fb
Packit 0021fb
If -F contains any directories, those are searched in precedence to
Packit 0021fb
the above system directories, in the same order in which they are
Packit 0021fb
mentioned in -F.  Any files passed in -F are imported similarly to
Packit 0021fb
above legacy config files, before them.
Packit 0021fb
Packit 0021fb
See ltrace.conf(5) for details on the syntax of ltrace prototype
Packit 0021fb
library files.
Packit 0021fb
Packit 0021fb
.SH BUGS
Packit 0021fb
It has most of the bugs stated in
Packit 0021fb
.BR strace(1) .
Packit 0021fb
.LP
Packit 0021fb
It only works on Linux and in a small subset of architectures.
Packit 0021fb
.LP
Packit 0021fb
.PP
Packit 0021fb
If you would like to report a bug, send a message to the mailing list
Packit 0021fb
(ltrace-devel@lists.alioth.debian.org), or use the
Packit 0021fb
.BR reportbug(1)
Packit 0021fb
program if you are under the Debian GNU/Linux distribution.
Packit 0021fb
Packit 0021fb
.SH FILES
Packit 0021fb
.TP
Packit 0021fb
.I /etc/ltrace.conf
Packit 0021fb
System configuration file
Packit 0021fb
.TP
Packit 0021fb
.I ~/.ltrace.conf
Packit 0021fb
Personal config file, overrides
Packit 0021fb
.I /etc/ltrace.conf
Packit 0021fb
Packit 0021fb
.SH AUTHOR
Packit 0021fb
Juan Cespedes <cespedes@debian.org>
Packit 0021fb
.br
Packit 0021fb
Petr Machata <pmachata@redhat.com>
Packit 0021fb
Packit 0021fb
.SH "SEE ALSO"
Packit 0021fb
.BR ltrace.conf(5),
Packit 0021fb
.BR strace(1) ,
Packit 0021fb
.BR ptrace(2)