blob: 2a24c38304cf1124fd26b24ec9e9a88d756d003d [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000027.de CW
28.sp
29.nf
30.ft CW
31..
32.de CE
Wichert Akkerman8829a551999-06-11 13:18:40 +000033.ft R
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034.fi
35.sp
36..
Dmitry V. Levina1978322014-06-03 12:03:41 +000037.\" Macro IX is not defined in the groff macros
38.if \n(.g \{\
39. de IX
40..
41.\}
Dmitry V. Levina7835e62010-03-31 17:26:49 +000042.TH STRACE 1 "2010-03-30"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043.SH NAME
44strace \- trace system calls and signals
45.SH SYNOPSIS
46.B strace
Luca Clementi327064b2013-07-23 00:11:35 -070047[\fB-CdffhikqrtttTvVxxy\fR]
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020048[\fB-I\fIn\fR]
Denys Vlasenko22efaf02013-02-27 12:15:19 +010049[\fB-b\fIexecve\fR]
50[\fB-e\fIexpr\fR]...
51[\fB-a\fIcolumn\fR]
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020052[\fB-o\fIfile\fR]
53[\fB-s\fIstrsize\fR]
54[\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
55[\fB-D\fR]
56[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
57\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058.sp
59.B strace
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020060\fB-c\fR[\fBdf\fR]
61[\fB-I\fIn\fR]
Denys Vlasenko22efaf02013-02-27 12:15:19 +010062[\fB-b\fIexecve\fR]
63[\fB-e\fIexpr\fR]...
64[\fB-O\fIoverhead\fR]
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020065[\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
66[\fB-D\fR]
67[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
68\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069.SH DESCRIPTION
70.IX "strace command" "" "\fLstrace\fR command"
71.LP
72In the simplest case
73.B strace
74runs the specified
75.I command
76until it exits.
77It intercepts and records the system calls which are called
78by a process and the signals which are received by a process.
79The name of each system call, its arguments and its return value
80are printed on standard error or to the file specified with the
81.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +000082option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083.LP
84.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +000085is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +000086System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087it invaluable for solving problems with
88programs for which the source is not readily available since
89they do not need to be recompiled in order to trace them.
90Students, hackers and the overly-curious will find that
91a great deal can be learned about a system and its system calls by
92tracing even ordinary programs. And programmers will find that
93since system calls and signals are events that happen at the user/kernel
94interface, a close examination of this boundary is very
95useful for bug isolation, sanity checking and
96attempting to capture race conditions.
97.LP
98Each line in the trace contains the system call name, followed
99by its arguments in parentheses and its return value.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200100An example from stracing the command "cat /dev/null" is:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101.CW
102open("/dev/null", O_RDONLY) = 3
103.CE
104Errors (typically a return value of \-1) have the errno symbol
105and error string appended.
106.CW
Dmitry V. Levina1978322014-06-03 12:03:41 +0000107open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108.CE
Denys Vlasenkob5370532013-06-26 15:35:16 +0200109Signals are printed as signal symbol and decoded siginfo structure.
110An excerpt from stracing and interrupting the command "sleep 666" is:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111.CW
112sigsuspend([] <unfinished ...>
Denys Vlasenkob5370532013-06-26 15:35:16 +0200113--- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114+++ killed by SIGINT +++
115.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000116If a system call is being executed and meanwhile another one is being called
117from a different thread/process then
118.B strace
119will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000120being
121.IR unfinished .
122When the call returns it will be marked as
123.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000124.CW
125[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
126[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
127[pid 28772] <... select resumed> ) = 1 (in [3])
128.CE
129Interruption of a (restartable) system call by a signal delivery is processed
130differently as kernel terminates the system call and also arranges its
131immediate reexecution after the signal handler completes.
132.CW
133read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
Denys Vlasenkob5370532013-06-26 15:35:16 +0200134--- SIGALRM ... ---
Jan Kratochvil14256a72008-09-12 08:44:30 +0000135rt_sigreturn(0xe) = 0
Denys Vlasenkob5370532013-06-26 15:35:16 +0200136read(0, "", 1) = 0
Jan Kratochvil14256a72008-09-12 08:44:30 +0000137.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138Arguments are printed in symbolic form with a passion.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200139This example shows the shell performing ">>xyzzy" output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140.CW
141open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
142.CE
Dmitry V. Levin9b3eb842012-02-22 00:29:44 +0000143Here the third argument of open is decoded by breaking down the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144flag argument into its three bitwise-OR constituents and printing the
145mode value in octal by tradition. Where traditional or native
146usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000147In some cases,
148.B strace
149output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150.LP
151Structure pointers are dereferenced and the members are displayed
152as appropriate. In all cases arguments are formatted in the most C-like
153fashion possible.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200154For example, the essence of the command "ls \-l /dev/null" is captured as:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155.CW
156lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
157.CE
Denys Vlasenkob5370532013-06-26 15:35:16 +0200158Notice how the 'struct stat' argument is dereferenced and how each member is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159displayed symbolically. In particular, observe how the st_mode member
160is carefully decoded into a bitwise-OR of symbolic and numeric values.
161Also notice in this example that the first argument to lstat is an input
162to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000163arguments are not modified if the system call fails, arguments may not
Denys Vlasenkob5370532013-06-26 15:35:16 +0200164always be dereferenced. For example, retrying the "ls \-l" example
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165with a non-existent file produces the following line:
166.CW
Dmitry V. Levina1978322014-06-03 12:03:41 +0000167lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168.CE
169In this case the porch light is on but nobody is home.
170.LP
171Character pointers are dereferenced and printed as C strings.
172Non-printing characters in strings are normally represented by
173ordinary C escape codes.
174Only the first
175.I strsize
176(32 by default) bytes of strings are printed;
177longer strings have an ellipsis appended following the closing quote.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200178Here is a line from "ls \-l" where the
Wichert Akkerman8829a551999-06-11 13:18:40 +0000179.B getpwuid
180library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181.CW
182read(3, "root::0:0:System Administrator:/"..., 1024) = 422
183.CE
184While structures are annotated using curly braces, simple pointers
185and arrays are printed using square brackets with commas separating
Denys Vlasenkob5370532013-06-26 15:35:16 +0200186elements. Here is an example from the command "id" on a system with
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187supplementary group ids:
188.CW
189getgroups(32, [100, 0]) = 2
190.CE
191On the other hand, bit-sets are also shown using square brackets
192but set elements are separated only by a space. Here is the shell
193preparing to execute an external command:
194.CW
195sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
196.CE
197Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
198In some cases the bit-set is so full that printing out the unset
199elements is more valuable. In that case, the bit-set is prefixed by
200a tilde like this:
201.CW
202sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
203.CE
204Here the second argument represents the full set of all signals.
205.SH OPTIONS
206.TP 12
207.TP
208.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000209Count time, calls, and errors for each system call and report a summary on
210program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000211running in the kernel) independent of wall clock time. If
212.B \-c
213is used with
214.B \-f
215or
216.B \-F
217(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000219.B \-C
220Like
221.B \-c
222but also print regular output while processes are running.
223.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200224.B \-D
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200225Run tracer process as a detached grandchild, not as parent of the
226tracee. This reduces the visible effect of
227.B strace
228by keeping the tracee a direct child of the calling process.
229.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000231Show some debugging output of
232.B strace
233itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234.TP
235.B \-f
236Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000237processes as a result of the
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100238.BR fork (2),
239.BR vfork (2)
240and
241.BR clone (2)
Dmitry V. Levina1978322014-06-03 12:03:41 +0000242system calls. Note that
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100243.B \-p
244.I PID
245.B \-f
246will attach all threads of process PID if it is multi-threaded,
247not only thread with thread_id = PID.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248.TP
249.B \-ff
250If the
251.B \-o
252.I filename
253option is in effect, each processes trace is written to
254.I filename.pid
255where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000256This is incompatible with
257.BR \-c ,
258since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259.TP
260.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000261This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000262.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263.TP
264.B \-h
265Print the help summary.
266.TP
267.B \-i
268Print the instruction pointer at the time of the system call.
269.TP
Luca Clementi327064b2013-07-23 00:11:35 -0700270.B \-k
Dmitry V. Levin2734a702014-06-18 15:34:27 +0000271Print the execution stack trace of the traced processes after each system call (experimental).
Luca Clementi327064b2013-07-23 00:11:35 -0700272.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273.B \-q
274Suppress messages about attaching, detaching etc. This happens
275automatically when output is redirected to a file and the command
276is run directly instead of attaching.
277.TP
Daniel P. Berrange01997cf2013-05-13 11:30:55 +0100278.B \-qq
Dmitry V. Levine8ff4c62013-05-28 20:27:10 +0000279If given twice, suppress messages about process exit status.
Daniel P. Berrange01997cf2013-05-13 11:30:55 +0100280.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281.B \-r
282Print a relative timestamp upon entry to each system call. This
283records the time difference between the beginning of successive
284system calls.
285.TP
286.B \-t
287Prefix each line of the trace with the time of day.
288.TP
289.B \-tt
290If given twice, the time printed will include the microseconds.
291.TP
292.B \-ttt
293If given thrice, the time printed will include the microseconds
294and the leading portion will be printed as the number
295of seconds since the epoch.
296.TP
297.B \-T
Dmitry V. Levina1978322014-06-03 12:03:41 +0000298Show the time spent in system calls. This records the time
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299difference between the beginning and the end of each system call.
300.TP
Mark Hillse53bf232014-05-28 17:52:40 +0100301.B \-w
302Summarise the time difference between the beginning and end of
Dmitry V. Levina1978322014-06-03 12:03:41 +0000303each system call. The default is to summarise the system time.
Mark Hillse53bf232014-05-28 17:52:40 +0100304.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305.B \-v
306Print unabbreviated versions of environment, stat, termios, etc.
307calls. These structures are very common in calls and so the default
308behavior displays a reasonable subset of structure members. Use
309this option to get all of the gory details.
310.TP
311.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000312Print the version number of
313.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314.TP
315.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000316Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317.TP
318.B \-xx
319Print all strings in hexadecimal string format.
320.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000321.B \-y
322Print paths associated with file descriptor arguments.
323.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000325Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326.TP
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100327.BI "\-b " syscall
328If specified syscall is reached, detach from traced process.
329Currently, only
330.I execve
Dmitry V. Levina1978322014-06-03 12:03:41 +0000331syscall is supported. This option is useful if you want to trace
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100332multi-threaded process and therefore require -f, but don't want
333to trace its (potentially very complex) children.
334.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335.BI "\-e " expr
336A qualifying expression which modifies which events to trace
337or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000338.RS 15
339.IP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000340[\,\fIqualifier\/\fB=\fR][\fB!\fR]\,\fIvalue1\/\fR[\fB,\,\fIvalue2\/\fR]...
Wichert Akkerman8829a551999-06-11 13:18:40 +0000341.RE
342.IP
343where
344.I qualifier
345is one of
346.BR trace ,
347.BR abbrev ,
348.BR verbose ,
349.BR raw ,
350.BR signal ,
351.BR read ,
352or
353.B write
354and
355.I value
356is a qualifier-dependent symbol or number. The default
357qualifier is
358.BR trace .
359Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000360.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000361means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000362.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000363which in turn means trace only the
364.B open
365system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000366.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000367means to trace every system call except
368.BR open .
369In addition, the special values
370.B all
371and
372.B none
373have the obvious meanings.
374.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000376expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377the exclamation point with a backslash.
378.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000379\fB\-e\ trace\fR=\,\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380Trace only the specified set of system calls. The
381.B \-c
382option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000383to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000384.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000385means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386trace those four system calls. Be careful when making inferences
387about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000388are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000389.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000391.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392Trace all system calls which take a file name as an argument. You
393can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000394.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395which is useful to seeing what files the process is referencing.
396Furthermore, using the abbreviation will ensure that you don't
397accidentally forget to include a call like
398.B lstat
399in the list. Betchya woulda forgot that one.
400.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000401.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402Trace all system calls which involve process management. This
403is useful for watching the fork, wait, and exec steps of a process.
404.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000405.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406Trace all the network related system calls.
407.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000408.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409Trace all signal related system calls.
410.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000411.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412Trace all IPC related system calls.
413.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000414.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000415Trace all file descriptor related system calls.
416.TP
Namhyung Kim96792962012-10-24 11:41:57 +0900417.BR "\-e\ trace" = memory
418Trace all memory mapping related system calls.
419.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000420\fB\-e\ abbrev\fR=\,\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000422The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000423.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000424The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000426option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000427.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000429\fB\-e\ verbose\fR=\,\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000431default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000432.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000434\fB\-e\ raw\fR=\,\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000435Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436This option has the effect of causing all arguments to be printed
437in hexadecimal. This is mostly useful if you don't trust the
438decoding or you need to know the actual numeric value of an
439argument.
440.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000441\fB\-e\ signal\fR=\,\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000442Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000443.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000444For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000445.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000446(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000447.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000448causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000450\fB\-e\ read\fR=\,\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000451Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000453all input activity on file descriptors
454.I 3
455and
456.I 5
457use
Dmitry V. Levina1978322014-06-03 12:03:41 +0000458\fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000459Note that this is independent from the normal tracing of the
460.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000462.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000464\fB\-e\ write\fR=\,\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000465Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000467all output activity on file descriptors
468.I 3
469and
470.I 5
471use
Dmitry V. Levina1978322014-06-03 12:03:41 +0000472\fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000473Note that this is independent from the normal tracing of the
474.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000476.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200478.BI "\-I " interruptible
479When strace can be interrupted by signals (such as pressing ^C).
4801: no signals are blocked; 2: fatal signals are blocked while decoding syscall
481(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4824: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
483strace -o FILE PROG not stop on ^Z).
484.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000485.BI "\-o " filename
486Write the trace output to the file
487.I filename
488rather than to stderr.
489Use
490.I filename.pid
491if
492.B \-ff
493is used.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200494If the argument begins with '|' or with '!' then the rest of the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495argument is treated as a command and all output is piped to it.
496This is convenient for piping the debugging output to a program
497without affecting the redirections of executed programs.
498.TP
499.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000500Set the overhead for tracing system calls to
501.I overhead
502microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503This is useful for overriding the default heuristic for guessing
504how much time is spent in mere measuring when timing system calls using
505the
506.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000507option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000508program run without tracing (using
509.BR time (1))
510and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000512.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513.TP
514.BI "\-p " pid
515Attach to the process with the process
516.SM ID
517.I pid
518and begin tracing.
519The trace may be terminated
520at any time by a keyboard interrupt signal (\c
521.SM CTRL\s0-C).
522.B strace
523will respond by detaching itself from the traced process(es)
524leaving it (them) to continue running.
525Multiple
526.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200527options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100528-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000530.BI "\-P " path
531Trace only system calls accessing
532.I path.
533Multiple
534.B \-P
Denys Vlasenko7239dbc2013-03-05 15:46:34 +0100535options can be used to specify several paths.
Grant Edwards8a082772011-04-07 20:25:40 +0000536.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537.BI "\-s " strsize
538Specify the maximum string size to print (the default is 32). Note
539that filenames are not considered strings and are always printed in
540full.
541.TP
542.BI "\-S " sortby
543Sort the output of the histogram printed by the
544.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000545option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000546.BR time ,
547.BR calls ,
548.BR name ,
549and
550.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000551(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000552.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553.TP
554.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000555Run command with the user \s-1ID\s0, group \s-2ID\s0, and
556supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557.IR username .
558This option is only useful when running as root and enables the
559correct execution of setuid and/or setgid binaries.
560Unless this option is used setuid and setgid programs are executed
561without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000562.TP
Dmitry V. Levina1978322014-06-03 12:03:41 +0000563\fB\-E\ \fIvar\fR=\,\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000564Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000565.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000566in its list of environment variables.
567.TP
568.BI "\-E " var
569Remove
570.IR var
571from the inherited list of environment variables before passing it on to
572the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000573.SH DIAGNOSTICS
574When
575.I command
576exits,
577.B strace
578exits with the same exit status.
579If
580.I command
581is terminated by a signal,
582.B strace
583terminates itself with the same signal, so that
584.B strace
585can be used as a wrapper process transparent to the invoking parent process.
Denys Vlasenkob5370532013-06-26 15:35:16 +0200586Note that parent-child relationship (signal stop notifications,
587getppid() value, etc) between traced process and its parent are not preserved
588unless
589.B \-D
590is used.
Roland McGratha09353a2008-12-10 06:09:29 +0000591.LP
592When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000593.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000594the exit status of
595.B strace
596is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597.SH "SETUID INSTALLATION"
598If
599.B strace
600is installed setuid to root then the invoking user will be able to
601attach to and trace processes owned by any user.
602In addition setuid and setgid programs will be executed and traced
603with the correct effective privileges.
604Since only users trusted with full root privileges should be allowed
605to do these things,
606it only makes sense to install
607.B strace
608as setuid to root when the users who can execute it are restricted
609to those users who have this trust.
610For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000611.B strace
Denys Vlasenkob5370532013-06-26 15:35:16 +0200612with mode 'rwsr-xr--', user
Wichert Akkerman8829a551999-06-11 13:18:40 +0000613.B root
614and group
615.BR trace ,
616where members of the
617.B trace
618group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000620a non-setuid version of
621.B strace
622for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000624.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000625.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000626.BR ptrace (2),
627.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628.SH NOTES
629It is a pity that so much tracing clutter is produced by systems
630employing shared libraries.
631.LP
632It is instructive to think about system call inputs and outputs
633as data-flow across the user/kernel boundary. Because user-space
634and kernel-space are separate and address-protected, it is
635sometimes possible to make deductive inferences about process
636behavior using inputs and outputs as propositions.
637.LP
638In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000639or have a different name. For example, on System V-derived systems
640the true
641.BR time (2)
642system call does not take an argument and the
643.B stat
644function is called
645.B xstat
646and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647discrepancies are normal but idiosyncratic characteristics of the
648system call interface and are accounted for by C library wrapper
649functions.
650.LP
Denys Vlasenkob5370532013-06-26 15:35:16 +0200651On some platforms a process that is attached to with the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652.B \-p
Denys Vlasenkob5370532013-06-26 15:35:16 +0200653option may observe a spurious EINTR return from the current
Dmitry V. Levina1978322014-06-03 12:03:41 +0000654system call that is not restartable. (Ideally, all system calls
Denys Vlasenkob5370532013-06-26 15:35:16 +0200655should be restarted on strace attach, making the attach invisible
656to the traced process, but a few system calls aren't.
657Arguably, every instance of such behavior is a kernel bug.)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658This may have an unpredictable effect on the process
659if the process takes no action to restart the system call.
660.SH BUGS
661Programs that use the
662.I setuid
663bit do not have
664effective user
665.SM ID
666privileges while being traced.
667.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668A traced process runs slowly.
669.LP
670Traced processes which are descended from
671.I command
672may be left running after an interrupt signal (\c
673.SM CTRL\s0-C).
674.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675The
676.B \-i
677option is weakly supported.
678.SH HISTORY
Wichert Akkerman8829a551999-06-11 13:18:40 +0000679The original
680.B strace
681was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000683The SunOS version of
684.B strace
685was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000687Even though Paul released
688.B strace
6892.5 in 1992,
690Branko's work was based on Paul's
691.B strace
6921.5 release from 1991.
693In 1993, Rick Sladkey merged
694.B strace
6952.5 for SunOS and the second release of
696.B strace
697for Linux, added many of the features of
698.BR truss (1)
699from SVR4, and produced an
700.B strace
701that worked on both platforms. In 1994 Rick ported
702.B strace
703to SVR4 and Solaris and wrote the
704automatic configuration support. In 1995 he ported
705.B strace
706to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000707and tired of writing about himself in the third person.
708.SH PROBLEMS
709Problems with
710.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100711should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000713mailing list at <strace\-devel@lists.sourceforge.net>.