blob: 331c223079146f0c1b610db4d942bce68772f3da [file] [log] [blame]
Petr Machata11f23ba2012-10-25 03:39:59 +02001.\" -*-nroff-*-
Petr Machata4b3bda42013-01-11 23:32:17 +01002.\" Copyright (c) 2012, 2013 Petr Machata, Red Hat Inc.
Ian Wienand9a2ad352006-02-20 22:44:45 +01003.\" Copyright (c) 1997-2005 Juan Cespedes <cespedes@debian.org>
Petr Machata11f23ba2012-10-25 03:39:59 +02004.\"
5.\" This program is free software; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of the
8.\" License, or (at your option) any later version.
9.\"
10.\" This program is distributed in the hope that it will be useful, but
11.\" WITHOUT ANY WARRANTY; without even the implied warranty of
12.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13.\" General Public License for more details.
14.\"
15.\" You should have received a copy of the GNU General Public License
16.\" along with this program; if not, write to the Free Software
17.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18.\" 02110-1301 USA
19.\"
Petr Machata4b3bda42013-01-11 23:32:17 +010020.TH LTRACE "1" "January 2013" "" "User Commands"
Ian Wienand9a2ad352006-02-20 22:44:45 +010021.SH NAME
Juan Cespedes07461b61997-08-22 15:29:10 +020022ltrace \- A library call tracer
23
Ian Wienand9a2ad352006-02-20 22:44:45 +010024.SH SYNOPSIS
Petr Machata4b3bda42013-01-11 23:32:17 +010025.\"
26.\" ---------------------------------------------------------------------------
27.\"
28.PP
Juan Cespedes07461b61997-08-22 15:29:10 +020029.B ltrace
Petr Machata4b3bda42013-01-11 23:32:17 +010030.\"
31.\" What events to trace:
32.\"
33[\-e \fIfilter\fR|\-L] [\-l|\-\-library=\fIlibrary_pattern\fR]
34[\-x \fIfilter\fR] [\-S] [\-b|\-\-no-signals]
35.\"
36.\" What to display with each event:
37.\"
38[\-i] [\-w|\-\-where=\fInr\fR] [\-r|\-t|\-tt|\-ttt] [\-T]
39.\"
40.\" Output formatting:
41.\"
Petr Machata56499002013-09-19 23:44:54 +020042[\-F \fIpathlist\fR]
Petr Machata4b3bda42013-01-11 23:32:17 +010043[\-A \fImaxelts\fR] [\-s \fIstrsize\fR] [\-C|\-\-demangle]
44[\-a|\-\-align \fIcolumn\fR] [\-n|\-\-indent \fInr\fR]
45[\-o|\-\-output \fIfilename\fR]
46.\"
47.\" Various:
48.\"
49[\-D|\-\-debug \fImask\fR] [\-u \fIusername\fR]
50.\"
51.\" What processes to trace:
52.\"
53[\-f] [\-p \fIpid\fR] [[\-\-] \fIcommand [arg ...]\fR]
54.\"
55.\" ---------------------------------------------------------------------------
56.\"
57.PP
Juan Cespedesf1947152014-01-05 17:24:50 +010058.BR ltrace " \-c"
Petr Machata4b3bda42013-01-11 23:32:17 +010059.\"
60.\" What events to trace:
61.\"
62[\-e \fIfilter\fR|\-L] [\-l|\-\-library=\fIlibrary_pattern\fR]
63[\-x \fIfilter\fR] [\-S]
64.\"
65.\" Output formatting:
66.\"
67[\-o|\-\-output \fIfilename\fR]
68.\"
69.\" What processes to trace:
70.\"
71[\-f] [\-p \fIpid\fR] [[\-\-] \fIcommand [arg ...]\fR]
72.\"
73.\" ---------------------------------------------------------------------------
74.\"
75.PP
76.BR ltrace " \-V|\-\-version"
77.PP
78.BR ltrace " \-h|\-\-help"
Juan Cespedes07461b61997-08-22 15:29:10 +020079
Ian Wienand9a2ad352006-02-20 22:44:45 +010080.SH DESCRIPTION
Juan Cespedes07461b61997-08-22 15:29:10 +020081.B ltrace
82is a program that simply runs the specified
83.I command
84until it exits. It intercepts and records the dynamic library calls
85which are called by the executed process and the signals which are
86received by that process.
Juan Cespedesac3db291998-04-25 14:31:58 +020087It can also intercept and print the system calls executed by the program.
Ian Wienand9a2ad352006-02-20 22:44:45 +010088.PP
Juan Cespedes07461b61997-08-22 15:29:10 +020089Its use is very similar to
Juan Cespedes81690ef1998-03-13 19:31:29 +010090.BR strace(1) .
Juan Cespedes07461b61997-08-22 15:29:10 +020091
Petr Machata56499002013-09-19 23:44:54 +020092.B ltrace
93shows parameters of invoked functions and system calls. To determine
94what arguments each function has, it needs external declaration of
95function prototypes. Those are stored in files called \fIprototype
96libraries\fR--see ltrace.conf(5) for details on the syntax of these
97files. See the section \fBPROTOTYPE LIBRARY DISCOVERY\fR to learn how
98\fBltrace\fR finds prototype libraries.
99
Ian Wienand9a2ad352006-02-20 22:44:45 +0100100.SH OPTIONS
Petr Machata4b3bda42013-01-11 23:32:17 +0100101.PP
102.IP "\-a, \-\-align \fIcolumn"
Joe Damatofa2aefc2010-10-30 19:56:50 -0700103Align return values in a specific
104.IR column
105(default column is 5/8 of screen width).
Petr Machata4b3bda42013-01-11 23:32:17 +0100106.IP "\-A \fImaxelts"
Petr Machata8c98e402012-11-19 01:30:31 +0100107Maximum number of array elements to print before suppressing the rest
108with an ellipsis ("..."). This also limits number of recursive
109structure expansions.
Petr Machata4b3bda42013-01-11 23:32:17 +0100110.IP "\-b, \-\-no-signals"
Juan Cespedesf1947152014-01-05 17:24:50 +0100111Disable printing of signals received by the traced process.
Petr Machata4b3bda42013-01-11 23:32:17 +0100112.IP \-c
113Count time and calls for each library call and report a summary on
114program exit.
115.IP "\-C, \-\-demangle"
Ian Wienand9a2ad352006-02-20 22:44:45 +0100116Decode (demangle) low-level symbol names into user-level names.
Justin Pryzbyfda2c6f2006-07-18 00:05:26 +0200117Besides removing any initial underscore prefix used by the system,
Juan Cespedesac3db291998-04-25 14:31:58 +0200118this makes C++ function names readable.
Petr Machata4b3bda42013-01-11 23:32:17 +0100119.IP "\-D, \-\-debug \fRmask\fI"
120Show debugging output of \fBltrace\fR itself. \fImask\fR is a number
121with internal meaning that's not really well defined at all.
122\fImask\fR of 77 shows all debug messages, which is what you usually
123need.
124.IP "\-e \fIfilter"
Petr Machata4e1c0662012-04-24 00:50:07 +0200125A qualifying expression which modifies which library calls to trace.
126The format of the filter expression is described in the section
127\fBFILTER EXPRESSIONS\fR. If more than one \-e option appears on the
128command line, the library calls that match any of them are traced. If
129no \-e is given, \fB@MAIN\fR is assumed as a default.
Petr Machata4b3bda42013-01-11 23:32:17 +0100130.IP \-f
Juan Cespedesd65efa32003-02-03 00:22:30 +0100131Trace child processes as they are created by
Juan Cespedesc4e53a92009-05-06 20:36:42 +0200132currently traced processes as a result of the fork(2)
Juan Cespedesd65efa32003-02-03 00:22:30 +0100133or clone(2) system calls.
Juan Cespedesc4e53a92009-05-06 20:36:42 +0200134The new process is attached immediately.
Petr Machata56499002013-09-19 23:44:54 +0200135.IP "\-F \fIpathlist"
136Contains a colon-separated list of paths. If a path refers to a
137directory, that directory is considered when prototype libraries are
138searched (see the section \fBPROTOTYPE LIBRARY DISCOVERY\fR). If it refers to
139a file, that file is imported implicitly to all loaded prototype
140libraries.
Petr Machata4b3bda42013-01-11 23:32:17 +0100141.IP "\-h, \-\-help"
Juan Cespedesac3db291998-04-25 14:31:58 +0200142Show a summary of the options to ltrace and exit.
Petr Machata4b3bda42013-01-11 23:32:17 +0100143.IP \-i
Juan Cespedesd65efa32003-02-03 00:22:30 +0100144Print the instruction pointer at the time of the library call.
Petr Machata4b3bda42013-01-11 23:32:17 +0100145.IP "\-l, \-\-library \fIlibrary_pattern"
Petr Machata9265da42012-11-02 02:56:08 +0100146Display only calls to functions implemented by libraries that match
Petr Machata51e74ac2012-09-27 23:43:25 +0200147.I library_pattern.
148Multiple library patters can be specified with several instances of
149this option. Syntax of library_pattern is described in section
150\fBFILTER EXPRESSIONS\fR.
Petr Machata90d5ec52012-11-02 02:58:16 +0100151
152Note that while this option selects calls that might be directed to
153the selected libraries, there's no actual guarantee that the call
154won't be directed elsewhere due to e.g. LD_PRELOAD or simply
155dependency ordering. If you want to make sure that symbols in given
156library are actually called, use \fB-x @\fIlibrary_pattern\fR instead.
Petr Machata4b3bda42013-01-11 23:32:17 +0100157.IP \-L
Juan Cespedesf1947152014-01-05 17:24:50 +0100158When no \-e option is given, don't assume the default action of
Petr Machata51e74ac2012-09-27 23:43:25 +0200159\fB@MAIN\fR.
Petr Machata4b3bda42013-01-11 23:32:17 +0100160.IP "\-n, \-\-indent \fInr"
161Indent trace output by \fInr\fR spaces for each level of call
162nesting. Using this option makes the program flow visualization easy
163to follow. This indents uselessly also functions that never return,
164such as service functions for throwing exceptions in the C++ runtime.
165.IP "\-o, \-\-output \fIfilename"
166Write the trace output to the file \fIfilename\fR rather than to
167stderr.
168.IP "\-p \fIpid"
169Attach to the process with the process ID \fIpid\fR and begin tracing.
170This option can be used together with passing a command to execute.
171It is possible to attach to several processes by passing more than one
172option \-p.
173.IP \-r
174Print a relative timestamp with each line of the trace. This records
175the time difference between the beginning of successive lines.
176.IP "\-s \fIstrsize"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100177Specify the maximum string size to print (the default is 32).
Petr Machata4b3bda42013-01-11 23:32:17 +0100178.IP \-S
Juan Cespedesd65efa32003-02-03 00:22:30 +0100179Display system calls as well as library calls
Petr Machata4b3bda42013-01-11 23:32:17 +0100180.IP \-t
Juan Cespedesd65efa32003-02-03 00:22:30 +0100181Prefix each line of the trace with the time of day.
Petr Machata4b3bda42013-01-11 23:32:17 +0100182.IP \-tt
Juan Cespedesd65efa32003-02-03 00:22:30 +0100183If given twice, the time printed will include the microseconds.
Petr Machata4b3bda42013-01-11 23:32:17 +0100184.IP \-ttt
Juan Cespedesd65efa32003-02-03 00:22:30 +0100185If given thrice, the time printed will include the microseconds and
186the leading portion will be printed as the number of seconds since the
187epoch.
Petr Machata4b3bda42013-01-11 23:32:17 +0100188.IP \-T
Juan Cespedesd65efa32003-02-03 00:22:30 +0100189Show the time spent inside each call. This records the time difference
190between the beginning and the end of each call.
Petr Machata4b3bda42013-01-11 23:32:17 +0100191.IP "\-u \fIusername"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100192Run command with the userid, groupid and supplementary groups of
Ian Wienand9a2ad352006-02-20 22:44:45 +0100193.IR username .
Juan Cespedesd65efa32003-02-03 00:22:30 +0100194This option is only useful when running as root and enables the
195correct execution of setuid and/or setgid binaries.
Juan Cespedesf1947152014-01-05 17:24:50 +0100196.IP "\-w, \-\-where \fInr"
Petr Machata4b3bda42013-01-11 23:32:17 +0100197Show backtrace of \fInr\fR stack frames for each traced function. This
Mark Wielaarddfefa9f2014-01-07 21:00:44 +0100198option enabled only if elfutils or libunwind support was enabled at compile
199time.
Petr Machata4b3bda42013-01-11 23:32:17 +0100200.IP "\-x \fIfilter"
Petr Machata4e1c0662012-04-24 00:50:07 +0200201A qualifying expression which modifies which symbol table entry points
202to trace. The format of the filter expression is described in the
203section \fBFILTER EXPRESSIONS\fR. If more than one \-x option appears
204on the command line, the symbols that match any of them are traced.
205No entry points are traced if no \-x is given.
Petr Machata4b3bda42013-01-11 23:32:17 +0100206.IP "\-V, \-\-version"
Juan Cespedesac3db291998-04-25 14:31:58 +0200207Show the version number of ltrace and exit.
Juan Cespedes07461b61997-08-22 15:29:10 +0200208
Petr Machata4e1c0662012-04-24 00:50:07 +0200209.SH FILTER EXPRESSIONS
210
211Filter expression is a chain of glob- or regexp-based rules that are
212used to pick symbols for tracing from libraries that the process uses.
213Most of it is intuitive, so as an example, the following would trace
214calls to malloc and free, except those done by libc:
215
216-e malloc+free-@libc.so*
217
218This reads: trace malloc and free, but don't trace anything that comes
219from libc. Semi-formally, the syntax of the above example looks
220approximately like this:
221
Petr Machata964a6802012-06-29 14:27:08 +0200222{[+-][\fIsymbol_pattern\fR][@\fIlibrary_pattern\fR]}
Petr Machata4e1c0662012-04-24 00:50:07 +0200223
Petr Machata964a6802012-06-29 14:27:08 +0200224\fISymbol_pattern\fR is used to match symbol names,
225\fIlibrary_pattern\fR to match library SONAMEs. Both are implicitly
226globs, but can be regular expressions as well (see below). The glob
227syntax supports meta-characters \fB*\fR and \fB?\fR and character
228classes, similarly to what basic bash globs support. \fB^\fR and
229\fB$\fR are recognized to mean, respectively, start and end of given
230name.
Petr Machata4e1c0662012-04-24 00:50:07 +0200231
Petr Machata964a6802012-06-29 14:27:08 +0200232Both \fIsymbol_pattern\fR and \fIlibrary_pattern\fR have to match the
233whole name. If you want to match only part of the name, surround it
Petr Machata4e1c0662012-04-24 00:50:07 +0200234with one or two *'s as appropriate. The exception is if the pattern
235is not mentioned at all, in which case it's as if the corresponding
236pattern were \fB*\fR. (So \fBmalloc\fR is really \fBmalloc@*\fR and
237\fB@libc.*\fR is really \fB*@libc.*\fR.)
238
239In libraries that don't have an explicit SONAME, basename is taken for
240SONAME. That holds for main binary as well: \fB/bin/echo\fR has an
241implicit SONAME of \fBecho\fR. In addition to that, special library
242pattern \fBMAIN\fR always matches symbols in the main binary and never
243a library with actual SONAME \fBMAIN\fR (use e.g. \fB^MAIN\fR or
244\fB[M]AIN\fR for that).
245
246If the symbol or library pattern is surrounded in slashes (/like
247this/), then it is considered a regular expression instead. As a
248shorthand, instead of writing \fB/x/@/y/\fR, you can write
249\fB/x@y/\fR.
250
251If the library pattern starts with a slash, it is not a SONAME
252expression, but a path expression, and is matched against the library
253path name.
254
255The first rule may lack a sign, in which case \fB+\fR is assumed. If,
256on the other hand, the first rule has a \fB-\fR sign, it is as if
Petr Machata4b3bda42013-01-11 23:32:17 +0100257there was another rule \fB@\fR in front of it, which has the effect of
258tracing complement of given rule.
Petr Machata4e1c0662012-04-24 00:50:07 +0200259
260The above rules are used to construct the set of traced symbols. Each
261candidate symbol is passed through the chain of above rules.
Petr Machata964a6802012-06-29 14:27:08 +0200262Initially, the symbol is \fIunmarked\fR. If it matches a \fB+\fR
263rule, it becomes \fImarked\fR, if it matches a \fB-\fR rule, it
264becomes \fIunmarked\fR again. If, after applying all rules, the
265symbol is \fImarked\fR, it will be traced.
Petr Machata4e1c0662012-04-24 00:50:07 +0200266
Petr Machata56499002013-09-19 23:44:54 +0200267.SH PROTOTYPE LIBRARY DISCOVERY
268
269When a library is mapped into the address space of a traced process,
270ltrace needs to know what the prototypes are of functions that this
271library implements. For purposes of ltrace, prototype really is a bit
272more than just type signature: it's also formatting of individual
273parameters and of return value. These prototypes are stored in files
274called prototype libraries.
275
276After a library is mapped, ltrace finds out what its SONAME is. It
277then looks for a file named SONAME.conf--e.g. protolib for libc.so.6
278would be in a file called libc.so.6.conf. When such file is found
279(more about where ltrace looks for these files is below), ltrace reads
280all prototypes stored therein. When a symbol table entry point (such
Juan Cespedesf1947152014-01-05 17:24:50 +0100281as those traced by \-x) is hit, the prototype is looked up in a
282prototype library corresponding to the library where the hit occurred.
283When a library call (such as those traced by \-e and \-l) is hit, the
Petr Machata56499002013-09-19 23:44:54 +0200284prototype is looked up in all prototype libraries loaded for given
285process. That is necessary, because a library call is traced in a PLT
286table of a caller library, but the prototype is described at callee
287library.
288
289If a library has no SONAME, basename of library file is considered
290instead. For the main program binary, basename is considered as well
Petr Machata98a7dce2013-10-23 17:37:47 +0200291(e.g. protolib for /bin/echo would be called echo.conf). If a name
292corresponding to soname (e.g. libc.so.6.conf) is not found, and the
293module under consideration is a shared library, ltrace also tries
294partial matches. Ltrace snips one period after another, retrying the
295search, until either a protolib is found, or X.so is all that's left.
296Thus libc.so.conf would be considered, but libc.conf not.
Petr Machata56499002013-09-19 23:44:54 +0200297
298When looking for a prototype library, ltrace potentially looks into
299several directories. On Linux, those are $XDG_CONFIG_HOME/ltrace,
Petr Machataaa3db6b2013-10-23 00:52:13 +0200300$HOME/.ltrace, \fIX\fR/ltrace for each \fIX\fR in $XDG_CONFIG_DIRS and
301/usr/share/ltrace. If the environment variable XDG_CONFIG_HOME is not
302defined, ltrace looks into $HOME/.config/ltrace instead.
Petr Machata56499002013-09-19 23:44:54 +0200303
304There's also a mechanism for loading legacy config files. If
305$HOME/.ltrace.conf exists it is imported to every loaded prototype
306library. Similarly for /etc/ltrace.conf. If both exist, both are
307imported, and $HOME/.ltrace.conf is consulted before /etc/ltrace.conf.
308
Juan Cespedesf1947152014-01-05 17:24:50 +0100309If \-F contains any directories, those are searched in precedence to
Petr Machata56499002013-09-19 23:44:54 +0200310the above system directories, in the same order in which they are
Juan Cespedesf1947152014-01-05 17:24:50 +0100311mentioned in \-F. Any files passed in \-F are imported similarly to
Petr Machata56499002013-09-19 23:44:54 +0200312above legacy config files, before them.
313
314See ltrace.conf(5) for details on the syntax of ltrace prototype
315library files.
316
Ian Wienand9a2ad352006-02-20 22:44:45 +0100317.SH BUGS
Juan Cespedesac3db291998-04-25 14:31:58 +0200318It has most of the bugs stated in
319.BR strace(1) .
Ian Wienand9a2ad352006-02-20 22:44:45 +0100320.LP
Juan Cespedes6aafe552014-01-09 12:18:46 +0100321It only works on Linux and in some architectures.
Ian Wienand9a2ad352006-02-20 22:44:45 +0100322.LP
Ian Wienand9a2ad352006-02-20 22:44:45 +0100323.PP
Steve Fink7ab8df12006-08-07 04:06:16 +0200324If you would like to report a bug, send a message to the mailing list
325(ltrace-devel@lists.alioth.debian.org), or use the
Ian Wienandbf312a12006-02-20 23:28:35 +0100326.BR reportbug(1)
Juan Cespedesac3db291998-04-25 14:31:58 +0200327program if you are under the Debian GNU/Linux distribution.
Juan Cespedes07461b61997-08-22 15:29:10 +0200328
Ian Wienand9a2ad352006-02-20 22:44:45 +0100329.SH FILES
330.TP
Juan Cespedes5e01f651998-03-08 22:31:44 +0100331.I /etc/ltrace.conf
332System configuration file
Ian Wienand9a2ad352006-02-20 22:44:45 +0100333.TP
Juan Cespedes5e01f651998-03-08 22:31:44 +0100334.I ~/.ltrace.conf
335Personal config file, overrides
336.I /etc/ltrace.conf
337
Ian Wienand9a2ad352006-02-20 22:44:45 +0100338.SH AUTHOR
Juan Cespedes64e793b1997-09-11 23:22:36 +0200339Juan Cespedes <cespedes@debian.org>
Petr Machata4e1c0662012-04-24 00:50:07 +0200340.br
341Petr Machata <pmachata@redhat.com>
Juan Cespedes07461b61997-08-22 15:29:10 +0200342
343.SH "SEE ALSO"
Petr Machata11f23ba2012-10-25 03:39:59 +0200344.BR ltrace.conf(5),
Juan Cespedes07461b61997-08-22 15:29:10 +0200345.BR strace(1) ,
346.BR ptrace(2)