]> granicus.if.org Git - strace/blob - strace.1
Add capability for Linux to change a vfork call into plain fork, which
[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
37 .fi
38 .sp
39 ..
40 .TH STRACE 1 "96/02/13"
41 .SH NAME
42 strace \- trace system calls and signals
43 .SH SYNOPSIS
44 .B strace
45 [
46 .B \-dffhiqrtttTvxx
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 .I command
70 [
71 .I arg
72 \&...
73 ]
74 ]
75 .sp
76 .B strace
77 .B \-c
78 [
79 .BI \-e expr
80 ]
81 \&...
82 [
83 .BI \-O overhead
84 ]
85 [
86 .BI \-S sortby
87 ]
88 [
89 .I command
90 [
91 .I arg
92 \&...
93 ]
94 ]
95 .SH DESCRIPTION
96 .IX "strace command" "" "\fLstrace\fR command"
97 .LP
98 In the simplest case
99 .B strace
100 runs the specified
101 .I command
102 until it exits.
103 It intercepts and records the system calls which are called
104 by a process and the signals which are received by a process.
105 The name of each system call, its arguments and its return value
106 are printed on standard error or to the file specified with the
107 .B \-o
108 option.
109 .LP
110 .B strace
111 is a useful diagnositic, instructional, and debugging tool.
112 System adminstrators, diagnosticians and trouble-shooters will find
113 it invaluable for solving problems with
114 programs for which the source is not readily available since
115 they do not need to be recompiled in order to trace them.
116 Students, hackers and the overly-curious will find that
117 a great deal can be learned about a system and its system calls by
118 tracing even ordinary programs.  And programmers will find that
119 since system calls and signals are events that happen at the user/kernel
120 interface, a close examination of this boundary is very
121 useful for bug isolation, sanity checking and
122 attempting to capture race conditions.
123 .LP
124 Each line in the trace contains the system call name, followed
125 by its arguments in parentheses and its return value.
126 An example from stracing the command ``cat /dev/null'' is:
127 .CW
128 open("/dev/null", O_RDONLY) = 3
129 .CE
130 Errors (typically a return value of \-1) have the errno symbol
131 and error string appended.
132 .CW
133 open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
134 .CE
135 Signals are printed as a signal symbol and a signal string.
136 An excerpt from stracing and interrupting the command ``sleep 666'' is:
137 .CW
138 sigsuspend([] <unfinished ...>
139 --- SIGINT (Interrupt) ---
140 +++ killed by SIGINT +++
141 .CE
142 Arguments are printed in symbolic form with a passion.
143 This example shows the shell peforming ``>>xyzzy'' output redirection:
144 .CW
145 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
146 .CE
147 Here the three argument form of open is decoded by breaking down the
148 flag argument into its three bitwise-OR constituents and printing the
149 mode value in octal by tradition.  Where traditional or native
150 usage differs from ANSI or POSIX, the latter forms are preferred.
151 In some cases, strace output has proven to be more readable than
152 the source.
153 .LP
154 Structure pointers are dereferenced and the members are displayed
155 as appropriate.  In all cases arguments are formatted in the most C-like
156 fashion possible.
157 For example, the essence of the command ``ls \-l /dev/null'' is captured as:
158 .CW
159 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
160 .CE
161 Notice how the `struct stat' argument is dereferenced and how each member is
162 displayed symbolically.  In particular, observe how the st_mode member
163 is carefully decoded into a bitwise-OR of symbolic and numeric values.
164 Also notice in this example that the first argument to lstat is an input
165 to the system call and the second argument is an output.  Since output
166 arguments not modified if the system call fails, arguments may not
167 always be dereferenced.  For example, retrying the ``ls \-l'' example
168 with a non-existent file produces the following line:
169 .CW
170 lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
171 .CE
172 In this case the porch light is on but nobody is home.
173 .LP
174 Character pointers are dereferenced and printed as C strings.
175 Non-printing characters in strings are normally represented by
176 ordinary C escape codes.
177 Only the first
178 .I strsize
179 (32 by default) bytes of strings are printed;
180 longer strings have an ellipsis appended following the closing quote.
181 Here is a line from ``ls \-l'' where the getpwuid library routine is
182 reading the password file:
183 .CW
184 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
185 .CE
186 While structures are annotated using curly braces, simple pointers
187 and arrays are printed using square brackets with commas separating
188 elements.  Here is an example from the command ``id'' on a system with
189 supplementary group ids:
190 .CW
191 getgroups(32, [100, 0]) = 2
192 .CE
193 On the other hand, bit-sets are also shown using square brackets
194 but set elements are separated only by a space.  Here is the shell
195 preparing to execute an external command:
196 .CW
197 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
198 .CE
199 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
200 In some cases the bit-set is so full that printing out the unset
201 elements is more valuable.  In that case, the bit-set is prefixed by
202 a tilde like this:
203 .CW
204 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
205 .CE
206 Here the second argument represents the full set of all signals.
207 .SH OPTIONS
208 .TP 12
209 .TP
210 .B \-c
211 Count time, calls, and errors for each system call and report a
212 summary on program exit.
213 .TP
214 .B \-d
215 Show some debugging output of strace itself on
216 .I stderr .
217 .TP
218 .B \-f
219 Trace child processes as they are created by currently traced
220 processes as a result of the fork(2) system call.  The new process is
221 attached to as soon as its pid is known (through the return value of
222 fork(2) in the parent process). This means that such children may run
223 uncontrolled for a while (especially in the case of a vfork(2)), until
224 the parent is scheduled again to complete its (v)fork(2) call.
225 If the parent process decides to wait(2) for a child that is currently
226 being traced, it is suspended until an appropriate child process either
227 terminates or incurs a signal that would cause it to terminate (as
228 determined from the child's current signal disposition).
229 .TP
230 .B \-ff
231 If the
232 .B \-o
233 .I filename
234 option is in effect, each processes trace is written to
235 .I filename.pid
236 where pid is the numeric process id of each process.
237 .TP
238 .B \-F
239 Attempt to follow vforks.  (On SunOS 4.x, this is accomplished with
240 some dynamic linking trickery.  On Linux, it requires some kernel
241 functionality not yet in the standard kernel.)  Otherwise, vforks will
242 not be followed even if
243 .B \-f
244 has been given.
245 .TP
246 .B \-h
247 Print the help summary.
248 .TP
249 .B \-i
250 Print the instruction pointer at the time of the system call.
251 .TP
252 .B \-q
253 Suppress messages about attaching, detaching etc.  This happens
254 automatically when output is redirected to a file and the command
255 is run directly instead of attaching.
256 .TP
257 .B \-r
258 Print a relative timestamp upon entry to each system call.  This
259 records the time difference between the beginning of successive
260 system calls.
261 .TP
262 .B \-t
263 Prefix each line of the trace with the time of day.
264 .TP
265 .B \-tt
266 If given twice, the time printed will include the microseconds.
267 .TP
268 .B \-ttt
269 If given thrice, the time printed will include the microseconds
270 and the leading portion will be printed as the number
271 of seconds since the epoch.
272 .TP
273 .B \-T
274 Show the time spent in system calls. This records the time
275 difference between the beginning and the end of each system call.
276 .TP
277 .B \-v
278 Print unabbreviated versions of environment, stat, termios, etc.
279 calls.  These structures are very common in calls and so the default
280 behavior displays a reasonable subset of structure members.  Use
281 this option to get all of the gory details.
282 .TP
283 .B \-V
284 Print the version number of strace.
285 .TP
286 .B \-x
287 Print all non-ascii strings in hexadecimal string format.
288 .TP
289 .B \-xx
290 Print all strings in hexadecimal string format.
291 .TP
292 .BI "\-a " column
293 Align return values in a secific column (default column 40).
294 .TP
295 .BI "\-e " expr
296 A qualifying expression which modifies which events to trace
297 or how to trace them.  The format of the expression is:
298 .br
299 [qualifier=][!]value1[,value2]...
300 .br
301 where qualifier is one of trace, abbrev, verbose, raw, signal, read, or write
302 and value is a qualifier-dependent symbol or number.  The default
303 qualifier is trace.  Using an exclamation mark negates the set of values.
304 For example \-eopen means literally \-e trace=open which in turn means
305 trace only the open system call.  By contrast, \-etrace=!open means
306 to trace every system call except open.  In addition the special values
307 all and none have the obvious meanings.
308 .LP
309 Note that some shells use the exclamation point for history
310 expansion; even inside quoted arguments.  If so, you must escape
311 the exclamation point with a backslash.
312 .TP
313 .BI "\-e trace=" set
314 Trace only the specified set of system calls.  The
315 .B \-c
316 option is useful for determining which system calls might be useful
317 to trace.  For example, trace=open,close,read,write means to only
318 trace those four system calls.  Be careful when making inferences
319 about the user/kernel boundary if only a subset of system calls
320 are being monitored.  The default is trace=all.
321 .TP
322 .B "\-e trace=file"
323 Trace all system calls which take a file name as an argument.  You
324 can think of this as an abbreviation for
325 .BR "\-e trace=open,stat,chmod,unlink," ...
326 which is useful to seeing what files the process is referencing.
327 Furthermore, using the abbreviation will ensure that you don't
328 accidentally forget to include a call like
329 .B lstat
330 in the list.  Betchya woulda forgot that one.
331 .TP
332 .B "\-e trace=process"
333 Trace all system calls which involve process management.  This
334 is useful for watching the fork, wait, and exec steps of a process.
335 .TP
336 .B "\-e trace=network"
337 Trace all the network related system calls.
338 .TP
339 .B "\-e trace=signal"
340 Trace all signal related system calls.
341 .TP
342 .B "\-e trace=ipc"
343 Trace all IPC related system calls.
344 .TP
345 .BI "\-e abbrev=" set
346 Abbreviate the output from printing each member of large structures.
347 The default is abbrev=all.  The
348 .B \-v
349 option has the effect of abbrev=none.
350 .TP
351 .BI "\-e verbose=" set
352 Dereference structures for the specified set of system calls.  The
353 default is verbose=all.
354 .TP
355 .BI "\-e raw=" set
356 Print raw, undecoded arguments for the specifed set of system calls.
357 This option has the effect of causing all arguments to be printed
358 in hexadecimal.  This is mostly useful if you don't trust the
359 decoding or you need to know the actual numeric value of an
360 argument.
361 .TP
362 .BI "\-e signal=" set
363 Trace only the specified subset of signals.  The default is signal=all.
364 For example signal=!SIGIO (or signal=!io) causes SIGIO signals not to
365 be traced.
366 .TP
367 .BI "\-e read=" set
368 Perform a full hexadecimal and ascii dump of all the data read from
369 file descriptors listed in the specified set.  For example, to see
370 all input activity on file descriptors 3 and 5 use
371 .BR "\-e read=3,5" .
372 Note that this is independent from the normal tracing of the read
373 system call which is controlled by the option
374 .BR "\-e trace=read" .
375 .TP
376 .BI "\-e write=" set
377 Perform a full hexadecimal and ascii dump of all the data written to
378 file descriptors listed in the specified set.  For example, to see
379 all output activity on file descriptors 3 and 5 use
380 .BR "\-e write=3,5" .
381 Note that this is independent from the normal tracing of the write
382 system call which is controlled by the option
383 .BR "\-e trace=write" .
384 .TP
385 .BI "\-o " filename
386 Write the trace output to the file
387 .I filename
388 rather than to stderr.
389 Use
390 .I filename.pid
391 if
392 .B \-ff
393 is used.
394 If the argument begins with `|' or with `!' then the rest of the
395 argument is treated as a command and all output is piped to it.
396 This is convenient for piping the debugging output to a program
397 without affecting the redirections of executed programs.
398 .TP
399 .BI "\-O " overhead
400 Set the overhead for tracing system calls to overhead microseconds.
401 This is useful for overriding the default heuristic for guessing
402 how much time is spent in mere measuring when timing system calls using
403 the
404 .B \-c
405 option.  The acuracy of the heuristic can be gauged by timing a given
406 program run without tracing (using time(1)) and comparing the accumulated
407 system call time to the total produced using
408 .B \-c .
409 .TP
410 .BI "\-p " pid
411 Attach to the process with the process
412 .SM ID
413 .I pid
414 and begin tracing.
415 The trace may be terminated
416 at any time by a keyboard interrupt signal (\c
417 .SM CTRL\s0-C).
418 .B strace
419 will respond by detaching itself from the traced process(es)
420 leaving it (them) to continue running.
421 Multiple
422 .B \-p
423 options can be used to attach to up to 32 processes in addition to
424 .I command
425 (which is optional if at least one
426 .B \-p
427 option is given).
428 .TP
429 .BI "\-s " strsize
430 Specify the maximum string size to print (the default is 32).  Note
431 that filenames are not considered strings and are always printed in
432 full.
433 .TP
434 .BI "\-S " sortby
435 Sort the output of the histogram printed by the
436 .B \-c
437 option by the specified critereon.  Legal values are
438 time, calls, name, and nothing (default time).
439 .TP
440 .BI "\-u " username
441 Run command with the userid, groupid and supplementary groups of
442 .IR username .
443 This option is only useful when running as root and enables the
444 correct execution of setuid and/or setgid binaries.
445 Unless this option is used setuid and setgid programs are executed
446 without effective privileges.
447 .SH "SETUID INSTALLATION"
448 If
449 .B strace
450 is installed setuid to root then the invoking user will be able to
451 attach to and trace processes owned by any user.
452 In addition setuid and setgid programs will be executed and traced
453 with the correct effective privileges.
454 Since only users trusted with full root privileges should be allowed
455 to do these things,
456 it only makes sense to install
457 .B strace
458 as setuid to root when the users who can execute it are restricted
459 to those users who have this trust.
460 For example, it makes sense to install a special version of
461 .B
462 strace
463 with mode `rwsr-xr--', user root and group trace,
464 where members of the trace group are trusted users.
465 If you do use this feature, please remember to install
466 a non-setuid version of strace for ordinary lusers to use.
467 .SH "SEE ALSO"
468 .BR ptrace(2) ,
469 .BR proc(4) ,
470 .BR time(1) ,
471 .BR trace(1) ,
472 .BR truss(1)
473 .SH NOTES
474 It is a pity that so much tracing clutter is produced by systems
475 employing shared libraries.
476 .LP
477 It is instructive to think about system call inputs and outputs
478 as data-flow across the user/kernel boundary.  Because user-space
479 and kernel-space are separate and address-protected, it is
480 sometimes possible to make deductive inferences about process
481 behavior using inputs and outputs as propositions.
482 .LP
483 In some cases, a system call will differ from the documented behavior
484 or have a different name.  For example, on System V derived systems
485 the true time(2) system call does not take an argument and the stat
486 function is called xstat and takes an extra leading argument.  These
487 discrepancies are normal but idiosyncratic characteristics of the
488 system call interface and are accounted for by C library wrapper
489 functions.
490 .LP
491 On some platforms a process that has a system call trace applied
492 to it with the
493 .B \-p
494 option will receive a
495 .BR \s-1SIGSTOP\s0 .
496 This signal may interrupt a system call that is not restartable.
497 This may have an unpredictable effect on the process
498 if the process takes no action to restart the system call.
499 .SH BUGS
500 Programs that use the
501 .I setuid
502 bit do not have
503 effective user
504 .SM ID
505 privileges while being traced.
506 .LP
507 A traced process ignores
508 .SM SIGSTOP
509 except of SVR4 platforms.
510 .LP
511 A traced process which tries to block SIGTRAP will be sent a SIGSTOP
512 in an attempt to force continuation of tracing.
513 .LP
514 A traced process runs slowly.
515 .LP
516 Traced processes which are descended from
517 .I command
518 may be left running after an interrupt signal (\c
519 .SM CTRL\s0-C).
520 .LP
521 On Linux, exciting as it would be, tracing the init process is forbidden.
522 .LP
523 The
524 .B \-i
525 option is weakly supported.
526 .SH HISTORY
527 .B strace
528 The original strace was written by Paul Kranenburg
529 for SunOS and was inspired by its trace utility.
530 The SunOS version of strace was ported to Linux and enhanced
531 by Branko Lankester, who also wrote the Linux kernel support.
532 Even though Paul released strace 2.5 in 1992,
533 Branko's work was based on Paul's strace 1.5 release from 1991.
534 In 1993, Rick Sladkey merged strace 2.5 for SunOS and the
535 second release of strace for Linux, added many of the features of
536 truss from SVR4, and produced an strace that worked on both platforms.
537 In 1994 Rick ported strace to SVR4 and Solaris and wrote the
538 automatic configuration support.  In 1995 he ported strace to Irix
539 and tired of writing about himself in the third person.
540 .SH PROBLEMS
541 Problems with
542 .B strace
543 should be reported to the current
544 .B strace
545 maintainer, Rick Sladkey, at <jrs@world.std.com>.