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