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