]> granicus.if.org Git - strace/blob - strace.1.in
strace.c: support simultaneous usage of -r and -t options
[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 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 the traditional or native
176 usage differs from ANSI or POSIX, the latter forms are preferred.
177 In some cases,
178 .B strace
179 output is proven to be more readable than the source.
180 .LP
181 Structure pointers are dereferenced and the members are displayed
182 as appropriate.  In most 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
190 .B st_mode
191 member is carefully decoded into a bitwise-OR of symbolic and numeric values.
192 Also notice in this example that the first argument to
193 .B lstat
194 is an input to the system call and the second argument is an output.
195 Since output arguments are not modified if the system call fails, arguments may
196 not always be dereferenced.  For example, retrying the "ls \-l" example
197 with a non-existent file produces the following line:
198 .CW
199 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
200 .CE
201 In this case the porch light is on but nobody is home.
202 .LP
203 Syscalls unknown to
204 .B strace
205 are printed raw, with the unknown system call number printed in hexadecimal form
206 and prefixed with "syscall_":
207 .CW
208 syscall_0xbad(0xfedcba9876543210, 0xfedcba9876543211, 0xfedcba9876543212,
209 0xfedcba9876543213, 0xfedcba9876543214, 0xfedcba9876543215) = -1 (errno 38)
210 .CE
211 .LP
212 Character pointers are dereferenced and printed as C strings.
213 Non-printing characters in strings are normally represented by
214 ordinary C escape codes.
215 Only the first
216 .I strsize
217 (32 by default) bytes of strings are printed;
218 longer strings have an ellipsis appended following the closing quote.
219 Here is a line from "ls \-l" where the
220 .B getpwuid
221 library routine is reading the password file:
222 .CW
223 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
224 .CE
225 While structures are annotated using curly braces, simple pointers
226 and arrays are printed using square brackets with commas separating
227 elements.  Here is an example from the command "id" on a system with
228 supplementary group ids:
229 .CW
230 getgroups(32, [100, 0]) = 2
231 .CE
232 On the other hand, bit-sets are also shown using square brackets
233 but set elements are separated only by a space.  Here is the shell,
234 preparing to execute an external command:
235 .CW
236 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
237 .CE
238 Here, the second argument is a bit-set of two signals,
239 .BR SIGCHLD " and " SIGTTOU .
240 In some cases, the bit-set is so full that printing out the unset
241 elements is more valuable.  In that case, the bit-set is prefixed by
242 a tilde like this:
243 .CW
244 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
245 .CE
246 Here, the second argument represents the full set of all signals.
247 .SH OPTIONS
248 .SS Output format
249 .TP 12
250 .BI "\-a " column
251 Align return values in a specific column (default column 40).
252 .TP
253 .B \-i
254 Print the instruction pointer at the time of the system call.
255 .TP
256 .B \-k
257 Print the execution stack trace of the traced processes after each system call (experimental).
258 This option is available only if
259 .B strace
260 is built with libunwind.
261 .TP
262 .BI "\-o " filename
263 Write the trace output to the file
264 .I filename
265 rather than to stderr.
266 .IR filename . pid
267 form is used if
268 .B \-ff
269 option is supplied.
270 If the argument begins with '|' or '!', the rest of the
271 argument is treated as a command and all output is piped to it.
272 This is convenient for piping the debugging output to a program
273 without affecting the redirections of executed programs.
274 The latter is not compatible with
275 .B \-ff
276 option currently.
277 .TP
278 .B \-q
279 Suppress messages about attaching, detaching etc.  This happens
280 automatically when output is redirected to a file and the command
281 is run directly instead of attaching.
282 .TP
283 .B \-qq
284 If given twice, suppress messages about process exit status.
285 .TP
286 .B \-r
287 Print a relative timestamp upon entry to each system call.  This
288 records the time difference between the beginning of successive
289 system calls.
290 Note that since
291 .B \-r
292 option uses the monotonic clock time for measuring time difference and not the
293 wall clock time, its measurements can differ from the difference in time
294 reported by the
295 .B \-t
296 option.
297 .TP
298 .BI "\-s " strsize
299 Specify the maximum string size to print (the default is 32).  Note
300 that filenames are not considered strings and are always printed in
301 full.
302 .TP
303 .B \-t
304 Prefix each line of the trace with the wall clock time.
305 .TP
306 .B \-tt
307 If given twice, the time printed will include the microseconds.
308 .TP
309 .B \-ttt
310 If given thrice, the time printed will include the microseconds
311 and the leading portion will be printed as the number
312 of seconds since the epoch.
313 .TP
314 .B \-T
315 Show the time spent in system calls.  This records the time
316 difference between the beginning and the end of each system call.
317 .TP
318 .B \-x
319 Print all non-ASCII strings in hexadecimal string format.
320 .TP
321 .B \-xx
322 Print all strings in hexadecimal string format.
323 .TP
324 .B \-y
325 Print paths associated with file descriptor arguments.
326 .TP
327 .B \-yy
328 Print protocol specific information associated with socket file descriptors,
329 and block/character device number associated with device file descriptors.
330 .SS Statistics
331 .TP 12
332 .B \-c
333 Count time, calls, and errors for each system call and report a summary on
334 program exit, suppressing the regular output.
335 This attempts to show system time (CPU time spent running
336 in the kernel) independent of wall clock time.  If
337 .B \-c
338 is used with
339 .BR \-f ,
340 only aggregate totals for all traced processes are kept.
341 .TP
342 .B \-C
343 Like
344 .B \-c
345 but also print regular output while processes are running.
346 .TP
347 .BI "\-O " overhead
348 Set the overhead for tracing system calls to
349 .I overhead
350 microseconds.
351 This is useful for overriding the default heuristic for guessing
352 how much time is spent in mere measuring when timing system calls using
353 the
354 .B \-c
355 option.  The accuracy of the heuristic can be gauged by timing a given
356 program run without tracing (using
357 .BR time (1))
358 and comparing the accumulated
359 system call time to the total produced using
360 .BR \-c .
361 .TP
362 .BI "\-S " sortby
363 Sort the output of the histogram printed by the
364 .B \-c
365 option by the specified criterion.  Legal values are
366 .BR time ,
367 .BR calls ,
368 .BR name ,
369 and
370 .B nothing
371 (default is
372 .BR time ).
373 .TP
374 .B \-w
375 Summarise the time difference between the beginning and end of
376 each system call.  The default is to summarise the system time.
377 .SS Filtering
378 .TP 12
379 .BI "\-e " expr
380 A qualifying expression which modifies which events to trace
381 or how to trace them.  The format of the expression is:
382 .RS 15
383 .IP
384 [\,\fIqualifier\/\fB=\fR][\fB!\fR][\fB?\fR]\,\fIvalue1\/\fR[\fB,\fR[\fB?\fR]\,\fIvalue2\/\fR]...
385 .RE
386 .IP
387 where
388 .I qualifier
389 is one of
390 .BR trace ,
391 .BR abbrev ,
392 .BR verbose ,
393 .BR raw ,
394 .BR signal ,
395 .BR read ,
396 .BR write ,
397 .BR fault ,
398 or
399 .B inject
400 and
401 .I value
402 is a qualifier-dependent symbol or number.  The default
403 qualifier is
404 .BR trace .
405 Using an exclamation mark negates the set of values.  For example,
406 .BR \-e "\ " open
407 means literally
408 .BR \-e "\ " trace = open
409 which in turn means trace only the
410 .B open
411 system call.  By contrast,
412 .BR \-e "\ " trace "=!" open
413 means to trace every system call except
414 .BR open .
415 Question mark before the syscall qualification allows suppression of error
416 in case no syscalls matched the qualification provided.
417 In addition, the special values
418 .B all
419 and
420 .B none
421 have the obvious meanings.
422 .IP
423 Note that some shells use the exclamation point for history
424 expansion even inside quoted arguments.  If so, you must escape
425 the exclamation point with a backslash.
426 .TP
427 \fB\-e\ trace\fR=\,\fIset\fR
428 Trace only the specified set of system calls.  The
429 .B \-c
430 option is useful for determining which system calls might be useful
431 to trace.  For example,
432 .BR trace = open,close,read,write
433 means to only
434 trace those four system calls.  Be careful when making inferences
435 about the user/kernel boundary if only a subset of system calls
436 are being monitored.  The default is
437 .BR trace = all .
438 .TP
439 \fB\-e\ trace\fR=/\,\fIregex\fR
440 Trace only those system calls that match the
441 .IR regex .
442 You can use
443 .B POSIX
444 Extended Regular Expression syntax (see
445 .BR regex (7)).
446 .TP
447 .BR "\-e\ trace" = %file
448 .TQ
449 .BR "\-e\ trace" = file " (deprecated)"
450 Trace all system calls which take a file name as an argument.  You
451 can think of this as an abbreviation for
452 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
453 which is useful to seeing what files the process is referencing.
454 Furthermore, using the abbreviation will ensure that you don't
455 accidentally forget to include a call like
456 .B lstat
457 in the list.  Betchya woulda forgot that one.
458 .TP
459 .BR "\-e\ trace" = %process
460 .TQ
461 .BR "\-e\ trace" = process " (deprecated)"
462 Trace all system calls which involve process management.  This
463 is useful for watching the fork, wait, and exec steps of a process.
464 .TP
465 .BR "\-e\ trace" = %network
466 .TQ
467 .BR "\-e\ trace" = network " (deprecated)"
468 Trace all the network related system calls.
469 .TP
470 .BR "\-e\ trace" = %signal
471 .TQ
472 .BR "\-e\ trace" = signal " (deprecated)"
473 Trace all signal related system calls.
474 .TP
475 .BR "\-e\ trace" = %ipc
476 .TQ
477 .BR "\-e\ trace" = ipc " (deprecated)"
478 Trace all IPC related system calls.
479 .TP
480 .BR "\-e\ trace" = %desc
481 .TQ
482 .BR "\-e\ trace" = desc " (deprecated)"
483 Trace all file descriptor related system calls.
484 .TP
485 .BR "\-e\ trace" = %memory
486 .TQ
487 .BR "\-e\ trace" = memory " (deprecated)"
488 Trace all memory mapping related system calls.
489 .TP
490 .BR "\-e\ trace" = %stat
491 Trace stat syscall variants.
492 .TP
493 .BR "\-e\ trace" = %lstat
494 Trace lstat syscall variants.
495 .TP
496 .BR "\-e\ trace" = %fstat
497 Trace fstat and fstatat syscall variants.
498 .TP
499 .BR "\-e\ trace" = %%stat
500 Trace syscalls used for requesting file status (stat, lstat, fstat, fstatat,
501 statx, and their variants).
502 .TP
503 .BR "\-e\ trace" = %statfs
504 Trace statfs, statfs64, statvfs, osf_statfs, and osf_statfs64 system calls.
505 The same effect can be achieved with
506 .BR "\-e\ trace" = /^(.*_)?statv?fs
507 regular expression.
508 .TP
509 .BR "\-e\ trace" = %fstatfs
510 Trace fstatfs, fstatfs64, fstatvfs, osf_fstatfs, and osf_fstatfs64 system calls.
511 The same effect can be achieved with
512 .BR "\-e\ trace" = /fstatv?fs
513 regular expression.
514 .TP
515 .BR "\-e\ trace" = %%statfs
516 Trace syscalls related to file system statistics (statfs-like, fstatfs-like,
517 and ustat).  The same effect can be achieved with
518 .BR "\-e\ trace" = /statv?fs|fsstat|ustat
519 regular expression.
520 .TP
521 .BR "\-e\ trace" = %pure
522 Trace syscalls that always succeed and have no arguments.
523 Currently, this list includes
524 .BR arc_gettls "(2), " getdtablesize "(2), " getegid "(2), " getegid32 "(2),"
525 .BR geteuid "(2), " geteuid32 "(2), " getgid "(2), " getgid32 "(2),"
526 .BR getpagesize "(2), " getpgrp "(2), " getpid "(2), " getppid "(2),"
527 .BR get_thread_area (2)
528 (on architectures other than x86),
529 .BR gettid "(2), " get_tls "(2), " getuid "(2), " getuid32 "(2),"
530 .BR getxgid "(2), " getxpid "(2), " getxuid "(2), " kern_features "(2), and"
531 .BR metag_get_tls "(2)"
532 syscalls.
533 .TP
534 \fB\-e\ abbrev\fR=\,\fIset\fR
535 Abbreviate the output from printing each member of large structures.
536 The default is
537 .BR abbrev = all .
538 The
539 .B \-v
540 option has the effect of
541 .BR abbrev = none .
542 .TP
543 \fB\-e\ verbose\fR=\,\fIset\fR
544 Dereference structures for the specified set of system calls.  The
545 default is
546 .BR verbose = all .
547 .TP
548 \fB\-e\ raw\fR=\,\fIset\fR
549 Print raw, undecoded arguments for the specified set of system calls.
550 This option has the effect of causing all arguments to be printed
551 in hexadecimal.  This is mostly useful if you don't trust the
552 decoding or you need to know the actual numeric value of an
553 argument.
554 .TP
555 \fB\-e\ signal\fR=\,\fIset\fR
556 Trace only the specified subset of signals.  The default is
557 .BR signal = all .
558 For example,
559 .BR signal "=!" SIGIO
560 (or
561 .BR signal "=!" io )
562 causes
563 .B SIGIO
564 signals not to be traced.
565 .TP
566 \fB\-e\ read\fR=\,\fIset\fR
567 Perform a full hexadecimal and ASCII dump of all the data read from
568 file descriptors listed in the specified set.  For example, to see
569 all input activity on file descriptors
570 .I 3
571 and
572 .I 5
573 use
574 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
575 Note that this is independent from the normal tracing of the
576 .BR read (2)
577 system call which is controlled by the option
578 .BR -e "\ " trace = read .
579 .TP
580 \fB\-e\ write\fR=\,\fIset\fR
581 Perform a full hexadecimal and ASCII dump of all the data written to
582 file descriptors listed in the specified set.  For example, to see
583 all output activity on file descriptors
584 .I 3
585 and
586 .I 5
587 use
588 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
589 Note that this is independent from the normal tracing of the
590 .BR write (2)
591 system call which is controlled by the option
592 .BR -e "\ " trace = write .
593 .TP
594 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBdelay_enter\fR=\,\fIusecs\/\fR][:\fBdelay_exit\fR=\,\fIusecs\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
595 Perform syscall tampering for the specified set of syscalls.
596
597 At least one of
598 .BR error ,
599 .BR retval ,
600 .BR signal ,
601 .BR delay_enter ,
602 or
603 .B delay_exit
604 options has to be specified.
605 .B error
606 and
607 .B retval
608 are mutually exclusive.
609
610 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
611 a fault is injected into a syscall invocation:
612 the syscall number is replaced by -1 which corresponds to an invalid syscall,
613 and the error code is specified using a symbolic
614 .I errno
615 value like
616 .B ENOSYS
617 or a numeric value within 1..4095 range.
618
619 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
620 success injection is performed: the syscall number is replaced by -1,
621 but a bogus success value is returned to the callee.
622
623 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
624 like
625 .B SIGSEGV
626 or a numeric value within 1..\fBSIGRTMAX\fR range,
627 that signal is delivered on entering every syscall specified by the
628 .IR set .
629
630 If :\fBdelay_enter\fR=\,\fIusecs\/\fR or :\fBdelay_exit\fR=\,\fIusecs\/\fR
631 options are specified, delay injection is performed: the tracee is delayed
632 by at least
633 .IR usecs
634 microseconds on entering or exiting the syscall.
635
636 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
637 :\fBerror\fR=\,\fIerrno\/\fR, :\fBretval\fR=\,\fIvalue\/\fR or
638 :\fBdelay_{enter,exit}\fR=\,\fIusecs\/\fR options,
639 then only a signal
640 .I sig
641 is delivered without a syscall fault or delay injection.
642 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
643 :\fBretval\fR=\,\fIvalue\/\fR option without
644 :\fBdelay_enter\fR=\,\fIusecs\/\fR,
645 :\fBdelay_exit\fR=\,\fIusecs\/\fR or
646 :\fBsignal\fR=\,\fIsig\/\fR options injects a fault without delivering a signal
647 or injecting a delay, etc.
648
649 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
650 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
651 a fault or success is injected and a signal is delivered.
652
653 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
654 an injection is being made into every invocation of each syscall from the
655 .IR set .
656
657 The format of the subexpression is one of the following:
658 .RS
659 .IP "" 2
660 .I first
661 .RS 4
662 For every syscall from the
663 .IR set ,
664 perform an injection for the syscall invocation number
665 .I first
666 only.
667 .RE
668 .IP "" 2
669 \fIfirst\/\fB+\fR
670 .RS 4
671 For every syscall from the
672 .IR set ,
673 perform injections for the syscall invocation number
674 .I first
675 and all subsequent invocations.
676 .RE
677 .IP "" 2
678 \fIfirst\/\fB+\fIstep\fR
679 .RS 4
680 For every syscall from the
681 .IR set ,
682 perform injections for syscall invocations number
683 .IR first ,
684 .IR first + step ,
685 .IR first + step + step ,
686 and so on.
687 .RE
688 .RE
689 .IP
690 For example, to fail each third and subsequent chdir syscalls with
691 .BR ENOENT ,
692 use
693 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
694
695 The valid range for numbers
696 .I first
697 and
698 .I step
699 is 1..65535.
700
701 An injection expression can contain only one
702 .BR error =
703 or
704 .BR retval =
705 specification, and only one
706 .BR signal =
707 specification.  If an injection expression contains multiple
708 .BR when =
709 specifications, the last one takes precedence.
710
711 Accounting of syscalls that are subject to injection
712 is done per syscall and per tracee.
713
714 Specification of syscall injection can be combined
715 with other syscall filtering options, for example,
716 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
717
718 .TP
719 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
720 Perform syscall fault injection for the specified set of syscalls.
721
722 This is equivalent to more generic
723 \fB\-e\ inject\fR= expression with default value of
724 .I errno
725 option set to
726 .IR ENOSYS .
727
728 .TP
729 .BI "\-P " path
730 Trace only system calls accessing
731 .IR path .
732 Multiple
733 .B \-P
734 options can be used to specify several paths.
735 .TP
736 .B \-v
737 Print unabbreviated versions of environment, stat, termios, etc.
738 calls.  These structures are very common in calls and so the default
739 behavior displays a reasonable subset of structure members.  Use
740 this option to get all of the gory details.
741 .SS Tracing
742 .TP 12
743 .BI "\-b " syscall
744 If specified syscall is reached, detach from traced process.
745 Currently, only
746 .I execve
747 syscall is supported.  This option is useful if you want to trace
748 multi-threaded process and therefore require -f, but don't want
749 to trace its (potentially very complex) children.
750 .TP
751 .B \-D
752 Run tracer process as a detached grandchild, not as parent of the
753 tracee.  This reduces the visible effect of
754 .B strace
755 by keeping the tracee a direct child of the calling process.
756 .TP
757 .B \-f
758 Trace child processes as they are created by currently traced
759 processes as a result of the
760 .BR fork (2),
761 .BR vfork (2)
762 and
763 .BR clone (2)
764 system calls.  Note that
765 .B \-p
766 .I PID
767 .B \-f
768 will attach all threads of process PID if it is multi-threaded,
769 not only thread with thread_id = PID.
770 .TP
771 .B \-ff
772 If the
773 .B \-o
774 .I filename
775 option is in effect, each processes trace is written to
776 .I filename.pid
777 where pid is the numeric process id of each process.
778 This is incompatible with
779 .BR \-c ,
780 since no per-process counts are kept.
781
782 One might want to consider using
783 .BR strace-log-merge (1)
784 to obtain a combined strace log view.
785 .TP
786 .BI "\-I " interruptible
787 When strace can be interrupted by signals (such as pressing ^C).
788 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
789 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
790 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
791 strace -o FILE PROG not stop on ^Z).
792 .SS Startup
793 .TP 12
794 \fB\-E\ \fIvar\fR=\,\fIval\fR
795 Run command with
796 .IR var = val
797 in its list of environment variables.
798 .TP
799 .BI "\-E " var
800 Remove
801 .IR var
802 from the inherited list of environment variables before passing it on to
803 the command.
804 .TP
805 .BI "\-p " pid
806 Attach to the process with the process
807 .SM ID
808 .I pid
809 and begin tracing.
810 The trace may be terminated
811 at any time by a keyboard interrupt signal (\c
812 .SM CTRL\s0-C).
813 .B strace
814 will respond by detaching itself from the traced process(es)
815 leaving it (them) to continue running.
816 Multiple
817 .B \-p
818 options can be used to attach to many processes in addition to
819 .I command
820 (which is optional if at least one
821 .B \-p
822 option is given).
823 .B \-p
824 "`pidof PROG`" syntax is supported.
825 .TP
826 .BI "\-u " username
827 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
828 supplementary groups of
829 .IR username .
830 This option is only useful when running as root and enables the
831 correct execution of setuid and/or setgid binaries.
832 Unless this option is used setuid and setgid programs are executed
833 without effective privileges.
834 .SS Miscellaneous
835 .TP 12
836 .B \-d
837 Show some debugging output of
838 .B strace
839 itself on the standard error.
840 .TP
841 .B \-F
842 This option is deprecated.  It is retained for backward compatibility only
843 and may be removed in future releases.
844 Usage of multiple instances of
845 .B \-F
846 option is still equivalent to a single
847 .BR \-f ,
848 and it is ignored at all if used along with one or more instances of
849 .B \-f
850 option.
851 .TP
852 .B \-h
853 Print the help summary.
854 .TP
855 .B \-V
856 Print the version number of
857 .BR strace .
858 .SH DIAGNOSTICS
859 When
860 .I command
861 exits,
862 .B strace
863 exits with the same exit status.
864 If
865 .I command
866 is terminated by a signal,
867 .B strace
868 terminates itself with the same signal, so that
869 .B strace
870 can be used as a wrapper process transparent to the invoking parent process.
871 Note that parent-child relationship (signal stop notifications,
872 getppid() value, etc) between traced process and its parent are not preserved
873 unless
874 .B \-D
875 is used.
876 .LP
877 When using
878 .B \-p
879 without a
880 .IR command ,
881 the exit status of
882 .B strace
883 is zero unless no processes has been attached or there was an unexpected error
884 in doing the tracing.
885 .SH "SETUID INSTALLATION"
886 If
887 .B strace
888 is installed setuid to root then the invoking user will be able to
889 attach to and trace processes owned by any user.
890 In addition setuid and setgid programs will be executed and traced
891 with the correct effective privileges.
892 Since only users trusted with full root privileges should be allowed
893 to do these things,
894 it only makes sense to install
895 .B strace
896 as setuid to root when the users who can execute it are restricted
897 to those users who have this trust.
898 For example, it makes sense to install a special version of
899 .B strace
900 with mode 'rwsr-xr--', user
901 .B root
902 and group
903 .BR trace ,
904 where members of the
905 .B trace
906 group are trusted users.
907 If you do use this feature, please remember to install
908 a regular non-setuid version of
909 .B strace
910 for ordinary users to use.
911 .SH "MULTIPLE PERSONALITY SUPPORT"
912 On some architectures,
913 .B strace
914 supports decoding of syscalls for processes that use different ABI rather than
915 the one
916 .B strace
917 uses.
918 Specifically, in addition to decoding native ABI,
919 .B strace
920 can decode the following ABIs on the following architectures:
921 .TS H
922 allbox;
923 lb lb
924 l l.
925 Architecture    ABIs supported
926 x86_64  i386, x32 (when built as an x86_64 application); i386 (when built as an x32 application)
927 AArch64 ARM 32-bit EABI
928 PowerPC 64-bit  PowerPC 32-bit
929 RISC-V 64-bit   RISC-V 32-bit
930 s390x   s390
931 SPARC 64-bit    SPARC 32-bit
932 TILE 64-bit     TILE 32-bit
933 .TE
934 .PP
935 This support is optional and relies on ability to generate and parse structure
936 definitions during the build time.
937 Please refer to the output of the
938 .B strace \-V
939 command in order to figure out what support is available in your strace build
940 ("non-native" refers to an ABI that differs from the ABI strace has):
941 .TP 15
942 .B m32-mpers
943 .B strace
944 can trace and properly decode non-native 32-bit binaries.
945 .TP
946 .B no-m32-mpers
947 .B strace
948 can trace, but cannot properly decode non-native 32-bit binaries.
949 .TP
950 .B mx32-mpers
951 .B strace
952 can trace and properly decode non-native 32-on-64-bit binaries.
953 .TP
954 .B no-mx32-mpers
955 .B strace
956 can trace, but cannot properly decode non-native 32-on-64-bit binaries.
957 .PP
958 If the output contains neither
959 .B m32-mpers
960 nor
961 .BR no-m32-mpers ,
962 then decoding of non-native 32-bit binaries is not implemented at all
963 or not applicable.
964 .PP
965 Likewise, if the output contains neither
966 .B mx32-mpers
967 nor
968 .BR no-mx32-mpers ,
969 then decoding of non-native 32-on-64-bit binaries is not implemented at all
970 or not applicable.
971 .SH NOTES
972 It is a pity that so much tracing clutter is produced by systems
973 employing shared libraries.
974 .LP
975 It is instructive to think about system call inputs and outputs
976 as data-flow across the user/kernel boundary.  Because user-space
977 and kernel-space are separate and address-protected, it is
978 sometimes possible to make deductive inferences about process
979 behavior using inputs and outputs as propositions.
980 .LP
981 In some cases, a system call will differ from the documented behavior
982 or have a different name.  For example, the
983 .BR faccessat (2)
984 system call does not have
985 .I flags
986 argument, and the
987 .BR setrlimit (2)
988 library function uses
989 .BR prlimit64 (2)
990 system call on modern (2.6.38+) kernels.  These
991 discrepancies are normal but idiosyncratic characteristics of the
992 system call interface and are accounted for by C library wrapper
993 functions.
994 .LP
995 Some system calls have different names in different architectures and
996 personalities.  In these cases, system call filtering and printing
997 uses the names that match corresponding
998 .BR __NR_ *
999 kernel macros of the tracee's architecture and personality.
1000 There are two exceptions from this general rule:
1001 .BR arm_fadvise64_64 (2)
1002 ARM syscall and
1003 .BR xtensa_fadvise64_64 (2)
1004 Xtensa syscall are filtered and printed as
1005 .BR fadvise64_64 (2).
1006 .LP
1007 On some platforms a process that is attached to with the
1008 .B \-p
1009 option may observe a spurious EINTR return from the current
1010 system call that is not restartable.  (Ideally, all system calls
1011 should be restarted on strace attach, making the attach invisible
1012 to the traced process, but a few system calls aren't.
1013 Arguably, every instance of such behavior is a kernel bug.)
1014 This may have an unpredictable effect on the process
1015 if the process takes no action to restart the system call.
1016 .LP
1017 As
1018 .B strace
1019 executes the specified
1020 .I command
1021 directly and does not employ a shell for that, scripts without shebang
1022 that usually run just fine when invoked by shell fail to execute with
1023 .B ENOEXEC
1024 error.
1025 It is advisable to manually supply a shell as a
1026 .I command
1027 with the script as its argument.
1028 .SH BUGS
1029 Programs that use the
1030 .I setuid
1031 bit do not have
1032 effective user
1033 .SM ID
1034 privileges while being traced.
1035 .LP
1036 A traced process runs slowly.
1037 .LP
1038 Traced processes which are descended from
1039 .I command
1040 may be left running after an interrupt signal (\c
1041 .SM CTRL\s0-C).
1042 .SH HISTORY
1043 The original
1044 .B strace
1045 was written by Paul Kranenburg
1046 for SunOS and was inspired by its
1047 .B trace
1048 utility.
1049 The SunOS version of
1050 .B strace
1051 was ported to Linux and enhanced
1052 by Branko Lankester, who also wrote the Linux kernel support.
1053 Even though Paul released
1054 .B strace
1055 2.5 in 1992,
1056 Branko's work was based on Paul's
1057 .B strace
1058 1.5 release from 1991.
1059 In 1993, Rick Sladkey merged
1060 .B strace
1061 2.5 for SunOS and the second release of
1062 .B strace
1063 for Linux, added many of the features of
1064 .BR truss (1)
1065 from SVR4, and produced an
1066 .B strace
1067 that worked on both platforms.  In 1994 Rick ported
1068 .B strace
1069 to SVR4 and Solaris and wrote the
1070 automatic configuration support.  In 1995 he ported
1071 .B strace
1072 to Irix
1073 and tired of writing about himself in the third person.
1074 .PP
1075 Beginning with 1996,
1076 .B strace
1077 was maintained by Wichert Akkerman.
1078 During his tenure,
1079 .B strace
1080 development migrated to CVS; ports to FreeBSD and many architectures on Linux
1081 (including ARM, IA-64, MIPS, PA-RISC, PowerPC, s390, SPARC) were introduced.
1082 In 2002, the burden of
1083 .B strace
1084 maintainership was transferred to Ronald McGrath.
1085 Since then,
1086 .B strace
1087 gained support for several new Linux architectures (AMD64, s390x, SuperH),
1088 bi-architecture support for some of them, and received numerous additions and
1089 improvements in syscalls decoders on Linux;
1090 .B strace
1091 development migrated to
1092 .B git
1093 during that period.
1094 Since 2009,
1095 .B strace
1096 is actively maintained by Dmitry Levin.
1097 .B strace
1098 gained support for AArch64, ARC, AVR32, Blackfin, Meta, Nios II, OpenSISC 1000,
1099 RISC-V, Tile/TileGx, Xtensa architectures since that time.
1100 In 2012, unmaintained and apparently broken support for non-Linux operating
1101 systems was removed.
1102 Also, in 2012
1103 .B strace
1104 gained support for path tracing and file descriptor path decoding.
1105 In 2014, support for stack traces printing was added.
1106 In 2016, syscall fault injection was implemented.
1107 .PP
1108 For the additional information, please refer to the
1109 .B NEWS
1110 file and
1111 .B strace
1112 repository commit log.
1113 .SH REPORTING BUGS
1114 Problems with
1115 .B strace
1116 should be reported to the
1117 .B strace
1118 mailing list at <strace\-devel@lists.strace.io>.
1119 .SH "SEE ALSO"
1120 .BR strace-log-merge (1),
1121 .BR ltrace (1),
1122 .BR perf-trace (1),
1123 .BR trace-cmd (1),
1124 .BR time (1),
1125 .BR ptrace (2),
1126 .BR proc (5)