library_exported_names_each_alias(), library_exported_names_each() now restartable
[platform/upstream/ltrace.git] / ltrace.1
1 .\" -*-nroff-*-
2 .\" Copyright (c) 2012, 2013, 2014 Petr Machata, Red Hat Inc.
3 .\" Copyright (c) 1997-2005 Juan Cespedes <cespedes@debian.org>
4 .\"
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 .\"
20 .TH LTRACE "1" "January 2013" "" "User Commands"
21 .SH NAME
22 ltrace \- A library call tracer
23
24 .SH SYNOPSIS
25 .\"
26 .\" ---------------------------------------------------------------------------
27 .\"
28 .PP
29 .B ltrace
30 .\"
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 .\"
42 [[\-F|\-\-config] \fIpathlist\fR]
43 [\-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
58 .BR ltrace " \-c"
59 .\"
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"
79
80 .SH DESCRIPTION
81 .B ltrace
82 is a program that simply runs the specified
83 .I command
84 until it exits.  It intercepts and records the dynamic library calls
85 which are called by the executed process and the signals which are
86 received by that process.
87 It can also intercept and print the system calls executed by the program.
88 .PP
89 Its use is very similar to
90 .BR strace(1) .
91
92 .B ltrace
93 shows parameters of invoked functions and system calls.  To determine
94 what arguments each function has, it needs external declaration of
95 function prototypes.  Those are stored in files called \fIprototype
96 libraries\fR--see ltrace.conf(5) for details on the syntax of these
97 files.  See the section \fBPROTOTYPE LIBRARY DISCOVERY\fR to learn how
98 \fBltrace\fR finds prototype libraries.
99
100 .SH OPTIONS
101 .PP
102 .IP "\-a, \-\-align \fIcolumn"
103 Align return values in a specific
104 .IR column
105 (default column is 5/8 of screen width).
106 .IP "\-A \fImaxelts"
107 Maximum number of array elements to print before suppressing the rest
108 with an ellipsis ("...").  This also limits number of recursive
109 structure expansions.
110 .IP "\-b, \-\-no-signals"
111 Disable printing of signals received by the traced process.
112 .IP \-c
113 Count time and calls for each library call and report a summary on
114 program exit.
115 .IP "\-C, \-\-demangle"
116 Decode (demangle) low-level symbol names into user-level names.
117 Besides removing any initial underscore prefix used by the system,
118 this makes C++ function names readable.
119 .IP "\-D, \-\-debug \fRmask\fI"
120 Show debugging output of \fBltrace\fR itself.  \fImask\fR is a number
121 describing which debug messages should be displayed.  Use the option
122 \-Dh to see what can be used, but note that currently the only
123 reliable debugmask is 77, which shows all debug messages.
124 .IP "\-e \fIfilter"
125 A qualifying expression which modifies which library calls (i.e. calls done
126 through PLT slots, which are typically calls from the main binary to a library,
127 or inter-library calls) to trace. Usage examples and the syntax description
128 appear below in sections \fBFILTER SPECIFICATIONS\fR and \fBFILTER
129 EXPRESSIONS\fR. If more than one \-e option appears on the command line, the
130 library calls that match any of them are traced. If no \-e is given, \fB@MAIN\fR
131 is assumed as a default.
132 .IP \-f
133 Trace child processes as they are created by
134 currently traced processes as a result of the fork(2)
135 or clone(2) system calls.
136 The new process is attached immediately.
137 .IP "\-F, \-\-config \fIpathlist"
138 Contains a colon-separated list of paths.  If a path refers to a
139 directory, that directory is considered when prototype libraries are
140 searched (see the section \fBPROTOTYPE LIBRARY DISCOVERY\fR).  If it refers to
141 a file, that file is imported implicitly to all loaded prototype
142 libraries.
143 .IP "\-h, \-\-help"
144 Show a summary of the options to ltrace and exit.
145 .IP \-i
146 Print the instruction pointer at the time of the library call.
147 .IP "\-l, \-\-library \fIlibrary_pattern"
148 Display only calls to functions implemented by libraries that match
149 .I library_pattern.
150 This is as if you specified one \-e for every symbol implemented in a
151 library specified by
152 .I library_pattern.
153 Multiple library patters can be specified with several instances of this option.
154 Usage examples and the syntax description of library_pattern appear below in
155 sections \fBFILTER SPECIFICATIONS\fR and \fBFILTER EXPRESSIONS\fR.
156
157 Note that while this option selects calls that might be directed to
158 the selected libraries, there's no actual guarantee that the call
159 won't be directed elsewhere due to e.g. LD_PRELOAD or simply
160 dependency ordering.  If you want to make sure that symbols in given
161 library are actually called, use \fB-x @\fIlibrary_pattern\fR instead.
162 .IP \-L
163 When no \-e option is given, don't assume the default action of
164 \fB@MAIN\fR.  In practice this means that library calls will not be
165 traced.
166 .IP "\-n, \-\-indent \fInr"
167 Indent trace output by \fInr\fR spaces for each level of call
168 nesting. Using this option makes the program flow visualization easy
169 to follow.  This indents uselessly also functions that never return,
170 such as service functions for throwing exceptions in the C++ runtime.
171 .IP "\-o, \-\-output \fIfilename"
172 Write the trace output to the file \fIfilename\fR rather than to
173 stderr.
174 .IP "\-p \fIpid"
175 Attach to the process with the process ID \fIpid\fR and begin tracing.
176 This option can be used together with passing a command to execute.
177 It is possible to attach to several processes by passing more than one
178 option \-p.
179 .IP \-r
180 Print a relative timestamp with each line of the trace.  This records
181 the time difference between the beginning of successive lines.
182 .IP "\-s \fIstrsize"
183 Specify the maximum string size to print (the default is 32).
184 .IP \-S
185 Display system calls as well as library calls
186 .IP \-t
187 Prefix each line of the trace with the time of day.
188 .IP \-tt
189 If given twice, the time printed will include the microseconds.
190 .IP \-ttt
191 If given thrice, the time printed will include the microseconds and
192 the leading portion will be printed as the number of seconds since the
193 epoch.
194 .IP \-T
195 Show  the  time  spent inside each call. This records the time difference
196 between the beginning and the end of each call.
197 .IP "\-u \fIusername"
198 Run command with the userid, groupid and supplementary groups of
199 .IR username .
200 This option is only useful when running as root and enables the
201 correct execution of setuid and/or setgid binaries.
202 .IP "\-w, \-\-where \fInr"
203 Show backtrace of \fInr\fR stack frames for each traced function. This
204 option enabled only if elfutils or libunwind support was enabled at compile
205 time.
206 .IP "\-x \fIfilter"
207 A qualifying expression which modifies which symbol table entry points to trace
208 (those are typically calls inside a library or main binary, though PLT calls,
209 traced by \-e, land on entry points as well). Usage examples and the syntax
210 description appear below in sections \fBFILTER SPECIFICATIONS\fR and \fBFILTER
211 EXPRESSIONS\fR. If more than one \-x option appears on the command line, the
212 symbols that match any of them are traced. No entry points are traced if no \-x
213 is given.
214 .IP "\-V, \-\-version"
215 Show the version number of ltrace and exit.
216
217 .SH FILTER SPECIFICATIONS
218
219 Filters are specified with the \-l, \-e and \-x options. In short they mean:
220 .IP "\fI\-x\fR is \'show me what calls these symbols (including local calls)\'"
221 .IP "\fI\-e\fR is \'show me what calls these symbols (inter-library calls only)\'"
222 .IP "\fI\-l\fR is \'show me what calls into this library\'"
223 .PP
224 ..
225 .de Vb \" Begin verbatim text
226 .ft CW
227 .nf
228 .ne \\$1
229 ..
230 .de Ve \" End verbatim text
231 .ft R
232 .fi
233 ..
234 Suppose I have a library defined with this header \fBtstlib.h\fR:
235 .PP
236 .Vb 6
237 \& #pragma once
238 \& void func_f_lib(void);
239 \& void func_g_lib(void);
240 .Ve
241 .PP
242 and this implementation \fBtstlib.c\fR:
243 .PP
244 .Vb 6
245 \& #include "tstlib.h"
246 \& void func_f_lib(void)
247 \& {
248 \&     func_g_lib();
249 \& }
250 \& void func_g_lib(void)
251 \& {
252 \& }
253 .Ve
254 .PP
255 Suppose I have an executable that uses this library defined like this \fBtst.c\fR:
256 .PP
257 .Vb 6
258 \& #include "tstlib.h"
259 \& void func_f_main(void)
260 \& {
261 \& }
262 \& void main(void)
263 \& {
264 \&     func_f_main();
265 \&     func_f_lib();
266 \& }
267 .Ve
268 .PP
269 If linking without \fB-Bsymbolic\fR, the internal \fBfunc_g_lib()\fR call uses
270 the PLT like external calls, and thus ltrace says:
271 .PP
272 .Vb 6
273 \& \fB$ ltrace -x 'func*' -L ./tst\fR
274 \& func_f_main()                             = <void>
275 \& func_f_lib@tstlib.so( <unfinished ...>
276 \& func_g_lib@tstlib.so()                    = <void>
277 \& <... func_f_lib resumed> )                = <void>
278 \& +++ exited (status 163) +++
279 .Ve
280
281 .Vb 6
282 \& \fB$ ltrace -e 'func*' ./tst\fR
283 \& tst->func_f_lib( <unfinished ...>
284 \& tstlib.so->func_g_lib()                   = <void>
285 \& <... func_f_lib resumed> )                = <void>
286 \& +++ exited (status 163) +++
287 .Ve
288
289 .Vb 6
290 \& \fB$ ltrace -l tstlib.so ./tst\fR
291 \& tst->func_f_lib( <unfinished ...>
292 \& tstlib.so->func_g_lib()                   = <void>
293 \& <... func_f_lib resumed> )                = <void>
294 \& +++ exited (status 163) +++
295 .Ve
296 .PP
297 By contrast, if linking with \fB-Bsymbolic\fR, then the internal
298 \fBfunc_g_lib()\fR call bypasses the PLT, and ltrace says:
299 .PP
300 .Vb 6
301 \& \fB$ ltrace -x 'func*' -L ./tst\fR
302 \& func_f_main() = <void>
303 \& func_f_lib@tstlib.so( <unfinished ...>
304 \& func_g_lib@tstlib.so()                    = <void>
305 \& <... func_f_lib resumed> )                = <void>
306 \& +++ exited (status 163) +++
307 .Ve
308
309 .Vb 6
310 \& \fB$ ltrace -e 'func*' ./tst\fR
311 \& tst->func_f_lib()                         = <void>
312 \& +++ exited (status 163) +++
313 .Ve
314
315 .Vb 6
316 \& \fB$ ltrace -l tstlib.so ./tst\fR
317 \& tst->func_f_lib()                         = <void>
318 \& +++ exited (status 163) +++
319 .Ve
320 .PP
321 .SH FILTER EXPRESSIONS
322
323 Filter expression is a chain of glob- or regexp-based rules that are
324 used to pick symbols for tracing from libraries that the process uses.
325 Most of it is intuitive, so as an example, the following would trace
326 calls to malloc and free, except those done by libc:
327
328 -e malloc+free-@libc.so*
329
330 This reads: trace malloc and free, but don't trace anything that comes
331 from libc.  Semi-formally, the syntax of the above example looks
332 approximately like this:
333
334 {[+-][\fIsymbol_pattern\fR][@\fIlibrary_pattern\fR]}
335
336 \fISymbol_pattern\fR is used to match symbol names,
337 \fIlibrary_pattern\fR to match library SONAMEs.  Both are implicitly
338 globs, but can be regular expressions as well (see below).  The glob
339 syntax supports meta-characters \fB*\fR and \fB?\fR and character
340 classes, similarly to what basic bash globs support.  \fB^\fR and
341 \fB$\fR are recognized to mean, respectively, start and end of given
342 name.
343
344 Both \fIsymbol_pattern\fR and \fIlibrary_pattern\fR have to match the
345 whole name.  If you want to match only part of the name, surround it
346 with one or two *'s as appropriate.  The exception is if the pattern
347 is not mentioned at all, in which case it's as if the corresponding
348 pattern were \fB*\fR.  (So \fBmalloc\fR is really \fBmalloc@*\fR and
349 \fB@libc.*\fR is really \fB*@libc.*\fR.)
350
351 In libraries that don't have an explicit SONAME, basename is taken for
352 SONAME.  That holds for main binary as well: \fB/bin/echo\fR has an
353 implicit SONAME of \fBecho\fR.  In addition to that, special library
354 pattern \fBMAIN\fR always matches symbols in the main binary and never
355 a library with actual SONAME \fBMAIN\fR (use e.g. \fB^MAIN\fR or
356 \fB[M]AIN\fR for that).
357
358 If the symbol or library pattern is surrounded in slashes (/like
359 this/), then it is considered a regular expression instead.  As a
360 shorthand, instead of writing \fB/x/@/y/\fR, you can write
361 \fB/x@y/\fR.
362
363 If the library pattern starts with a slash, it is not a SONAME
364 expression, but a path expression, and is matched against the library
365 path name.
366
367 The first rule may lack a sign, in which case \fB+\fR is assumed.  If,
368 on the other hand, the first rule has a \fB-\fR sign, it is as if
369 there was another rule \fB@\fR in front of it, which has the effect of
370 tracing complement of given rule.
371
372 The above rules are used to construct the set of traced symbols.  Each
373 candidate symbol is passed through the chain of above rules.
374 Initially, the symbol is \fIunmarked\fR.  If it matches a \fB+\fR
375 rule, it becomes \fImarked\fR, if it matches a \fB-\fR rule, it
376 becomes \fIunmarked\fR again.  If, after applying all rules, the
377 symbol is \fImarked\fR, it will be traced.
378
379 .SH PROTOTYPE LIBRARY DISCOVERY
380
381 When a library is mapped into the address space of a traced process,
382 ltrace needs to know what the prototypes are of functions that this
383 library implements.  For purposes of ltrace, prototype really is a bit
384 more than just type signature: it's also formatting of individual
385 parameters and of return value.  These prototypes are stored in files
386 called prototype libraries.
387
388 After a library is mapped, ltrace finds out what its SONAME is.  It
389 then looks for a file named SONAME.conf--e.g. protolib for libc.so.6
390 would be in a file called libc.so.6.conf.  When such file is found
391 (more about where ltrace looks for these files is below), ltrace reads
392 all prototypes stored therein.  When a symbol table entry point (such
393 as those traced by \-x) is hit, the prototype is looked up in a
394 prototype library corresponding to the library where the hit occurred.
395 When a library call (such as those traced by \-e and \-l) is hit, the
396 prototype is looked up in all prototype libraries loaded for given
397 process.  That is necessary, because a library call is traced in a PLT
398 table of a caller library, but the prototype is described at callee
399 library.
400
401 If a library has no SONAME, basename of library file is considered
402 instead.  For the main program binary, basename is considered as well
403 (e.g. protolib for /bin/echo would be called echo.conf).  If a name
404 corresponding to soname (e.g. libc.so.6.conf) is not found, and the
405 module under consideration is a shared library, ltrace also tries
406 partial matches.  Ltrace snips one period after another, retrying the
407 search, until either a protolib is found, or X.so is all that's left.
408 Thus libc.so.conf would be considered, but libc.conf not.
409
410 When looking for a prototype library, ltrace potentially looks into
411 several directories.  On Linux, those are $XDG_CONFIG_HOME/ltrace,
412 $HOME/.ltrace, \fIX\fR/ltrace for each \fIX\fR in $XDG_CONFIG_DIRS and
413 /usr/share/ltrace.  If the environment variable XDG_CONFIG_HOME is not
414 defined, ltrace looks into $HOME/.config/ltrace instead.
415
416 There's also a mechanism for loading legacy config files.  If
417 $HOME/.ltrace.conf exists it is imported to every loaded prototype
418 library.  Similarly for /etc/ltrace.conf.  If both exist, both are
419 imported, and $HOME/.ltrace.conf is consulted before /etc/ltrace.conf.
420
421 If \-F contains any directories, those are searched in precedence to
422 the above system directories, in the same order in which they are
423 mentioned in \-F.  Any files passed in \-F are imported similarly to
424 above legacy config files, before them.
425
426 See ltrace.conf(5) for details on the syntax of ltrace prototype
427 library files.
428
429 .SH BUGS
430 It has most of the bugs stated in
431 .BR strace(1) .
432 .LP
433 It only works on Linux and in some architectures.
434 .LP
435 .PP
436 If you would like to report a bug, send a message to the mailing list
437 (ltrace-devel@lists.alioth.debian.org), or use the
438 .BR reportbug(1)
439 program if you are under the Debian GNU/Linux distribution.
440
441 .SH FILES
442 .TP
443 .I /etc/ltrace.conf
444 System configuration file
445 .TP
446 .I ~/.ltrace.conf
447 Personal config file, overrides
448 .I /etc/ltrace.conf
449
450 .SH AUTHOR
451 Juan Cespedes <cespedes@debian.org>
452 .br
453 Petr Machata <pmachata@redhat.com>
454
455 .SH "SEE ALSO"
456 .BR ltrace.conf(5),
457 .BR strace(1) ,
458 .BR ptrace(2)