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