]> granicus.if.org Git - strace/blob - strace.1
Fix a problem with sys_lseek on x32
[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 \fB\-e\ abbrev\fR=\fIset\fR
399 Abbreviate the output from printing each member of large structures.
400 The default is
401 .BR abbrev = all .
402 The
403 .B \-v
404 option has the effect of
405 .BR abbrev = none .
406 .TP
407 \fB\-e\ verbose\fR=\fIset\fR
408 Dereference structures for the specified set of system calls.  The
409 default is
410 .BR verbose = all .
411 .TP
412 \fB\-e\ raw\fR=\fIset\fR
413 Print raw, undecoded arguments for the specified set of system calls.
414 This option has the effect of causing all arguments to be printed
415 in hexadecimal.  This is mostly useful if you don't trust the
416 decoding or you need to know the actual numeric value of an
417 argument.
418 .TP
419 \fB\-e\ signal\fR=\fIset\fR
420 Trace only the specified subset of signals.  The default is
421 .BR signal = all .
422 For example,
423 .B signal "=!" SIGIO
424 (or
425 .BR signal "=!" io )
426 causes SIGIO signals not to be traced.
427 .TP
428 \fB\-e\ read\fR=\fIset\fR
429 Perform a full hexadecimal and ASCII dump of all the data read from
430 file descriptors listed in the specified set.  For example, to see
431 all input activity on file descriptors
432 .I 3
433 and
434 .I 5
435 use
436 \fB\-e\ read\fR=\fI3\fR,\fI5\fR.
437 Note that this is independent from the normal tracing of the
438 .BR read (2)
439 system call which is controlled by the option
440 .BR -e "\ " trace = read .
441 .TP
442 \fB\-e\ write\fR=\fIset\fR
443 Perform a full hexadecimal and ASCII dump of all the data written to
444 file descriptors listed in the specified set.  For example, to see
445 all output activity on file descriptors
446 .I 3
447 and
448 .I 5
449 use
450 \fB\-e\ write\fR=\fI3\fR,\fI5\fR.
451 Note that this is independent from the normal tracing of the
452 .BR write (2)
453 system call which is controlled by the option
454 .BR -e "\ " trace = write .
455 .TP
456 .BI "\-I " interruptible
457 When strace can be interrupted by signals (such as pressing ^C).
458 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
459 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
460 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
461 strace -o FILE PROG not stop on ^Z).
462 .TP
463 .BI "\-o " filename
464 Write the trace output to the file
465 .I filename
466 rather than to stderr.
467 Use
468 .I filename.pid
469 if
470 .B \-ff
471 is used.
472 If the argument begins with `|' or with `!' then the rest of the
473 argument is treated as a command and all output is piped to it.
474 This is convenient for piping the debugging output to a program
475 without affecting the redirections of executed programs.
476 .TP
477 .BI "\-O " overhead
478 Set the overhead for tracing system calls to
479 .I overhead
480 microseconds.
481 This is useful for overriding the default heuristic for guessing
482 how much time is spent in mere measuring when timing system calls using
483 the
484 .B \-c
485 option.  The accuracy of the heuristic can be gauged by timing a given
486 program run without tracing (using
487 .BR time (1))
488 and comparing the accumulated
489 system call time to the total produced using
490 .BR \-c .
491 .TP
492 .BI "\-p " pid
493 Attach to the process with the process
494 .SM ID
495 .I pid
496 and begin tracing.
497 The trace may be terminated
498 at any time by a keyboard interrupt signal (\c
499 .SM CTRL\s0-C).
500 .B strace
501 will respond by detaching itself from the traced process(es)
502 leaving it (them) to continue running.
503 Multiple
504 .B \-p
505 options can be used to attach to many processes.
506 -p "`pidof PROG`" syntax is supported.
507 .TP
508 .BI "\-P " path
509 Trace only system calls accessing
510 .I path.
511 Multiple
512 .B \-P
513 options can be used to specify up to 256 paths.
514 .TP
515 .BI "\-s " strsize
516 Specify the maximum string size to print (the default is 32).  Note
517 that filenames are not considered strings and are always printed in
518 full.
519 .TP
520 .BI "\-S " sortby
521 Sort the output of the histogram printed by the
522 .B \-c
523 option by the specified criterion.  Legal values are
524 .BR time ,
525 .BR calls ,
526 .BR name ,
527 and
528 .B nothing
529 (default is
530 .BR time ).
531 .TP
532 .BI "\-u " username
533 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
534 supplementary groups of
535 .IR username .
536 This option is only useful when running as root and enables the
537 correct execution of setuid and/or setgid binaries.
538 Unless this option is used setuid and setgid programs are executed
539 without effective privileges.
540 .TP
541 \fB\-E\ \fIvar\fR=\fIval\fR
542 Run command with
543 .IR var = val
544 in its list of environment variables.
545 .TP
546 .BI "\-E " var
547 Remove
548 .IR var
549 from the inherited list of environment variables before passing it on to
550 the command.
551 .SH DIAGNOSTICS
552 When
553 .I command
554 exits,
555 .B strace
556 exits with the same exit status.
557 If
558 .I command
559 is terminated by a signal,
560 .B strace
561 terminates itself with the same signal, so that
562 .B strace
563 can be used as a wrapper process transparent to the invoking parent process.
564 .LP
565 When using
566 .BR \-p ,
567 the exit status of
568 .B strace
569 is zero unless there was an unexpected error in doing the tracing.
570 .SH "SETUID INSTALLATION"
571 If
572 .B strace
573 is installed setuid to root then the invoking user will be able to
574 attach to and trace processes owned by any user.
575 In addition setuid and setgid programs will be executed and traced
576 with the correct effective privileges.
577 Since only users trusted with full root privileges should be allowed
578 to do these things,
579 it only makes sense to install
580 .B strace
581 as setuid to root when the users who can execute it are restricted
582 to those users who have this trust.
583 For example, it makes sense to install a special version of
584 .B strace
585 with mode `rwsr-xr--', user
586 .B root
587 and group
588 .BR trace ,
589 where members of the
590 .B trace
591 group are trusted users.
592 If you do use this feature, please remember to install
593 a non-setuid version of
594 .B strace
595 for ordinary lusers to use.
596 .SH "SEE ALSO"
597 .BR ltrace (1),
598 .BR time (1),
599 .BR ptrace (2),
600 .BR proc (5)
601 .SH NOTES
602 It is a pity that so much tracing clutter is produced by systems
603 employing shared libraries.
604 .LP
605 It is instructive to think about system call inputs and outputs
606 as data-flow across the user/kernel boundary.  Because user-space
607 and kernel-space are separate and address-protected, it is
608 sometimes possible to make deductive inferences about process
609 behavior using inputs and outputs as propositions.
610 .LP
611 In some cases, a system call will differ from the documented behavior
612 or have a different name.  For example, on System V-derived systems
613 the true
614 .BR time (2)
615 system call does not take an argument and the
616 .B stat
617 function is called
618 .B xstat
619 and takes an extra leading argument.  These
620 discrepancies are normal but idiosyncratic characteristics of the
621 system call interface and are accounted for by C library wrapper
622 functions.
623 .LP
624 On some platforms a process that has a system call trace applied
625 to it with the
626 .B \-p
627 option will receive a
628 .BR \s-1SIGSTOP\s0 .
629 This signal may interrupt a system call that is not restartable.
630 This may have an unpredictable effect on the process
631 if the process takes no action to restart the system call.
632 .SH BUGS
633 Programs that use the
634 .I setuid
635 bit do not have
636 effective user
637 .SM ID
638 privileges while being traced.
639 .LP
640 A traced process runs slowly.
641 .LP
642 Traced processes which are descended from
643 .I command
644 may be left running after an interrupt signal (\c
645 .SM CTRL\s0-C).
646 .LP
647 The
648 .B \-i
649 option is weakly supported.
650 .SH HISTORY
651 .B strace
652 The original
653 .B strace
654 was written by Paul Kranenburg
655 for SunOS and was inspired by its trace utility.
656 The SunOS version of
657 .B strace
658 was ported to Linux and enhanced
659 by Branko Lankester, who also wrote the Linux kernel support.
660 Even though Paul released
661 .B strace
662 2.5 in 1992,
663 Branko's work was based on Paul's
664 .B strace
665 1.5 release from 1991.
666 In 1993, Rick Sladkey merged
667 .B strace
668 2.5 for SunOS and the second release of
669 .B strace
670 for Linux, added many of the features of
671 .BR truss (1)
672 from SVR4, and produced an
673 .B strace
674 that worked on both platforms.  In 1994 Rick ported
675 .B strace
676 to SVR4 and Solaris and wrote the
677 automatic configuration support.  In 1995 he ported
678 .B strace
679 to Irix
680 and tired of writing about himself in the third person.
681 .SH PROBLEMS
682 Problems with
683 .B strace
684 should be reported to the
685 .B strace
686 mailing list at <strace\-devel@lists.sourceforge.net>.