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