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