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