Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 36 | .ft R |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | .fi |
| 38 | .sp |
| 39 | .. |
Wichert Akkerman | 8dc9a1a | 1999-07-09 14:08:14 +0000 | [diff] [blame] | 40 | .TH STRACE 1 "99/06/11" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 |
Nate Sammons | b4aa113 | 1999-03-31 05:59:04 +0000 | [diff] [blame] | 111 | is a useful diagnostic, instructional, and debugging tool. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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. |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 151 | In some cases, |
| 152 | .B strace |
| 153 | output has proven to be more readable than the source. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 154 | .LP |
| 155 | Structure pointers are dereferenced and the members are displayed |
| 156 | as appropriate. In all cases arguments are formatted in the most C-like |
| 157 | fashion possible. |
| 158 | For example, the essence of the command ``ls \-l /dev/null'' is captured as: |
| 159 | .CW |
| 160 | lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0 |
| 161 | .CE |
| 162 | Notice how the `struct stat' argument is dereferenced and how each member is |
| 163 | displayed symbolically. In particular, observe how the st_mode member |
| 164 | is carefully decoded into a bitwise-OR of symbolic and numeric values. |
| 165 | Also notice in this example that the first argument to lstat is an input |
| 166 | to the system call and the second argument is an output. Since output |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 167 | arguments are not modified if the system call fails, arguments may not |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 168 | always be dereferenced. For example, retrying the ``ls \-l'' example |
| 169 | with a non-existent file produces the following line: |
| 170 | .CW |
| 171 | lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory) |
| 172 | .CE |
| 173 | In this case the porch light is on but nobody is home. |
| 174 | .LP |
| 175 | Character pointers are dereferenced and printed as C strings. |
| 176 | Non-printing characters in strings are normally represented by |
| 177 | ordinary C escape codes. |
| 178 | Only the first |
| 179 | .I strsize |
| 180 | (32 by default) bytes of strings are printed; |
| 181 | longer strings have an ellipsis appended following the closing quote. |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 182 | Here is a line from ``ls \-l'' where the |
| 183 | .B getpwuid |
| 184 | library routine is reading the password file: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 185 | .CW |
| 186 | read(3, "root::0:0:System Administrator:/"..., 1024) = 422 |
| 187 | .CE |
| 188 | While structures are annotated using curly braces, simple pointers |
| 189 | and arrays are printed using square brackets with commas separating |
| 190 | elements. Here is an example from the command ``id'' on a system with |
| 191 | supplementary group ids: |
| 192 | .CW |
| 193 | getgroups(32, [100, 0]) = 2 |
| 194 | .CE |
| 195 | On the other hand, bit-sets are also shown using square brackets |
| 196 | but set elements are separated only by a space. Here is the shell |
| 197 | preparing to execute an external command: |
| 198 | .CW |
| 199 | sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0 |
| 200 | .CE |
| 201 | Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU. |
| 202 | In some cases the bit-set is so full that printing out the unset |
| 203 | elements is more valuable. In that case, the bit-set is prefixed by |
| 204 | a tilde like this: |
| 205 | .CW |
| 206 | sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0 |
| 207 | .CE |
| 208 | Here the second argument represents the full set of all signals. |
| 209 | .SH OPTIONS |
| 210 | .TP 12 |
| 211 | .TP |
| 212 | .B \-c |
| 213 | Count time, calls, and errors for each system call and report a |
| 214 | summary on program exit. |
| 215 | .TP |
| 216 | .B \-d |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 217 | Show some debugging output of |
| 218 | .B strace |
| 219 | itself on the standard error. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 220 | .TP |
| 221 | .B \-f |
| 222 | Trace child processes as they are created by currently traced |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 223 | processes as a result of the |
| 224 | .BR fork (2) |
| 225 | system call. The new process is |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 226 | attached to as soon as its pid is known (through the return value of |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 227 | .BR fork (2) |
| 228 | in the parent process). This means that such children may run |
| 229 | uncontrolled for a while (especially in the case of a |
| 230 | .BR vfork (2)), |
| 231 | until the parent is scheduled again to complete its |
| 232 | .RB ( v ) fork (2) |
| 233 | call. |
| 234 | If the parent process decides to |
| 235 | .BR wait (2) |
| 236 | for a child that is currently |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 237 | being traced, it is suspended until an appropriate child process either |
| 238 | terminates or incurs a signal that would cause it to terminate (as |
| 239 | determined from the child's current signal disposition). |
| 240 | .TP |
| 241 | .B \-ff |
| 242 | If the |
| 243 | .B \-o |
| 244 | .I filename |
| 245 | option is in effect, each processes trace is written to |
| 246 | .I filename.pid |
| 247 | where pid is the numeric process id of each process. |
| 248 | .TP |
| 249 | .B \-F |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 250 | Attempt to follow |
| 251 | .BR vfork s. |
| 252 | (On SunOS 4.x, this is accomplished with |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 253 | some dynamic linking trickery. On Linux, it requires some kernel |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 254 | functionality not yet in the standard kernel.) Otherwise, |
| 255 | .BR vfork s |
| 256 | will |
Nate Sammons | ccd8f21 | 1999-03-29 22:57:54 +0000 | [diff] [blame] | 257 | not be followed even if |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 258 | .B \-f |
| 259 | has been given. |
| 260 | .TP |
| 261 | .B \-h |
| 262 | Print the help summary. |
| 263 | .TP |
| 264 | .B \-i |
| 265 | Print the instruction pointer at the time of the system call. |
| 266 | .TP |
| 267 | .B \-q |
| 268 | Suppress messages about attaching, detaching etc. This happens |
| 269 | automatically when output is redirected to a file and the command |
| 270 | is run directly instead of attaching. |
| 271 | .TP |
| 272 | .B \-r |
| 273 | Print a relative timestamp upon entry to each system call. This |
| 274 | records the time difference between the beginning of successive |
| 275 | system calls. |
| 276 | .TP |
| 277 | .B \-t |
| 278 | Prefix each line of the trace with the time of day. |
| 279 | .TP |
| 280 | .B \-tt |
| 281 | If given twice, the time printed will include the microseconds. |
| 282 | .TP |
| 283 | .B \-ttt |
| 284 | If given thrice, the time printed will include the microseconds |
| 285 | and the leading portion will be printed as the number |
| 286 | of seconds since the epoch. |
| 287 | .TP |
| 288 | .B \-T |
| 289 | Show the time spent in system calls. This records the time |
| 290 | difference between the beginning and the end of each system call. |
| 291 | .TP |
| 292 | .B \-v |
| 293 | Print unabbreviated versions of environment, stat, termios, etc. |
| 294 | calls. These structures are very common in calls and so the default |
| 295 | behavior displays a reasonable subset of structure members. Use |
| 296 | this option to get all of the gory details. |
| 297 | .TP |
| 298 | .B \-V |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 299 | Print the version number of |
| 300 | .BR strace . |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | .TP |
| 302 | .B \-x |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 303 | Print all non-ASCII strings in hexadecimal string format. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 304 | .TP |
| 305 | .B \-xx |
| 306 | Print all strings in hexadecimal string format. |
| 307 | .TP |
| 308 | .BI "\-a " column |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 309 | Align return values in a specific column (default column 40). |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 310 | .TP |
| 311 | .BI "\-e " expr |
| 312 | A qualifying expression which modifies which events to trace |
| 313 | or how to trace them. The format of the expression is: |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 314 | .RS 15 |
| 315 | .IP |
| 316 | [\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]... |
| 317 | .RE |
| 318 | .IP |
| 319 | where |
| 320 | .I qualifier |
| 321 | is one of |
| 322 | .BR trace , |
| 323 | .BR abbrev , |
| 324 | .BR verbose , |
| 325 | .BR raw , |
| 326 | .BR signal , |
| 327 | .BR read , |
| 328 | or |
| 329 | .B write |
| 330 | and |
| 331 | .I value |
| 332 | is a qualifier-dependent symbol or number. The default |
| 333 | qualifier is |
| 334 | .BR trace . |
| 335 | Using an exclamation mark negates the set of values. For example, |
| 336 | .B \-eopen |
| 337 | means literally |
| 338 | .B "\-e trace=open" |
| 339 | which in turn means trace only the |
| 340 | .B open |
| 341 | system call. By contrast, |
| 342 | .B "\-etrace=!open" |
| 343 | means to trace every system call except |
| 344 | .BR open . |
| 345 | In addition, the special values |
| 346 | .B all |
| 347 | and |
| 348 | .B none |
| 349 | have the obvious meanings. |
| 350 | .IP |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 351 | Note that some shells use the exclamation point for history |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 352 | expansion even inside quoted arguments. If so, you must escape |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 353 | the exclamation point with a backslash. |
| 354 | .TP |
| 355 | .BI "\-e trace=" set |
| 356 | Trace only the specified set of system calls. The |
| 357 | .B \-c |
| 358 | option is useful for determining which system calls might be useful |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 359 | to trace. For example, |
| 360 | .B trace=open,close,read,write |
| 361 | means to only |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 362 | trace those four system calls. Be careful when making inferences |
| 363 | about the user/kernel boundary if only a subset of system calls |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 364 | are being monitored. The default is |
| 365 | .BR trace=all . |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 366 | .TP |
| 367 | .B "\-e trace=file" |
| 368 | Trace all system calls which take a file name as an argument. You |
| 369 | can think of this as an abbreviation for |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 370 | .BR "\-e\ trace=open,stat,chmod,unlink," ... |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 371 | which is useful to seeing what files the process is referencing. |
| 372 | Furthermore, using the abbreviation will ensure that you don't |
| 373 | accidentally forget to include a call like |
| 374 | .B lstat |
| 375 | in the list. Betchya woulda forgot that one. |
| 376 | .TP |
| 377 | .B "\-e trace=process" |
| 378 | Trace all system calls which involve process management. This |
| 379 | is useful for watching the fork, wait, and exec steps of a process. |
| 380 | .TP |
| 381 | .B "\-e trace=network" |
| 382 | Trace all the network related system calls. |
| 383 | .TP |
| 384 | .B "\-e trace=signal" |
| 385 | Trace all signal related system calls. |
| 386 | .TP |
| 387 | .B "\-e trace=ipc" |
| 388 | Trace all IPC related system calls. |
| 389 | .TP |
| 390 | .BI "\-e abbrev=" set |
| 391 | Abbreviate the output from printing each member of large structures. |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 392 | The default is |
| 393 | .BR abbrev=all . |
| 394 | The |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 395 | .B \-v |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 396 | option has the effect of |
| 397 | .BR abbrev=none . |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 398 | .TP |
| 399 | .BI "\-e verbose=" set |
| 400 | Dereference structures for the specified set of system calls. The |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 401 | default is |
| 402 | .BR verbose=all . |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 403 | .TP |
| 404 | .BI "\-e raw=" set |
| 405 | Print raw, undecoded arguments for the specifed set of system calls. |
| 406 | This option has the effect of causing all arguments to be printed |
| 407 | in hexadecimal. This is mostly useful if you don't trust the |
| 408 | decoding or you need to know the actual numeric value of an |
| 409 | argument. |
| 410 | .TP |
| 411 | .BI "\-e signal=" set |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 412 | Trace only the specified subset of signals. The default is |
| 413 | .BR signal=all . |
| 414 | For example, |
| 415 | .B signal=!SIGIO |
| 416 | (or |
| 417 | .BR signal=!io ) |
| 418 | causes SIGIO signals not to be traced. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 419 | .TP |
| 420 | .BI "\-e read=" set |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 421 | Perform a full hexadecimal and ASCII dump of all the data read from |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 422 | file descriptors listed in the specified set. For example, to see |
| 423 | all input activity on file descriptors 3 and 5 use |
| 424 | .BR "\-e read=3,5" . |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 425 | Note that this is independent from the normal tracing of the |
| 426 | .BR read (2) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 427 | system call which is controlled by the option |
| 428 | .BR "\-e trace=read" . |
| 429 | .TP |
| 430 | .BI "\-e write=" set |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 431 | Perform a full hexadecimal and ASCII dump of all the data written to |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 432 | file descriptors listed in the specified set. For example, to see |
| 433 | all output activity on file descriptors 3 and 5 use |
| 434 | .BR "\-e write=3,5" . |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 435 | Note that this is independent from the normal tracing of the |
| 436 | .BR write (2) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 437 | system call which is controlled by the option |
| 438 | .BR "\-e trace=write" . |
| 439 | .TP |
| 440 | .BI "\-o " filename |
| 441 | Write the trace output to the file |
| 442 | .I filename |
| 443 | rather than to stderr. |
| 444 | Use |
| 445 | .I filename.pid |
| 446 | if |
| 447 | .B \-ff |
| 448 | is used. |
| 449 | If the argument begins with `|' or with `!' then the rest of the |
| 450 | argument is treated as a command and all output is piped to it. |
| 451 | This is convenient for piping the debugging output to a program |
| 452 | without affecting the redirections of executed programs. |
| 453 | .TP |
| 454 | .BI "\-O " overhead |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 455 | Set the overhead for tracing system calls to |
| 456 | .I overhead |
| 457 | microseconds. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 458 | This is useful for overriding the default heuristic for guessing |
| 459 | how much time is spent in mere measuring when timing system calls using |
| 460 | the |
| 461 | .B \-c |
| 462 | option. The acuracy of the heuristic can be gauged by timing a given |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 463 | program run without tracing (using |
| 464 | .BR time (1)) |
| 465 | and comparing the accumulated |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 466 | system call time to the total produced using |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 467 | .BR \-c . |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 468 | .TP |
| 469 | .BI "\-p " pid |
| 470 | Attach to the process with the process |
| 471 | .SM ID |
| 472 | .I pid |
| 473 | and begin tracing. |
| 474 | The trace may be terminated |
| 475 | at any time by a keyboard interrupt signal (\c |
| 476 | .SM CTRL\s0-C). |
| 477 | .B strace |
| 478 | will respond by detaching itself from the traced process(es) |
| 479 | leaving it (them) to continue running. |
| 480 | Multiple |
| 481 | .B \-p |
| 482 | options can be used to attach to up to 32 processes in addition to |
| 483 | .I command |
| 484 | (which is optional if at least one |
| 485 | .B \-p |
| 486 | option is given). |
| 487 | .TP |
| 488 | .BI "\-s " strsize |
| 489 | Specify the maximum string size to print (the default is 32). Note |
| 490 | that filenames are not considered strings and are always printed in |
| 491 | full. |
| 492 | .TP |
| 493 | .BI "\-S " sortby |
| 494 | Sort the output of the histogram printed by the |
| 495 | .B \-c |
| 496 | option by the specified critereon. Legal values are |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 497 | .BR time , |
| 498 | .BR calls , |
| 499 | .BR name , |
| 500 | and |
| 501 | .B nothing |
| 502 | (default |
| 503 | .BR time ). |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 504 | .TP |
| 505 | .BI "\-u " username |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 506 | Run command with the user \s-1ID\s0, group \s-2ID\s0, and |
| 507 | supplementary groups of |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 508 | .IR username . |
| 509 | This option is only useful when running as root and enables the |
| 510 | correct execution of setuid and/or setgid binaries. |
| 511 | Unless this option is used setuid and setgid programs are executed |
| 512 | without effective privileges. |
| 513 | .SH "SETUID INSTALLATION" |
| 514 | If |
| 515 | .B strace |
| 516 | is installed setuid to root then the invoking user will be able to |
| 517 | attach to and trace processes owned by any user. |
| 518 | In addition setuid and setgid programs will be executed and traced |
| 519 | with the correct effective privileges. |
| 520 | Since only users trusted with full root privileges should be allowed |
| 521 | to do these things, |
| 522 | it only makes sense to install |
| 523 | .B strace |
| 524 | as setuid to root when the users who can execute it are restricted |
| 525 | to those users who have this trust. |
| 526 | For example, it makes sense to install a special version of |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 527 | .B strace |
| 528 | with mode `rwsr-xr--', user |
| 529 | .B root |
| 530 | and group |
| 531 | .BR trace , |
| 532 | where members of the |
| 533 | .B trace |
| 534 | group are trusted users. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 535 | If you do use this feature, please remember to install |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 536 | a non-setuid version of |
| 537 | .B strace |
| 538 | for ordinary lusers to use. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 539 | .SH "SEE ALSO" |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 540 | .BR ptrace (2), |
| 541 | .BR proc (4), |
| 542 | .BR time (1), |
| 543 | .BR trace (1), |
| 544 | .BR truss (1) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 545 | .SH NOTES |
| 546 | It is a pity that so much tracing clutter is produced by systems |
| 547 | employing shared libraries. |
| 548 | .LP |
| 549 | It is instructive to think about system call inputs and outputs |
| 550 | as data-flow across the user/kernel boundary. Because user-space |
| 551 | and kernel-space are separate and address-protected, it is |
| 552 | sometimes possible to make deductive inferences about process |
| 553 | behavior using inputs and outputs as propositions. |
| 554 | .LP |
| 555 | In some cases, a system call will differ from the documented behavior |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 556 | or have a different name. For example, on System V-derived systems |
| 557 | the true |
| 558 | .BR time (2) |
| 559 | system call does not take an argument and the |
| 560 | .B stat |
| 561 | function is called |
| 562 | .B xstat |
| 563 | and takes an extra leading argument. These |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 564 | discrepancies are normal but idiosyncratic characteristics of the |
| 565 | system call interface and are accounted for by C library wrapper |
| 566 | functions. |
| 567 | .LP |
| 568 | On some platforms a process that has a system call trace applied |
| 569 | to it with the |
| 570 | .B \-p |
| 571 | option will receive a |
| 572 | .BR \s-1SIGSTOP\s0 . |
| 573 | This signal may interrupt a system call that is not restartable. |
| 574 | This may have an unpredictable effect on the process |
| 575 | if the process takes no action to restart the system call. |
| 576 | .SH BUGS |
| 577 | Programs that use the |
| 578 | .I setuid |
| 579 | bit do not have |
| 580 | effective user |
| 581 | .SM ID |
| 582 | privileges while being traced. |
| 583 | .LP |
| 584 | A traced process ignores |
| 585 | .SM SIGSTOP |
Nate Sammons | b4aa113 | 1999-03-31 05:59:04 +0000 | [diff] [blame] | 586 | except on SVR4 platforms. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 587 | .LP |
| 588 | A traced process which tries to block SIGTRAP will be sent a SIGSTOP |
| 589 | in an attempt to force continuation of tracing. |
| 590 | .LP |
| 591 | A traced process runs slowly. |
| 592 | .LP |
| 593 | Traced processes which are descended from |
| 594 | .I command |
| 595 | may be left running after an interrupt signal (\c |
| 596 | .SM CTRL\s0-C). |
| 597 | .LP |
| 598 | On Linux, exciting as it would be, tracing the init process is forbidden. |
| 599 | .LP |
| 600 | The |
| 601 | .B \-i |
| 602 | option is weakly supported. |
| 603 | .SH HISTORY |
| 604 | .B strace |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 605 | The original |
| 606 | .B strace |
| 607 | was written by Paul Kranenburg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 608 | for SunOS and was inspired by its trace utility. |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 609 | The SunOS version of |
| 610 | .B strace |
| 611 | was ported to Linux and enhanced |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 612 | by Branko Lankester, who also wrote the Linux kernel support. |
Wichert Akkerman | 8829a55 | 1999-06-11 13:18:40 +0000 | [diff] [blame] | 613 | Even though Paul released |
| 614 | .B strace |
| 615 | 2.5 in 1992, |
| 616 | Branko's work was based on Paul's |
| 617 | .B strace |
| 618 | 1.5 release from 1991. |
| 619 | In 1993, Rick Sladkey merged |
| 620 | .B strace |
| 621 | 2.5 for SunOS and the second release of |
| 622 | .B strace |
| 623 | for Linux, added many of the features of |
| 624 | .BR truss (1) |
| 625 | from SVR4, and produced an |
| 626 | .B strace |
| 627 | that worked on both platforms. In 1994 Rick ported |
| 628 | .B strace |
| 629 | to SVR4 and Solaris and wrote the |
| 630 | automatic configuration support. In 1995 he ported |
| 631 | .B strace |
| 632 | to Irix |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 633 | and tired of writing about himself in the third person. |
| 634 | .SH PROBLEMS |
| 635 | Problems with |
| 636 | .B strace |
| 637 | should be reported to the current |
| 638 | .B strace |
Wichert Akkerman | f9d3dcb | 1999-05-15 00:29:13 +0000 | [diff] [blame] | 639 | maintainer, Wichert Akkerman, at <wakkerma@debian.org>. |