]> granicus.if.org Git - strace/blob - strace.1
Remove hacks for old kernels for architectures which require new kernels
[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 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\"    derived from this software without specific prior written permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .de CW
28 .sp
29 .nf
30 .ft CW
31 ..
32 .de CE
33 .ft R
34 .fi
35 .sp
36 ..
37 .TH STRACE 1 "2010-03-30"
38 .SH NAME
39 strace \- trace system calls and signals
40 .SH SYNOPSIS
41 .B strace
42 [\fB-CdffhiqrtttTvVxxy\fR]
43 [\fB-I\fIn\fR]
44 [\fB-e\fIexpr\fR]... [\fB-a\fIcolumn\fR]
45 [\fB-o\fIfile\fR]
46 [\fB-s\fIstrsize\fR]
47 [\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
48 [\fB-D\fR]
49 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
50 \fIcommand\fR [\fIargs\fR]
51 .sp
52 .B strace
53 \fB-c\fR[\fBdf\fR]
54 [\fB-I\fIn\fR]
55 [\fB-e\fIexpr\fR]... [\fB-O\fIoverhead\fR]
56 [\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
57 [\fB-D\fR]
58 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
59 \fIcommand\fR [\fIargs\fR]
60 .SH DESCRIPTION
61 .IX "strace command" "" "\fLstrace\fR command"
62 .LP
63 In the simplest case
64 .B strace
65 runs the specified
66 .I command
67 until it exits.
68 It intercepts and records the system calls which are called
69 by a process and the signals which are received by a process.
70 The name of each system call, its arguments and its return value
71 are printed on standard error or to the file specified with the
72 .B \-o
73 option.
74 .LP
75 .B strace
76 is a useful diagnostic, instructional, and debugging tool.
77 System administrators, diagnosticians and trouble-shooters will find
78 it invaluable for solving problems with
79 programs for which the source is not readily available since
80 they do not need to be recompiled in order to trace them.
81 Students, hackers and the overly-curious will find that
82 a great deal can be learned about a system and its system calls by
83 tracing even ordinary programs.  And programmers will find that
84 since system calls and signals are events that happen at the user/kernel
85 interface, a close examination of this boundary is very
86 useful for bug isolation, sanity checking and
87 attempting to capture race conditions.
88 .LP
89 Each line in the trace contains the system call name, followed
90 by its arguments in parentheses and its return value.
91 An example from stracing the command ``cat /dev/null'' is:
92 .CW
93 open("/dev/null", O_RDONLY) = 3
94 .CE
95 Errors (typically a return value of \-1) have the errno symbol
96 and error string appended.
97 .CW
98 open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
99 .CE
100 Signals are printed as a signal symbol and a signal string.
101 An excerpt from stracing and interrupting the command ``sleep 666'' is:
102 .CW
103 sigsuspend([] <unfinished ...>
104 --- SIGINT (Interrupt) ---
105 +++ killed by SIGINT +++
106 .CE
107 If a system call is being executed and meanwhile another one is being called
108 from a different thread/process then
109 .B strace
110 will try to preserve the order of those events and mark the ongoing call as
111 being
112 .IR unfinished .
113 When the call returns it will be marked as
114 .IR resumed .
115 .CW
116 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
117 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
118 [pid 28772] <... select resumed> )      = 1 (in [3])
119 .CE
120 Interruption of a (restartable) system call by a signal delivery is processed
121 differently as kernel terminates the system call and also arranges its
122 immediate reexecution after the signal handler completes.
123 .CW
124 read(0, 0x7ffff72cf5cf, 1)              = ? ERESTARTSYS (To be restarted)
125 --- SIGALRM (Alarm clock) @ 0 (0) ---
126 rt_sigreturn(0xe)                       = 0
127 read(0, ""..., 1)                       = 0
128 .CE
129 Arguments are printed in symbolic form with a passion.
130 This example shows the shell performing ``>>xyzzy'' output redirection:
131 .CW
132 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
133 .CE
134 Here the third argument of open is decoded by breaking down the
135 flag argument into its three bitwise-OR constituents and printing the
136 mode value in octal by tradition.  Where traditional or native
137 usage differs from ANSI or POSIX, the latter forms are preferred.
138 In some cases,
139 .B strace
140 output has proven to be more readable than the source.
141 .LP
142 Structure pointers are dereferenced and the members are displayed
143 as appropriate.  In all cases arguments are formatted in the most C-like
144 fashion possible.
145 For example, the essence of the command ``ls \-l /dev/null'' is captured as:
146 .CW
147 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
148 .CE
149 Notice how the `struct stat' argument is dereferenced and how each member is
150 displayed symbolically.  In particular, observe how the st_mode member
151 is carefully decoded into a bitwise-OR of symbolic and numeric values.
152 Also notice in this example that the first argument to lstat is an input
153 to the system call and the second argument is an output.  Since output
154 arguments are not modified if the system call fails, arguments may not
155 always be dereferenced.  For example, retrying the ``ls \-l'' example
156 with a non-existent file produces the following line:
157 .CW
158 lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
159 .CE
160 In this case the porch light is on but nobody is home.
161 .LP
162 Character pointers are dereferenced and printed as C strings.
163 Non-printing characters in strings are normally represented by
164 ordinary C escape codes.
165 Only the first
166 .I strsize
167 (32 by default) bytes of strings are printed;
168 longer strings have an ellipsis appended following the closing quote.
169 Here is a line from ``ls \-l'' where the
170 .B getpwuid
171 library routine is reading the password file:
172 .CW
173 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
174 .CE
175 While structures are annotated using curly braces, simple pointers
176 and arrays are printed using square brackets with commas separating
177 elements.  Here is an example from the command ``id'' on a system with
178 supplementary group ids:
179 .CW
180 getgroups(32, [100, 0]) = 2
181 .CE
182 On the other hand, bit-sets are also shown using square brackets
183 but set elements are separated only by a space.  Here is the shell
184 preparing to execute an external command:
185 .CW
186 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
187 .CE
188 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
189 In some cases the bit-set is so full that printing out the unset
190 elements is more valuable.  In that case, the bit-set is prefixed by
191 a tilde like this:
192 .CW
193 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
194 .CE
195 Here the second argument represents the full set of all signals.
196 .SH OPTIONS
197 .TP 12
198 .TP
199 .B \-c
200 Count time, calls, and errors for each system call and report a summary on
201 program exit.  On Linux, this attempts to show system time (CPU time spent
202 running in the kernel) independent of wall clock time.  If
203 .B \-c
204 is used with
205 .B \-f
206 or
207 .B \-F
208 (below), only aggregate totals for all traced processes are kept.
209 .TP
210 .B \-C
211 Like
212 .B \-c
213 but also print regular output while processes are running.
214 .TP
215 .B \-D
216 Run tracer process as a detached grandchild, not as parent of the
217 tracee.  This reduces the visible effect of
218 .B strace
219 by keeping the tracee a direct child of the calling process.
220 .TP
221 .B \-d
222 Show some debugging output of
223 .B strace
224 itself on the standard error.
225 .TP
226 .B \-f
227 Trace child processes as they are created by currently traced
228 processes as a result of the
229 .BR fork (2)
230 system call.
231 .IP
232 On non-Linux platforms the new process is
233 attached to as soon as its pid is known (through the return value of
234 .BR fork (2)
235 in the parent process). This means that such children may run
236 uncontrolled for a while (especially in the case of a
237 .BR vfork (2)),
238 until the parent is scheduled again to complete its
239 .RB ( v ) fork (2)
240 call.  On Linux the child is traced from its first instruction with no delay.
241 If the parent process decides to
242 .BR wait (2)
243 for a child that is currently
244 being traced, it is suspended until an appropriate child process either
245 terminates or incurs a signal that would cause it to terminate (as
246 determined from the child's current signal disposition).
247 .TP
248 .B \-ff
249 If the
250 .B \-o
251 .I filename
252 option is in effect, each processes trace is written to
253 .I filename.pid
254 where pid is the numeric process id of each process.
255 This is incompatible with
256 .BR \-c ,
257 since no per-process counts are kept.
258 .TP
259 .B \-F
260 This option is now obsolete and it has the same functionality as
261 .BR \-f .
262 .TP
263 .B \-h
264 Print the help summary.
265 .TP
266 .B \-i
267 Print the instruction pointer at the time of the system call.
268 .TP
269 .B \-q
270 Suppress messages about attaching, detaching etc.  This happens
271 automatically when output is redirected to a file and the command
272 is run directly instead of attaching.
273 .TP
274 .B \-r
275 Print a relative timestamp upon entry to each system call.  This
276 records the time difference between the beginning of successive
277 system calls.
278 .TP
279 .B \-t
280 Prefix each line of the trace with the time of day.
281 .TP
282 .B \-tt
283 If given twice, the time printed will include the microseconds.
284 .TP
285 .B \-ttt
286 If given thrice, the time printed will include the microseconds
287 and the leading portion will be printed as the number
288 of seconds since the epoch.
289 .TP
290 .B \-T
291 Show the time spent in system calls. This records the time
292 difference between the beginning and the end of each system call.
293 .TP
294 .B \-v
295 Print unabbreviated versions of environment, stat, termios, etc.
296 calls.  These structures are very common in calls and so the default
297 behavior displays a reasonable subset of structure members.  Use
298 this option to get all of the gory details.
299 .TP
300 .B \-V
301 Print the version number of
302 .BR strace .
303 .TP
304 .B \-x
305 Print all non-ASCII strings in hexadecimal string format.
306 .TP
307 .B \-xx
308 Print all strings in hexadecimal string format.
309 .TP
310 .B \-y
311 Print paths associated with file descriptor arguments.
312 .TP
313 .BI "\-a " column
314 Align return values in a specific column (default column 40).
315 .TP
316 .BI "\-e " expr
317 A qualifying expression which modifies which events to trace
318 or how to trace them.  The format of the expression is:
319 .RS 15
320 .IP
321 [\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
322 .RE
323 .IP
324 where
325 .I qualifier
326 is one of
327 .BR trace ,
328 .BR abbrev ,
329 .BR verbose ,
330 .BR raw ,
331 .BR signal ,
332 .BR read ,
333 or
334 .B write
335 and
336 .I value
337 is a qualifier-dependent symbol or number.  The default
338 qualifier is
339 .BR trace .
340 Using an exclamation mark negates the set of values.  For example,
341 .BR \-e "\ " open
342 means literally
343 .BR \-e "\ " trace = open
344 which in turn means trace only the
345 .B open
346 system call.  By contrast,
347 .BR \-e "\ " trace "=!" open
348 means to trace every system call except
349 .BR open .
350 In addition, the special values
351 .B all
352 and
353 .B none
354 have the obvious meanings.
355 .IP
356 Note that some shells use the exclamation point for history
357 expansion even inside quoted arguments.  If so, you must escape
358 the exclamation point with a backslash.
359 .TP
360 \fB\-e\ trace\fR=\fIset\fR
361 Trace only the specified set of system calls.  The
362 .B \-c
363 option is useful for determining which system calls might be useful
364 to trace.  For example,
365 .BR trace = open,close,read,write
366 means to only
367 trace those four system calls.  Be careful when making inferences
368 about the user/kernel boundary if only a subset of system calls
369 are being monitored.  The default is
370 .BR trace = all .
371 .TP
372 .BR "\-e\ trace" = file
373 Trace all system calls which take a file name as an argument.  You
374 can think of this as an abbreviation for
375 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
376 which is useful to seeing what files the process is referencing.
377 Furthermore, using the abbreviation will ensure that you don't
378 accidentally forget to include a call like
379 .B lstat
380 in the list.  Betchya woulda forgot that one.
381 .TP
382 .BR "\-e\ trace" = process
383 Trace all system calls which involve process management.  This
384 is useful for watching the fork, wait, and exec steps of a process.
385 .TP
386 .BR "\-e\ trace" = network
387 Trace all the network related system calls.
388 .TP
389 .BR "\-e\ trace" = signal
390 Trace all signal related system calls.
391 .TP
392 .BR "\-e\ trace" = ipc
393 Trace all IPC related system calls.
394 .TP
395 .BR "\-e\ trace" = desc
396 Trace all file descriptor related system calls.
397 .TP
398 .BR "\-e\ trace" = memory
399 Trace all memory mapping related system calls.
400 .TP
401 \fB\-e\ abbrev\fR=\fIset\fR
402 Abbreviate the output from printing each member of large structures.
403 The default is
404 .BR abbrev = all .
405 The
406 .B \-v
407 option has the effect of
408 .BR abbrev = none .
409 .TP
410 \fB\-e\ verbose\fR=\fIset\fR
411 Dereference structures for the specified set of system calls.  The
412 default is
413 .BR verbose = all .
414 .TP
415 \fB\-e\ raw\fR=\fIset\fR
416 Print raw, undecoded arguments for the specified set of system calls.
417 This option has the effect of causing all arguments to be printed
418 in hexadecimal.  This is mostly useful if you don't trust the
419 decoding or you need to know the actual numeric value of an
420 argument.
421 .TP
422 \fB\-e\ signal\fR=\fIset\fR
423 Trace only the specified subset of signals.  The default is
424 .BR signal = all .
425 For example,
426 .B signal "=!" SIGIO
427 (or
428 .BR signal "=!" io )
429 causes SIGIO signals not to be traced.
430 .TP
431 \fB\-e\ read\fR=\fIset\fR
432 Perform a full hexadecimal and ASCII dump of all the data read from
433 file descriptors listed in the specified set.  For example, to see
434 all input activity on file descriptors
435 .I 3
436 and
437 .I 5
438 use
439 \fB\-e\ read\fR=\fI3\fR,\fI5\fR.
440 Note that this is independent from the normal tracing of the
441 .BR read (2)
442 system call which is controlled by the option
443 .BR -e "\ " trace = read .
444 .TP
445 \fB\-e\ write\fR=\fIset\fR
446 Perform a full hexadecimal and ASCII dump of all the data written to
447 file descriptors listed in the specified set.  For example, to see
448 all output activity on file descriptors
449 .I 3
450 and
451 .I 5
452 use
453 \fB\-e\ write\fR=\fI3\fR,\fI5\fR.
454 Note that this is independent from the normal tracing of the
455 .BR write (2)
456 system call which is controlled by the option
457 .BR -e "\ " trace = write .
458 .TP
459 .BI "\-I " interruptible
460 When strace can be interrupted by signals (such as pressing ^C).
461 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
462 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
463 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
464 strace -o FILE PROG not stop on ^Z).
465 .TP
466 .BI "\-o " filename
467 Write the trace output to the file
468 .I filename
469 rather than to stderr.
470 Use
471 .I filename.pid
472 if
473 .B \-ff
474 is used.
475 If the argument begins with `|' or with `!' then the rest of the
476 argument is treated as a command and all output is piped to it.
477 This is convenient for piping the debugging output to a program
478 without affecting the redirections of executed programs.
479 .TP
480 .BI "\-O " overhead
481 Set the overhead for tracing system calls to
482 .I overhead
483 microseconds.
484 This is useful for overriding the default heuristic for guessing
485 how much time is spent in mere measuring when timing system calls using
486 the
487 .B \-c
488 option.  The accuracy of the heuristic can be gauged by timing a given
489 program run without tracing (using
490 .BR time (1))
491 and comparing the accumulated
492 system call time to the total produced using
493 .BR \-c .
494 .TP
495 .BI "\-p " pid
496 Attach to the process with the process
497 .SM ID
498 .I pid
499 and begin tracing.
500 The trace may be terminated
501 at any time by a keyboard interrupt signal (\c
502 .SM CTRL\s0-C).
503 .B strace
504 will respond by detaching itself from the traced process(es)
505 leaving it (them) to continue running.
506 Multiple
507 .B \-p
508 options can be used to attach to many processes.
509 -p "`pidof PROG`" syntax is supported.
510 .TP
511 .BI "\-P " path
512 Trace only system calls accessing
513 .I path.
514 Multiple
515 .B \-P
516 options can be used to specify up to 256 paths.
517 .TP
518 .BI "\-s " strsize
519 Specify the maximum string size to print (the default is 32).  Note
520 that filenames are not considered strings and are always printed in
521 full.
522 .TP
523 .BI "\-S " sortby
524 Sort the output of the histogram printed by the
525 .B \-c
526 option by the specified criterion.  Legal values are
527 .BR time ,
528 .BR calls ,
529 .BR name ,
530 and
531 .B nothing
532 (default is
533 .BR time ).
534 .TP
535 .BI "\-u " username
536 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
537 supplementary groups of
538 .IR username .
539 This option is only useful when running as root and enables the
540 correct execution of setuid and/or setgid binaries.
541 Unless this option is used setuid and setgid programs are executed
542 without effective privileges.
543 .TP
544 \fB\-E\ \fIvar\fR=\fIval\fR
545 Run command with
546 .IR var = val
547 in its list of environment variables.
548 .TP
549 .BI "\-E " var
550 Remove
551 .IR var
552 from the inherited list of environment variables before passing it on to
553 the command.
554 .SH DIAGNOSTICS
555 When
556 .I command
557 exits,
558 .B strace
559 exits with the same exit status.
560 If
561 .I command
562 is terminated by a signal,
563 .B strace
564 terminates itself with the same signal, so that
565 .B strace
566 can be used as a wrapper process transparent to the invoking parent process.
567 .LP
568 When using
569 .BR \-p ,
570 the exit status of
571 .B strace
572 is zero unless there was an unexpected error in doing the tracing.
573 .SH "SETUID INSTALLATION"
574 If
575 .B strace
576 is installed setuid to root then the invoking user will be able to
577 attach to and trace processes owned by any user.
578 In addition setuid and setgid programs will be executed and traced
579 with the correct effective privileges.
580 Since only users trusted with full root privileges should be allowed
581 to do these things,
582 it only makes sense to install
583 .B strace
584 as setuid to root when the users who can execute it are restricted
585 to those users who have this trust.
586 For example, it makes sense to install a special version of
587 .B strace
588 with mode `rwsr-xr--', user
589 .B root
590 and group
591 .BR trace ,
592 where members of the
593 .B trace
594 group are trusted users.
595 If you do use this feature, please remember to install
596 a non-setuid version of
597 .B strace
598 for ordinary lusers to use.
599 .SH "SEE ALSO"
600 .BR ltrace (1),
601 .BR time (1),
602 .BR ptrace (2),
603 .BR proc (5)
604 .SH NOTES
605 It is a pity that so much tracing clutter is produced by systems
606 employing shared libraries.
607 .LP
608 It is instructive to think about system call inputs and outputs
609 as data-flow across the user/kernel boundary.  Because user-space
610 and kernel-space are separate and address-protected, it is
611 sometimes possible to make deductive inferences about process
612 behavior using inputs and outputs as propositions.
613 .LP
614 In some cases, a system call will differ from the documented behavior
615 or have a different name.  For example, on System V-derived systems
616 the true
617 .BR time (2)
618 system call does not take an argument and the
619 .B stat
620 function is called
621 .B xstat
622 and takes an extra leading argument.  These
623 discrepancies are normal but idiosyncratic characteristics of the
624 system call interface and are accounted for by C library wrapper
625 functions.
626 .LP
627 On some platforms a process that has a system call trace applied
628 to it with the
629 .B \-p
630 option will receive a
631 .BR \s-1SIGSTOP\s0 .
632 This signal may interrupt a system call that is not restartable.
633 This may have an unpredictable effect on the process
634 if the process takes no action to restart the system call.
635 .SH BUGS
636 Programs that use the
637 .I setuid
638 bit do not have
639 effective user
640 .SM ID
641 privileges while being traced.
642 .LP
643 A traced process runs slowly.
644 .LP
645 Traced processes which are descended from
646 .I command
647 may be left running after an interrupt signal (\c
648 .SM CTRL\s0-C).
649 .LP
650 The
651 .B \-i
652 option is weakly supported.
653 .SH HISTORY
654 .B strace
655 The original
656 .B strace
657 was written by Paul Kranenburg
658 for SunOS and was inspired by its trace utility.
659 The SunOS version of
660 .B strace
661 was ported to Linux and enhanced
662 by Branko Lankester, who also wrote the Linux kernel support.
663 Even though Paul released
664 .B strace
665 2.5 in 1992,
666 Branko's work was based on Paul's
667 .B strace
668 1.5 release from 1991.
669 In 1993, Rick Sladkey merged
670 .B strace
671 2.5 for SunOS and the second release of
672 .B strace
673 for Linux, added many of the features of
674 .BR truss (1)
675 from SVR4, and produced an
676 .B strace
677 that worked on both platforms.  In 1994 Rick ported
678 .B strace
679 to SVR4 and Solaris and wrote the
680 automatic configuration support.  In 1995 he ported
681 .B strace
682 to Irix
683 and tired of writing about himself in the third person.
684 .SH PROBLEMS
685 Problems with
686 .B strace
687 should be reported to the
688 .B strace
689 mailing list at <strace\-devel@lists.sourceforge.net>.