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