blob: 4c007cd414f72b26a049111ffdc6c886a86608ec [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001.\" Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
2.\" Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
3.\" Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. The name of the author may not be used to endorse or promote products
15.\" derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.\" $Id$
29.\"
30.de CW
31.sp
32.nf
33.ft CW
34..
35.de CE
Wichert Akkerman8829a551999-06-11 13:18:40 +000036.ft R
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037.fi
38.sp
39..
Dmitry V. Levina7835e62010-03-31 17:26:49 +000040.TH STRACE 1 "2010-03-30"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041.SH NAME
42strace \- trace system calls and signals
43.SH SYNOPSIS
44.B strace
45[
Grant Edwards8a082772011-04-07 20:25:40 +000046.B \-CdDffhiqrtttTvxxy
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047]
48[
49.BI \-a column
50]
51[
52.BI \-e expr
53]
54\&...
55[
56.BI \-o file
57]
58[
59.BI \-p pid
60]
61\&...
62[
Grant Edwards8a082772011-04-07 20:25:40 +000063.BI \-P path
64]
65\&...
66[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067.BI \-s strsize
68]
69[
70.BI \-u username
71]
72[
Roland McGrath4417fda2003-01-24 04:31:20 +000073.BI \-E var=val
74]
75\&...
76[
77.BI \-E var
78]
79\&...
80[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081.I command
82[
83.I arg
84\&...
85]
86]
87.sp
88.B strace
89.B \-c
90[
Andreas Schwabb87d30c2010-06-11 15:49:36 +020091.B \-D
92]
93[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000094.BI \-e expr
95]
96\&...
97[
98.BI \-O overhead
99]
100[
101.BI \-S sortby
102]
103[
104.I command
105[
106.I arg
107\&...
108]
109]
110.SH DESCRIPTION
111.IX "strace command" "" "\fLstrace\fR command"
112.LP
113In the simplest case
114.B strace
115runs the specified
116.I command
117until it exits.
118It intercepts and records the system calls which are called
119by a process and the signals which are received by a process.
120The name of each system call, its arguments and its return value
121are printed on standard error or to the file specified with the
122.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +0000123option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124.LP
125.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000126is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +0000127System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128it invaluable for solving problems with
129programs for which the source is not readily available since
130they do not need to be recompiled in order to trace them.
131Students, hackers and the overly-curious will find that
132a great deal can be learned about a system and its system calls by
133tracing even ordinary programs. And programmers will find that
134since system calls and signals are events that happen at the user/kernel
135interface, a close examination of this boundary is very
136useful for bug isolation, sanity checking and
137attempting to capture race conditions.
138.LP
139Each line in the trace contains the system call name, followed
140by its arguments in parentheses and its return value.
141An example from stracing the command ``cat /dev/null'' is:
142.CW
143open("/dev/null", O_RDONLY) = 3
144.CE
145Errors (typically a return value of \-1) have the errno symbol
146and error string appended.
147.CW
148open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
149.CE
150Signals are printed as a signal symbol and a signal string.
151An excerpt from stracing and interrupting the command ``sleep 666'' is:
152.CW
153sigsuspend([] <unfinished ...>
154--- SIGINT (Interrupt) ---
155+++ killed by SIGINT +++
156.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000157If a system call is being executed and meanwhile another one is being called
158from a different thread/process then
159.B strace
160will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000161being
162.IR unfinished .
163When the call returns it will be marked as
164.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000165.CW
166[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
167[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
168[pid 28772] <... select resumed> ) = 1 (in [3])
169.CE
170Interruption of a (restartable) system call by a signal delivery is processed
171differently as kernel terminates the system call and also arranges its
172immediate reexecution after the signal handler completes.
173.CW
174read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
175--- SIGALRM (Alarm clock) @ 0 (0) ---
176rt_sigreturn(0xe) = 0
177read(0, ""..., 1) = 0
178.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000180This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181.CW
182open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
183.CE
Dmitry V. Levin9b3eb842012-02-22 00:29:44 +0000184Here the third argument of open is decoded by breaking down the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185flag argument into its three bitwise-OR constituents and printing the
186mode value in octal by tradition. Where traditional or native
187usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000188In some cases,
189.B strace
190output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191.LP
192Structure pointers are dereferenced and the members are displayed
193as appropriate. In all cases arguments are formatted in the most C-like
194fashion possible.
195For example, the essence of the command ``ls \-l /dev/null'' is captured as:
196.CW
197lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
198.CE
199Notice how the `struct stat' argument is dereferenced and how each member is
200displayed symbolically. In particular, observe how the st_mode member
201is carefully decoded into a bitwise-OR of symbolic and numeric values.
202Also notice in this example that the first argument to lstat is an input
203to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000204arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205always be dereferenced. For example, retrying the ``ls \-l'' example
206with a non-existent file produces the following line:
207.CW
208lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
209.CE
210In this case the porch light is on but nobody is home.
211.LP
212Character pointers are dereferenced and printed as C strings.
213Non-printing characters in strings are normally represented by
214ordinary C escape codes.
215Only the first
216.I strsize
217(32 by default) bytes of strings are printed;
218longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000219Here is a line from ``ls \-l'' where the
220.B getpwuid
221library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222.CW
223read(3, "root::0:0:System Administrator:/"..., 1024) = 422
224.CE
225While structures are annotated using curly braces, simple pointers
226and arrays are printed using square brackets with commas separating
227elements. Here is an example from the command ``id'' on a system with
228supplementary group ids:
229.CW
230getgroups(32, [100, 0]) = 2
231.CE
232On the other hand, bit-sets are also shown using square brackets
233but set elements are separated only by a space. Here is the shell
234preparing to execute an external command:
235.CW
236sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
237.CE
238Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
239In some cases the bit-set is so full that printing out the unset
240elements is more valuable. In that case, the bit-set is prefixed by
241a tilde like this:
242.CW
243sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
244.CE
245Here the second argument represents the full set of all signals.
246.SH OPTIONS
247.TP 12
248.TP
249.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000250Count time, calls, and errors for each system call and report a summary on
251program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000252running in the kernel) independent of wall clock time. If
253.B \-c
254is used with
255.B \-f
256or
257.B \-F
258(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000260.B \-C
261Like
262.B \-c
263but also print regular output while processes are running.
264.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200265.B \-D
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200266Run tracer process as a detached grandchild, not as parent of the
267tracee. This reduces the visible effect of
268.B strace
269by keeping the tracee a direct child of the calling process.
270.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000272Show some debugging output of
273.B strace
274itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275.TP
276.B \-f
277Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000278processes as a result of the
279.BR fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000280system call.
281.IP
282On non-Linux platforms the new process is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283attached to as soon as its pid is known (through the return value of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000284.BR fork (2)
285in the parent process). This means that such children may run
286uncontrolled for a while (especially in the case of a
287.BR vfork (2)),
288until the parent is scheduled again to complete its
289.RB ( v ) fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000290call. On Linux the child is traced from its first instruction with no delay.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000291If the parent process decides to
292.BR wait (2)
293for a child that is currently
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294being traced, it is suspended until an appropriate child process either
295terminates or incurs a signal that would cause it to terminate (as
296determined from the child's current signal disposition).
297.TP
298.B \-ff
299If the
300.B \-o
301.I filename
302option is in effect, each processes trace is written to
303.I filename.pid
304where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000305This is incompatible with
306.BR \-c ,
307since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308.TP
309.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000310This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000311.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312.TP
313.B \-h
314Print the help summary.
315.TP
316.B \-i
317Print the instruction pointer at the time of the system call.
318.TP
319.B \-q
320Suppress messages about attaching, detaching etc. This happens
321automatically when output is redirected to a file and the command
322is run directly instead of attaching.
323.TP
324.B \-r
325Print a relative timestamp upon entry to each system call. This
326records the time difference between the beginning of successive
327system calls.
328.TP
329.B \-t
330Prefix each line of the trace with the time of day.
331.TP
332.B \-tt
333If given twice, the time printed will include the microseconds.
334.TP
335.B \-ttt
336If given thrice, the time printed will include the microseconds
337and the leading portion will be printed as the number
338of seconds since the epoch.
339.TP
340.B \-T
341Show the time spent in system calls. This records the time
342difference between the beginning and the end of each system call.
343.TP
344.B \-v
345Print unabbreviated versions of environment, stat, termios, etc.
346calls. These structures are very common in calls and so the default
347behavior displays a reasonable subset of structure members. Use
348this option to get all of the gory details.
349.TP
350.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000351Print the version number of
352.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353.TP
354.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000355Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356.TP
357.B \-xx
358Print all strings in hexadecimal string format.
359.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000360.B \-y
361Print paths associated with file descriptor arguments.
362.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000364Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365.TP
366.BI "\-e " expr
367A qualifying expression which modifies which events to trace
368or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000369.RS 15
370.IP
371[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
372.RE
373.IP
374where
375.I qualifier
376is one of
377.BR trace ,
378.BR abbrev ,
379.BR verbose ,
380.BR raw ,
381.BR signal ,
382.BR read ,
383or
384.B write
385and
386.I value
387is a qualifier-dependent symbol or number. The default
388qualifier is
389.BR trace .
390Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000391.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000392means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000393.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000394which in turn means trace only the
395.B open
396system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000397.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000398means to trace every system call except
399.BR open .
400In addition, the special values
401.B all
402and
403.B none
404have the obvious meanings.
405.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000407expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408the exclamation point with a backslash.
409.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000410\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411Trace only the specified set of system calls. The
412.B \-c
413option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000414to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000415.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000416means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417trace those four system calls. Be careful when making inferences
418about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000419are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000420.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000422.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423Trace all system calls which take a file name as an argument. You
424can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000425.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426which is useful to seeing what files the process is referencing.
427Furthermore, using the abbreviation will ensure that you don't
428accidentally forget to include a call like
429.B lstat
430in the list. Betchya woulda forgot that one.
431.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000432.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433Trace all system calls which involve process management. This
434is useful for watching the fork, wait, and exec steps of a process.
435.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000436.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437Trace all the network related system calls.
438.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000439.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440Trace all signal related system calls.
441.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000442.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443Trace all IPC related system calls.
444.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000445.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000446Trace all file descriptor related system calls.
447.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000448\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000450The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000451.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000452The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000454option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000455.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000457\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000459default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000460.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000462\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000463Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464This option has the effect of causing all arguments to be printed
465in hexadecimal. This is mostly useful if you don't trust the
466decoding or you need to know the actual numeric value of an
467argument.
468.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000469\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000470Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000471.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000472For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000473.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000474(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000475.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000476causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000478\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000479Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000481all input activity on file descriptors
482.I 3
483and
484.I 5
485use
486\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000487Note that this is independent from the normal tracing of the
488.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000490.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000492\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000493Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000495all output activity on file descriptors
496.I 3
497and
498.I 5
499use
500\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000501Note that this is independent from the normal tracing of the
502.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000504.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505.TP
506.BI "\-o " filename
507Write the trace output to the file
508.I filename
509rather than to stderr.
510Use
511.I filename.pid
512if
513.B \-ff
514is used.
515If the argument begins with `|' or with `!' then the rest of the
516argument is treated as a command and all output is piped to it.
517This is convenient for piping the debugging output to a program
518without affecting the redirections of executed programs.
519.TP
520.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000521Set the overhead for tracing system calls to
522.I overhead
523microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524This is useful for overriding the default heuristic for guessing
525how much time is spent in mere measuring when timing system calls using
526the
527.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000528option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000529program run without tracing (using
530.BR time (1))
531and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000533.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534.TP
535.BI "\-p " pid
536Attach to the process with the process
537.SM ID
538.I pid
539and begin tracing.
540The trace may be terminated
541at any time by a keyboard interrupt signal (\c
542.SM CTRL\s0-C).
543.B strace
544will respond by detaching itself from the traced process(es)
545leaving it (them) to continue running.
546Multiple
547.B \-p
548options can be used to attach to up to 32 processes in addition to
549.I command
550(which is optional if at least one
551.B \-p
552option is given).
553.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000554.BI "\-P " path
555Trace only system calls accessing
556.I path.
557Multiple
558.B \-P
559options can be used to specify up to 256 paths.
560.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561.BI "\-s " strsize
562Specify the maximum string size to print (the default is 32). Note
563that filenames are not considered strings and are always printed in
564full.
565.TP
566.BI "\-S " sortby
567Sort the output of the histogram printed by the
568.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000569option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000570.BR time ,
571.BR calls ,
572.BR name ,
573and
574.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000575(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000576.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577.TP
578.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000579Run command with the user \s-1ID\s0, group \s-2ID\s0, and
580supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581.IR username .
582This option is only useful when running as root and enables the
583correct execution of setuid and/or setgid binaries.
584Unless this option is used setuid and setgid programs are executed
585without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000586.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000587\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000588Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000589.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000590in its list of environment variables.
591.TP
592.BI "\-E " var
593Remove
594.IR var
595from the inherited list of environment variables before passing it on to
596the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000597.SH DIAGNOSTICS
598When
599.I command
600exits,
601.B strace
602exits with the same exit status.
603If
604.I command
605is terminated by a signal,
606.B strace
607terminates itself with the same signal, so that
608.B strace
609can be used as a wrapper process transparent to the invoking parent process.
610.LP
611When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000612.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000613the exit status of
614.B strace
615is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616.SH "SETUID INSTALLATION"
617If
618.B strace
619is installed setuid to root then the invoking user will be able to
620attach to and trace processes owned by any user.
621In addition setuid and setgid programs will be executed and traced
622with the correct effective privileges.
623Since only users trusted with full root privileges should be allowed
624to do these things,
625it only makes sense to install
626.B strace
627as setuid to root when the users who can execute it are restricted
628to those users who have this trust.
629For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000630.B strace
631with mode `rwsr-xr--', user
632.B root
633and group
634.BR trace ,
635where members of the
636.B trace
637group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000639a non-setuid version of
640.B strace
641for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000643.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000644.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000645.BR ptrace (2),
646.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647.SH NOTES
648It is a pity that so much tracing clutter is produced by systems
649employing shared libraries.
650.LP
651It is instructive to think about system call inputs and outputs
652as data-flow across the user/kernel boundary. Because user-space
653and kernel-space are separate and address-protected, it is
654sometimes possible to make deductive inferences about process
655behavior using inputs and outputs as propositions.
656.LP
657In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000658or have a different name. For example, on System V-derived systems
659the true
660.BR time (2)
661system call does not take an argument and the
662.B stat
663function is called
664.B xstat
665and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666discrepancies are normal but idiosyncratic characteristics of the
667system call interface and are accounted for by C library wrapper
668functions.
669.LP
670On some platforms a process that has a system call trace applied
671to it with the
672.B \-p
673option will receive a
674.BR \s-1SIGSTOP\s0 .
675This signal may interrupt a system call that is not restartable.
676This may have an unpredictable effect on the process
677if the process takes no action to restart the system call.
678.SH BUGS
679Programs that use the
680.I setuid
681bit do not have
682effective user
683.SM ID
684privileges while being traced.
685.LP
686A traced process ignores
687.SM SIGSTOP
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000688except on SVR4 platforms.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689.LP
690A traced process which tries to block SIGTRAP will be sent a SIGSTOP
691in an attempt to force continuation of tracing.
692.LP
693A traced process runs slowly.
694.LP
695Traced processes which are descended from
696.I command
697may be left running after an interrupt signal (\c
698.SM CTRL\s0-C).
699.LP
700On Linux, exciting as it would be, tracing the init process is forbidden.
701.LP
702The
703.B \-i
704option is weakly supported.
705.SH HISTORY
706.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000707The original
708.B strace
709was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000711The SunOS version of
712.B strace
713was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000715Even though Paul released
716.B strace
7172.5 in 1992,
718Branko's work was based on Paul's
719.B strace
7201.5 release from 1991.
721In 1993, Rick Sladkey merged
722.B strace
7232.5 for SunOS and the second release of
724.B strace
725for Linux, added many of the features of
726.BR truss (1)
727from SVR4, and produced an
728.B strace
729that worked on both platforms. In 1994 Rick ported
730.B strace
731to SVR4 and Solaris and wrote the
732automatic configuration support. In 1995 he ported
733.B strace
734to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735and tired of writing about himself in the third person.
Roland McGrath98a3ecf2008-08-28 23:41:57 +0000736.SH BUGS
737The SIGTRAP signal is used internally by the kernel implementation of
738system call tracing. When a traced process receives a SIGTRAP signal not
739associated with tracing, strace will not report that signal correctly.
740This signal is not normally used by programs, but could be via a hard-coded
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000741break instruction or via
742.BR kill (2).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743.SH PROBLEMS
744Problems with
745.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100746should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000748mailing list at <strace\-devel@lists.sourceforge.net>.