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