]> granicus.if.org Git - strace/blob - strace.1.in
Provide fallback definitions for SECCOMP_RET_* constants
[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 .TP
734 .BI "\-I " interruptible
735 When strace can be interrupted by signals (such as pressing ^C).
736 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
737 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
738 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
739 strace -o FILE PROG not stop on ^Z).
740 .SS Startup
741 .TP 12
742 \fB\-E\ \fIvar\fR=\,\fIval\fR
743 Run command with
744 .IR var = val
745 in its list of environment variables.
746 .TP
747 .BI "\-E " var
748 Remove
749 .IR var
750 from the inherited list of environment variables before passing it on to
751 the command.
752 .TP
753 .BI "\-p " pid
754 Attach to the process with the process
755 .SM ID
756 .I pid
757 and begin tracing.
758 The trace may be terminated
759 at any time by a keyboard interrupt signal (\c
760 .SM CTRL\s0-C).
761 .B strace
762 will respond by detaching itself from the traced process(es)
763 leaving it (them) to continue running.
764 Multiple
765 .B \-p
766 options can be used to attach to many processes in addition to
767 .I command
768 (which is optional if at least one
769 .B \-p
770 option is given).
771 .B \-p
772 "`pidof PROG`" syntax is supported.
773 .TP
774 .BI "\-u " username
775 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
776 supplementary groups of
777 .IR username .
778 This option is only useful when running as root and enables the
779 correct execution of setuid and/or setgid binaries.
780 Unless this option is used setuid and setgid programs are executed
781 without effective privileges.
782 .SS Miscellaneous
783 .TP 12
784 .B \-d
785 Show some debugging output of
786 .B strace
787 itself on the standard error.
788 .TP
789 .B \-F
790 This option is now obsolete and it has the same functionality as
791 .BR \-f .
792 .TP
793 .B \-h
794 Print the help summary.
795 .TP
796 .B \-V
797 Print the version number of
798 .BR strace .
799 .SH DIAGNOSTICS
800 When
801 .I command
802 exits,
803 .B strace
804 exits with the same exit status.
805 If
806 .I command
807 is terminated by a signal,
808 .B strace
809 terminates itself with the same signal, so that
810 .B strace
811 can be used as a wrapper process transparent to the invoking parent process.
812 Note that parent-child relationship (signal stop notifications,
813 getppid() value, etc) between traced process and its parent are not preserved
814 unless
815 .B \-D
816 is used.
817 .LP
818 When using
819 .B \-p
820 without a
821 .IR command ,
822 the exit status of
823 .B strace
824 is zero unless no processes has been attached or there was an unexpected error
825 in doing the tracing.
826 .SH "SETUID INSTALLATION"
827 If
828 .B strace
829 is installed setuid to root then the invoking user will be able to
830 attach to and trace processes owned by any user.
831 In addition setuid and setgid programs will be executed and traced
832 with the correct effective privileges.
833 Since only users trusted with full root privileges should be allowed
834 to do these things,
835 it only makes sense to install
836 .B strace
837 as setuid to root when the users who can execute it are restricted
838 to those users who have this trust.
839 For example, it makes sense to install a special version of
840 .B strace
841 with mode 'rwsr-xr--', user
842 .B root
843 and group
844 .BR trace ,
845 where members of the
846 .B trace
847 group are trusted users.
848 If you do use this feature, please remember to install
849 a non-setuid version of
850 .B strace
851 for ordinary lusers to use.
852 .SH NOTES
853 It is a pity that so much tracing clutter is produced by systems
854 employing shared libraries.
855 .LP
856 It is instructive to think about system call inputs and outputs
857 as data-flow across the user/kernel boundary.  Because user-space
858 and kernel-space are separate and address-protected, it is
859 sometimes possible to make deductive inferences about process
860 behavior using inputs and outputs as propositions.
861 .LP
862 In some cases, a system call will differ from the documented behavior
863 or have a different name.  For example, the
864 .BR faccessat (2)
865 system call does not have
866 .I flags
867 argument, and the
868 .BR setrlimit (2)
869 library function uses
870 .BR prlimit (2)
871 system call on modern (2.6.38+) kernels.  These
872 discrepancies are normal but idiosyncratic characteristics of the
873 system call interface and are accounted for by C library wrapper
874 functions.
875 .LP
876 Some system calls have different names in different architectures and
877 personalities.  In these cases, system call filtering and printing
878 uses the names that match corresponding
879 .BR __NR_ *
880 kernel macros of the tracee's architecture and personality.
881 There are two exceptions from this general rule:
882 .BR arm_fadvise64_64 (2)
883 ARM syscall and
884 .BR xtensa_fadvise64_64 (2)
885 Xtensa syscall are filtered and printed as
886 .BR fadvise64_64 (2).
887 .LP
888 On some platforms a process that is attached to with the
889 .B \-p
890 option may observe a spurious EINTR return from the current
891 system call that is not restartable.  (Ideally, all system calls
892 should be restarted on strace attach, making the attach invisible
893 to the traced process, but a few system calls aren't.
894 Arguably, every instance of such behavior is a kernel bug.)
895 This may have an unpredictable effect on the process
896 if the process takes no action to restart the system call.
897 .SH BUGS
898 Programs that use the
899 .I setuid
900 bit do not have
901 effective user
902 .SM ID
903 privileges while being traced.
904 .LP
905 A traced process runs slowly.
906 .LP
907 Traced processes which are descended from
908 .I command
909 may be left running after an interrupt signal (\c
910 .SM CTRL\s0-C).
911 .SH HISTORY
912 The original
913 .B strace
914 was written by Paul Kranenburg
915 for SunOS and was inspired by its trace utility.
916 The SunOS version of
917 .B strace
918 was ported to Linux and enhanced
919 by Branko Lankester, who also wrote the Linux kernel support.
920 Even though Paul released
921 .B strace
922 2.5 in 1992,
923 Branko's work was based on Paul's
924 .B strace
925 1.5 release from 1991.
926 In 1993, Rick Sladkey merged
927 .B strace
928 2.5 for SunOS and the second release of
929 .B strace
930 for Linux, added many of the features of
931 .BR truss (1)
932 from SVR4, and produced an
933 .B strace
934 that worked on both platforms.  In 1994 Rick ported
935 .B strace
936 to SVR4 and Solaris and wrote the
937 automatic configuration support.  In 1995 he ported
938 .B strace
939 to Irix
940 and tired of writing about himself in the third person.
941 .SH REPORTING BUGS
942 Problems with
943 .B strace
944 should be reported to the
945 .B strace
946 mailing list at <strace\-devel@lists.sourceforge.net>.
947 .SH "SEE ALSO"
948 .BR ltrace (1),
949 .BR time (1),
950 .BR ptrace (2),
951 .BR proc (5)