]> granicus.if.org Git - strace/blob - strace.1.in
strace.1: add indentation to examples
[strace] / strace.1.in
1 .\" 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 .\" Copyright (c) 1996-2017 The strace developers.
5 .\" All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. The name of the author may not be used to endorse or promote products
16 .\"    derived from this software without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .de CW
29 .sp
30 .in +4n
31 .nf
32 .ft CW
33 ..
34 .de CE
35 .ft R
36 .fi
37 .in
38 .sp
39 ..
40 .\" Like .OP, but with ellipsis at the end in order to signify that option
41 .\" can be provided multiple times. Based on .OP definition in groff's
42 .\" an-ext.tmac.
43 .de OM
44 .  ie \\n(.$-1 \
45 .    RI "[\fB\\$1\fP" "\ \\$2" "]...\&"
46 .  el \
47 .    RB "[" "\\$1" "]...\&"
48 ..
49 .\" Required option.
50 .de OR
51 .  ie \\n(.$-1 \
52 .    RI "\fB\\$1\fP" "\ \\$2"
53 .  el \
54 .    BR "\\$1"
55 ..
56 .TH STRACE 1 "@MANPAGE_DATE@" "strace @VERSION@"
57 .SH NAME
58 strace \- trace system calls and signals
59 .SH SYNOPSIS
60 .SY strace
61 .OP \-CdffhikqrtttTvVxxy
62 .OP \-I n
63 .OP \-b execve
64 .OM \-e expr
65 .OP \-a column
66 .OP \-o file
67 .OP \-s strsize
68 .OM \-P path
69 .OM \-p pid
70 .BR "" {
71 .OR \-p pid
72 .BR "" |
73 .OP \-D
74 .OM \-E var\fR[=\fIval\fR]
75 .OP \-u username
76 .IR command " [" args ]
77 .BR "" }
78 .YS
79 .SY strace
80 .B \-c
81 .OP \-df
82 .OP \-I n
83 .OP \-b execve
84 .OM \-e expr
85 .OP \-O overhead
86 .OP \-S sortby
87 .OM \-P path
88 .OM \-p pid
89 .BR "" {
90 .OR \-p pid
91 .BR "" |
92 .OP \-D
93 .OM \-E var\fR[=\fIval\fR]
94 .OP -u username
95 .IR command " [" args ]
96 .BR "" }
97 .YS
98
99 .SH DESCRIPTION
100 .IX "strace command" "" "\fLstrace\fR command"
101 .LP
102 In the simplest case
103 .B strace
104 runs the specified
105 .I command
106 until it exits.
107 It intercepts and records the system calls which are called
108 by a process and the signals which are received by a process.
109 The name of each system call, its arguments and its return value
110 are printed on standard error or to the file specified with the
111 .B \-o
112 option.
113 .LP
114 .B strace
115 is a useful diagnostic, instructional, and debugging tool.
116 System administrators, diagnosticians and trouble-shooters will find
117 it invaluable for solving problems with
118 programs for which the source is not readily available since
119 they do not need to be recompiled in order to trace them.
120 Students, hackers and the overly-curious will find that
121 a great deal can be learned about a system and its system calls by
122 tracing even ordinary programs.  And programmers will find that
123 since system calls and signals are events that happen at the user/kernel
124 interface, a close examination of this boundary is very
125 useful for bug isolation, sanity checking and
126 attempting to capture race conditions.
127 .LP
128 Each line in the trace contains the system call name, followed
129 by its arguments in parentheses and its return value.
130 An example from stracing the command "cat /dev/null" is:
131 .CW
132 open("/dev/null", O_RDONLY) = 3
133 .CE
134 Errors (typically a return value of \-1) have the errno symbol
135 and error string appended.
136 .CW
137 open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
138 .CE
139 Signals are printed as signal symbol and decoded siginfo structure.
140 An excerpt from stracing and interrupting the command "sleep 666" is:
141 .CW
142 sigsuspend([] <unfinished ...>
143 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
144 +++ killed by SIGINT +++
145 .CE
146 If a system call is being executed and meanwhile another one is being called
147 from a different thread/process then
148 .B strace
149 will try to preserve the order of those events and mark the ongoing call as
150 being
151 .IR unfinished .
152 When the call returns it will be marked as
153 .IR resumed .
154 .CW
155 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
156 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
157 [pid 28772] <... select resumed> )      = 1 (in [3])
158 .CE
159 Interruption of a (restartable) system call by a signal delivery is processed
160 differently as kernel terminates the system call and also arranges its
161 immediate reexecution after the signal handler completes.
162 .CW
163 read(0, 0x7ffff72cf5cf, 1)              = ? ERESTARTSYS (To be restarted)
164 --- SIGALRM ... ---
165 rt_sigreturn(0xe)                       = 0
166 read(0, "", 1)                          = 0
167 .CE
168 Arguments are printed in symbolic form with a passion.
169 This example shows the shell performing ">>xyzzy" output redirection:
170 .CW
171 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
172 .CE
173 Here the third argument of open is decoded by breaking down the
174 flag argument into its three bitwise-OR constituents and printing the
175 mode value in octal by tradition.  Where traditional or native
176 usage differs from ANSI or POSIX, the latter forms are preferred.
177 In some cases,
178 .B strace
179 output has proven to be more readable than the source.
180 .LP
181 Structure pointers are dereferenced and the members are displayed
182 as appropriate.  In all cases arguments are formatted in the most C-like
183 fashion possible.
184 For example, the essence of the command "ls \-l /dev/null" is captured as:
185 .CW
186 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
187 .CE
188 Notice how the 'struct stat' argument is dereferenced and how each member is
189 displayed symbolically.  In particular, observe how the st_mode member
190 is carefully decoded into a bitwise-OR of symbolic and numeric values.
191 Also notice in this example that the first argument to lstat is an input
192 to the system call and the second argument is an output.  Since output
193 arguments are not modified if the system call fails, arguments may not
194 always be dereferenced.  For example, retrying the "ls \-l" example
195 with a non-existent file produces the following line:
196 .CW
197 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
198 .CE
199 In this case the porch light is on but nobody is home.
200 .LP
201 Character pointers are dereferenced and printed as C strings.
202 Non-printing characters in strings are normally represented by
203 ordinary C escape codes.
204 Only the first
205 .I strsize
206 (32 by default) bytes of strings are printed;
207 longer strings have an ellipsis appended following the closing quote.
208 Here is a line from "ls \-l" where the
209 .B getpwuid
210 library routine is reading the password file:
211 .CW
212 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
213 .CE
214 While structures are annotated using curly braces, simple pointers
215 and arrays are printed using square brackets with commas separating
216 elements.  Here is an example from the command "id" on a system with
217 supplementary group ids:
218 .CW
219 getgroups(32, [100, 0]) = 2
220 .CE
221 On the other hand, bit-sets are also shown using square brackets
222 but set elements are separated only by a space.  Here is the shell
223 preparing to execute an external command:
224 .CW
225 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
226 .CE
227 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
228 In some cases the bit-set is so full that printing out the unset
229 elements is more valuable.  In that case, the bit-set is prefixed by
230 a tilde like this:
231 .CW
232 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
233 .CE
234 Here the second argument represents the full set of all signals.
235 .SH OPTIONS
236 .SS Output format
237 .TP 12
238 .BI "\-a " column
239 Align return values in a specific column (default column 40).
240 .TP
241 .B \-i
242 Print the instruction pointer at the time of the system call.
243 .TP
244 .B \-k
245 Print the execution stack trace of the traced processes after each system call (experimental).
246 This option is available only if
247 .B strace
248 is built with libunwind.
249 .TP
250 .BI "\-o " filename
251 Write the trace output to the file
252 .I filename
253 rather than to stderr.
254 Use
255 .I filename.pid
256 if
257 .B \-ff
258 is used.
259 If the argument begins with '|' or with '!' then the rest of the
260 argument is treated as a command and all output is piped to it.
261 This is convenient for piping the debugging output to a program
262 without affecting the redirections of executed programs.
263 .TP
264 .B \-q
265 Suppress messages about attaching, detaching etc.  This happens
266 automatically when output is redirected to a file and the command
267 is run directly instead of attaching.
268 .TP
269 .B \-qq
270 If given twice, suppress messages about process exit status.
271 .TP
272 .B \-r
273 Print a relative timestamp upon entry to each system call.  This
274 records the time difference between the beginning of successive
275 system calls.
276 .TP
277 .BI "\-s " strsize
278 Specify the maximum string size to print (the default is 32).  Note
279 that filenames are not considered strings and are always printed in
280 full.
281 .TP
282 .B \-t
283 Prefix each line of the trace with the time of day.
284 .TP
285 .B \-tt
286 If given twice, the time printed will include the microseconds.
287 .TP
288 .B \-ttt
289 If given thrice, the time printed will include the microseconds
290 and the leading portion will be printed as the number
291 of seconds since the epoch.
292 .TP
293 .B \-T
294 Show the time spent in system calls.  This records the time
295 difference between the beginning and the end of each system call.
296 .TP
297 .B \-x
298 Print all non-ASCII strings in hexadecimal string format.
299 .TP
300 .B \-xx
301 Print all strings in hexadecimal string format.
302 .TP
303 .B \-y
304 Print paths associated with file descriptor arguments.
305 .TP
306 .B \-yy
307 Print protocol specific information associated with socket file descriptors.
308 .SS Statistics
309 .TP 12
310 .B \-c
311 Count time, calls, and errors for each system call and report a summary on
312 program exit.  On Linux, this attempts to show system time (CPU time spent
313 running in the kernel) independent of wall clock time.  If
314 .B \-c
315 is used with
316 .B \-f
317 or
318 .B \-F
319 , only aggregate totals for all traced processes are kept.
320 .TP
321 .B \-C
322 Like
323 .B \-c
324 but also print regular output while processes are running.
325 .TP
326 .BI "\-O " overhead
327 Set the overhead for tracing system calls to
328 .I overhead
329 microseconds.
330 This is useful for overriding the default heuristic for guessing
331 how much time is spent in mere measuring when timing system calls using
332 the
333 .B \-c
334 option.  The accuracy of the heuristic can be gauged by timing a given
335 program run without tracing (using
336 .BR time (1))
337 and comparing the accumulated
338 system call time to the total produced using
339 .BR \-c .
340 .TP
341 .BI "\-S " sortby
342 Sort the output of the histogram printed by the
343 .B \-c
344 option by the specified criterion.  Legal values are
345 .BR time ,
346 .BR calls ,
347 .BR name ,
348 and
349 .B nothing
350 (default is
351 .BR time ).
352 .TP
353 .B \-w
354 Summarise the time difference between the beginning and end of
355 each system call.  The default is to summarise the system time.
356 .SS Filtering
357 .TP 12
358 .BI "\-e " expr
359 A qualifying expression which modifies which events to trace
360 or how to trace them.  The format of the expression is:
361 .RS 15
362 .IP
363 [\,\fIqualifier\/\fB=\fR][\fB!\fR][\fB?\fR]\,\fIvalue1\/\fR[\fB,\fR[\fB?\fR]\,\fIvalue2\/\fR]...
364 .RE
365 .IP
366 where
367 .I qualifier
368 is one of
369 .BR trace ,
370 .BR abbrev ,
371 .BR verbose ,
372 .BR raw ,
373 .BR signal ,
374 .BR read ,
375 .BR write ,
376 .BR fault ,
377 or
378 .B inject
379 and
380 .I value
381 is a qualifier-dependent symbol or number.  The default
382 qualifier is
383 .BR trace .
384 Using an exclamation mark negates the set of values.  For example,
385 .BR \-e "\ " open
386 means literally
387 .BR \-e "\ " trace = open
388 which in turn means trace only the
389 .B open
390 system call.  By contrast,
391 .BR \-e "\ " trace "=!" open
392 means to trace every system call except
393 .BR open .
394 Question mark before the syscall qualification allows suppression of error
395 in case no syscalls matched the qualification provided.
396 In addition, the special values
397 .B all
398 and
399 .B none
400 have the obvious meanings.
401 .IP
402 Note that some shells use the exclamation point for history
403 expansion even inside quoted arguments.  If so, you must escape
404 the exclamation point with a backslash.
405 .TP
406 \fB\-e\ trace\fR=\,\fIset\fR
407 Trace only the specified set of system calls.  The
408 .B \-c
409 option is useful for determining which system calls might be useful
410 to trace.  For example,
411 .BR trace = open,close,read,write
412 means to only
413 trace those four system calls.  Be careful when making inferences
414 about the user/kernel boundary if only a subset of system calls
415 are being monitored.  The default is
416 .BR trace = all .
417 .TP
418 \fB\-e\ trace\fR=/\,\fIregex\fR
419 Trace only those system calls that match the
420 .IR regex .
421 You can use
422 .B POSIX
423 Extended Regular Expression syntax (see
424 .BR regex (7)).
425 .PP
426 .BR "\-e\ trace" = %file
427 .TQ
428 .BR "\-e\ trace" = file " (deprecated)"
429 Trace all system calls which take a file name as an argument.  You
430 can think of this as an abbreviation for
431 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
432 which is useful to seeing what files the process is referencing.
433 Furthermore, using the abbreviation will ensure that you don't
434 accidentally forget to include a call like
435 .B lstat
436 in the list.  Betchya woulda forgot that one.
437 .PP
438 .BR "\-e\ trace" = %process
439 .TQ
440 .BR "\-e\ trace" = process " (deprecated)"
441 Trace all system calls which involve process management.  This
442 is useful for watching the fork, wait, and exec steps of a process.
443 .PP
444 .BR "\-e\ trace" = %network
445 .TQ
446 .BR "\-e\ trace" = network " (deprecated)"
447 Trace all the network related system calls.
448 .PP
449 .BR "\-e\ trace" = %signal
450 .TQ
451 .BR "\-e\ trace" = signal " (deprecated)"
452 Trace all signal related system calls.
453 .PP
454 .BR "\-e\ trace" = %ipc
455 .TQ
456 .BR "\-e\ trace" = ipc " (deprecated)"
457 Trace all IPC related system calls.
458 .PP
459 .BR "\-e\ trace" = %desc
460 .TQ
461 .BR "\-e\ trace" = desc " (deprecated)"
462 Trace all file descriptor related system calls.
463 .PP
464 .BR "\-e\ trace" = %memory
465 .TQ
466 .BR "\-e\ trace" = memory " (deprecated)"
467 Trace all memory mapping related system calls.
468 .TP
469 .BR "\-e\ trace" = %stat
470 Trace stat syscall variants.
471 .TP
472 .BR "\-e\ trace" = %lstat
473 Trace lstat syscall variants.
474 .TP
475 .BR "\-e\ trace" = %fstat
476 Trace fstat and fstatat syscall variants.
477 .TP
478 .BR "\-e\ trace" = %%stat
479 Trace syscalls used for requesting file status (stat, lstat, fstat, fstatat,
480 statx, and their variants).
481 .TP
482 .BR "\-e\ trace" = %statfs
483 Trace statfs, statfs64, statvfs, osf_statfs, and osf_statfs64 system calls.
484 The same effect can be achieved with
485 .BR "\-e\ trace" = /^(.*_)?statv?fs
486 regular expression.
487 .TP
488 .BR "\-e\ trace" = %fstatfs
489 Trace fstatfs, fstatfs64, fstatvfs, osf_fstatfs, and osf_fstatfs64 system calls.
490 The same effect can be achieved with
491 .BR "\-e\ trace" = /fstatv?fs
492 regular expression.
493 .TP
494 .BR "\-e\ trace" = %%statfs
495 Trace syscalls related to file system statistics (statfs-like, fstatfs-like,
496 and ustat).  The same effect can be achieved with
497 .BR "\-e\ trace" = /statv?fs|fsstat|ustat
498 regular expression.
499 .TP
500 \fB\-e\ abbrev\fR=\,\fIset\fR
501 Abbreviate the output from printing each member of large structures.
502 The default is
503 .BR abbrev = all .
504 The
505 .B \-v
506 option has the effect of
507 .BR abbrev = none .
508 .TP
509 \fB\-e\ verbose\fR=\,\fIset\fR
510 Dereference structures for the specified set of system calls.  The
511 default is
512 .BR verbose = all .
513 .TP
514 \fB\-e\ raw\fR=\,\fIset\fR
515 Print raw, undecoded arguments for the specified set of system calls.
516 This option has the effect of causing all arguments to be printed
517 in hexadecimal.  This is mostly useful if you don't trust the
518 decoding or you need to know the actual numeric value of an
519 argument.
520 .TP
521 \fB\-e\ signal\fR=\,\fIset\fR
522 Trace only the specified subset of signals.  The default is
523 .BR signal = all .
524 For example,
525 .B signal "=!" SIGIO
526 (or
527 .BR signal "=!" io )
528 causes SIGIO signals not to be traced.
529 .TP
530 \fB\-e\ read\fR=\,\fIset\fR
531 Perform a full hexadecimal and ASCII dump of all the data read from
532 file descriptors listed in the specified set.  For example, to see
533 all input activity on file descriptors
534 .I 3
535 and
536 .I 5
537 use
538 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
539 Note that this is independent from the normal tracing of the
540 .BR read (2)
541 system call which is controlled by the option
542 .BR -e "\ " trace = read .
543 .TP
544 \fB\-e\ write\fR=\,\fIset\fR
545 Perform a full hexadecimal and ASCII dump of all the data written to
546 file descriptors listed in the specified set.  For example, to see
547 all output activity on file descriptors
548 .I 3
549 and
550 .I 5
551 use
552 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
553 Note that this is independent from the normal tracing of the
554 .BR write (2)
555 system call which is controlled by the option
556 .BR -e "\ " trace = write .
557 .TP
558 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
559 Perform syscall tampering for the specified set of syscalls.
560
561 At least one of
562 .BR error ,
563 .BR retval ,
564 or
565 .B signal
566 options has to be specified.
567 .B error
568 and
569 .B retval
570 are mutually exclusive.
571
572 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
573 a fault is injected into a syscall invocation:
574 the syscall number is replaced by -1 which corresponds to an invalid syscall,
575 and the error code is specified using a symbolic
576 .I errno
577 value like
578 .B ENOSYS
579 or a numeric value within 1..4095 range.
580
581 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
582 success injection is performed: the syscall number is replaced by -1,
583 but a bogus success value is returned to the callee.
584
585 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
586 like
587 .B SIGSEGV
588 or a numeric value within 1..\fBSIGRTMAX\fR range,
589 that signal is delivered on entering every syscall specified by the
590 .IR set .
591
592 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
593 :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR options,
594 then only a signal
595 .I sig
596 is delivered without a syscall fault injection.
597 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
598 :\fBretval\fR=\,\fIvalue\/\fR option without
599 :\fBsignal\fR=\,\fIsig\/\fR option injects a fault without delivering a signal.
600
601 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
602 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
603 a fault or success is injected and a signal is delivered.
604
605 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
606 an injection is being made into every invocation of each syscall from the
607 .IR set .
608
609 The format of the subexpression is one of the following:
610 .RS
611 .IP "" 2
612 .I first
613 .RS 4
614 For every syscall from the
615 .IR set ,
616 perform an injection for the syscall invocation number
617 .I first
618 only.
619 .RE
620 .IP "" 2
621 \fIfirst\/\fB+\fR
622 .RS 4
623 For every syscall from the
624 .IR set ,
625 perform injections for the syscall invocation number
626 .I first
627 and all subsequent invocations.
628 .RE
629 .IP "" 2
630 \fIfirst\/\fB+\fIstep\fR
631 .RS 4
632 For every syscall from the
633 .IR set ,
634 perform injections for syscall invocations number
635 .IR first ,
636 .IR first + step ,
637 .IR first + step + step ,
638 and so on.
639 .RE
640 .RE
641 .IP
642 For example, to fail each third and subsequent chdir syscalls with
643 .BR ENOENT ,
644 use
645 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
646
647 The valid range for numbers
648 .I first
649 and
650 .I step
651 is 1..65535.
652
653 An injection expression can contain only one
654 .BR error =
655 or
656 .BR retval =
657 specification.
658 If an injection expression contains multiple
659 .BR when =
660 specifications, the last one takes precedence.
661
662 Accounting of syscalls that are subject to injection
663 is done per syscall and per tracee.
664
665 Specification of syscall injection can be combined
666 with other syscall filtering options, for example,
667 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
668
669 .TP
670 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
671 Perform syscall fault injection for the specified set of syscalls.
672
673 This is equivalent to more generic
674 \fB\-e\ inject\fR= expression with default value of
675 .I errno
676 option set to
677 .IR ENOSYS .
678
679 .TP
680 .BI "\-P " path
681 Trace only system calls accessing
682 .IR path .
683 Multiple
684 .B \-P
685 options can be used to specify several paths.
686 .TP
687 .B \-v
688 Print unabbreviated versions of environment, stat, termios, etc.
689 calls.  These structures are very common in calls and so the default
690 behavior displays a reasonable subset of structure members.  Use
691 this option to get all of the gory details.
692 .SS Tracing
693 .TP 12
694 .BI "\-b " syscall
695 If specified syscall is reached, detach from traced process.
696 Currently, only
697 .I execve
698 syscall is supported.  This option is useful if you want to trace
699 multi-threaded process and therefore require -f, but don't want
700 to trace its (potentially very complex) children.
701 .TP
702 .B \-D
703 Run tracer process as a detached grandchild, not as parent of the
704 tracee.  This reduces the visible effect of
705 .B strace
706 by keeping the tracee a direct child of the calling process.
707 .TP
708 .B \-f
709 Trace child processes as they are created by currently traced
710 processes as a result of the
711 .BR fork (2),
712 .BR vfork (2)
713 and
714 .BR clone (2)
715 system calls.  Note that
716 .B \-p
717 .I PID
718 .B \-f
719 will attach all threads of process PID if it is multi-threaded,
720 not only thread with thread_id = PID.
721 .TP
722 .B \-ff
723 If the
724 .B \-o
725 .I filename
726 option is in effect, each processes trace is written to
727 .I filename.pid
728 where pid is the numeric process id of each process.
729 This is incompatible with
730 .BR \-c ,
731 since no per-process counts are kept.
732 .TP
733 .BI "\-I " interruptible
734 When strace can be interrupted by signals (such as pressing ^C).
735 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
736 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
737 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
738 strace -o FILE PROG not stop on ^Z).
739 .SS Startup
740 .TP 12
741 \fB\-E\ \fIvar\fR=\,\fIval\fR
742 Run command with
743 .IR var = val
744 in its list of environment variables.
745 .TP
746 .BI "\-E " var
747 Remove
748 .IR var
749 from the inherited list of environment variables before passing it on to
750 the command.
751 .TP
752 .BI "\-p " pid
753 Attach to the process with the process
754 .SM ID
755 .I pid
756 and begin tracing.
757 The trace may be terminated
758 at any time by a keyboard interrupt signal (\c
759 .SM CTRL\s0-C).
760 .B strace
761 will respond by detaching itself from the traced process(es)
762 leaving it (them) to continue running.
763 Multiple
764 .B \-p
765 options can be used to attach to many processes in addition to
766 .I command
767 (which is optional if at least one
768 .B \-p
769 option is given).
770 .B \-p
771 "`pidof PROG`" syntax is supported.
772 .TP
773 .BI "\-u " username
774 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
775 supplementary groups of
776 .IR username .
777 This option is only useful when running as root and enables the
778 correct execution of setuid and/or setgid binaries.
779 Unless this option is used setuid and setgid programs are executed
780 without effective privileges.
781 .SS Miscellaneous
782 .TP 12
783 .B \-d
784 Show some debugging output of
785 .B strace
786 itself on the standard error.
787 .TP
788 .B \-F
789 This option is now obsolete and it has the same functionality as
790 .BR \-f .
791 .TP
792 .B \-h
793 Print the help summary.
794 .TP
795 .B \-V
796 Print the version number of
797 .BR strace .
798 .SH DIAGNOSTICS
799 When
800 .I command
801 exits,
802 .B strace
803 exits with the same exit status.
804 If
805 .I command
806 is terminated by a signal,
807 .B strace
808 terminates itself with the same signal, so that
809 .B strace
810 can be used as a wrapper process transparent to the invoking parent process.
811 Note that parent-child relationship (signal stop notifications,
812 getppid() value, etc) between traced process and its parent are not preserved
813 unless
814 .B \-D
815 is used.
816 .LP
817 When using
818 .B \-p
819 without a
820 .IR command ,
821 the exit status of
822 .B strace
823 is zero unless no processes has been attached or there was an unexpected error
824 in doing the tracing.
825 .SH "SETUID INSTALLATION"
826 If
827 .B strace
828 is installed setuid to root then the invoking user will be able to
829 attach to and trace processes owned by any user.
830 In addition setuid and setgid programs will be executed and traced
831 with the correct effective privileges.
832 Since only users trusted with full root privileges should be allowed
833 to do these things,
834 it only makes sense to install
835 .B strace
836 as setuid to root when the users who can execute it are restricted
837 to those users who have this trust.
838 For example, it makes sense to install a special version of
839 .B strace
840 with mode 'rwsr-xr--', user
841 .B root
842 and group
843 .BR trace ,
844 where members of the
845 .B trace
846 group are trusted users.
847 If you do use this feature, please remember to install
848 a non-setuid version of
849 .B strace
850 for ordinary lusers to use.
851 .SH NOTES
852 It is a pity that so much tracing clutter is produced by systems
853 employing shared libraries.
854 .LP
855 It is instructive to think about system call inputs and outputs
856 as data-flow across the user/kernel boundary.  Because user-space
857 and kernel-space are separate and address-protected, it is
858 sometimes possible to make deductive inferences about process
859 behavior using inputs and outputs as propositions.
860 .LP
861 In some cases, a system call will differ from the documented behavior
862 or have a different name.  For example, on System V-derived systems
863 the true
864 .BR time (2)
865 system call does not take an argument and the
866 .B stat
867 function is called
868 .B xstat
869 and takes an extra leading argument.  These
870 discrepancies are normal but idiosyncratic characteristics of the
871 system call interface and are accounted for by C library wrapper
872 functions.
873 .LP
874 Some system calls have different names in different architectures and
875 personalities.  In these cases, system call filtering and printing
876 uses the names that match corresponding
877 .BR __NR_ *
878 kernel macros of the tracee's architecture and personality.
879 There are two exceptions from this general rule:
880 .BR arm_fadvise64_64 (2)
881 ARM syscall and
882 .BR xtensa_fadvise64_64 (2)
883 Xtensa syscall are filtered and printed as
884 .BR fadvise64_64 (2).
885 .LP
886 On some platforms a process that is attached to with the
887 .B \-p
888 option may observe a spurious EINTR return from the current
889 system call that is not restartable.  (Ideally, all system calls
890 should be restarted on strace attach, making the attach invisible
891 to the traced process, but a few system calls aren't.
892 Arguably, every instance of such behavior is a kernel bug.)
893 This may have an unpredictable effect on the process
894 if the process takes no action to restart the system call.
895 .SH BUGS
896 Programs that use the
897 .I setuid
898 bit do not have
899 effective user
900 .SM ID
901 privileges while being traced.
902 .LP
903 A traced process runs slowly.
904 .LP
905 Traced processes which are descended from
906 .I command
907 may be left running after an interrupt signal (\c
908 .SM CTRL\s0-C).
909 .SH HISTORY
910 The original
911 .B strace
912 was written by Paul Kranenburg
913 for SunOS and was inspired by its trace utility.
914 The SunOS version of
915 .B strace
916 was ported to Linux and enhanced
917 by Branko Lankester, who also wrote the Linux kernel support.
918 Even though Paul released
919 .B strace
920 2.5 in 1992,
921 Branko's work was based on Paul's
922 .B strace
923 1.5 release from 1991.
924 In 1993, Rick Sladkey merged
925 .B strace
926 2.5 for SunOS and the second release of
927 .B strace
928 for Linux, added many of the features of
929 .BR truss (1)
930 from SVR4, and produced an
931 .B strace
932 that worked on both platforms.  In 1994 Rick ported
933 .B strace
934 to SVR4 and Solaris and wrote the
935 automatic configuration support.  In 1995 he ported
936 .B strace
937 to Irix
938 and tired of writing about himself in the third person.
939 .SH REPORTING BUGS
940 Problems with
941 .B strace
942 should be reported to the
943 .B strace
944 mailing list at <strace\-devel@lists.sourceforge.net>.
945 .SH "SEE ALSO"
946 .BR ltrace (1),
947 .BR time (1),
948 .BR ptrace (2),
949 .BR proc (5)