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