📄 strace.1
字号:
.\" Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>.\" Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>.\" Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>.\" All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. The name of the author may not be used to endorse or promote products.\" derived from this software without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED..\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..\".\" $Id: strace.1,v 1.7 1999/12/23 14:20:15 wichert Exp $.\".de CW.sp.nf.ft CW...de CE.ft R.fi.sp...TH STRACE 1 "99/06/11".SH NAMEstrace \- trace system calls and signals.SH SYNOPSIS.B strace[.B \-dffhiqrtttTvxx][.BI \-a column][.BI \-e expr]\&...[.BI \-o file][.BI \-p pid]\&...[.BI \-s strsize][.BI \-u username][.I command[.I arg\&...]].sp.B strace.B \-c[.BI \-e expr]\&...[.BI \-O overhead][.BI \-S sortby][.I command[.I arg\&...]].SH DESCRIPTION.IX "strace command" "" "\fLstrace\fR command".LPIn the simplest case.B straceruns the specified.I commanduntil it exits.It intercepts and records the system calls which are calledby a process and the signals which are received by a process.The name of each system call, its arguments and its return valueare printed on standard error or to the file specified with the.B \-ooption..LP.B straceis a useful diagnostic, instructional, and debugging tool.System adminstrators, diagnosticians and trouble-shooters will findit invaluable for solving problems withprograms for which the source is not readily available sincethey do not need to be recompiled in order to trace them.Students, hackers and the overly-curious will find thata great deal can be learned about a system and its system calls bytracing even ordinary programs. And programmers will find thatsince system calls and signals are events that happen at the user/kernelinterface, a close examination of this boundary is veryuseful for bug isolation, sanity checking andattempting to capture race conditions..LPEach line in the trace contains the system call name, followedby its arguments in parentheses and its return value.An example from stracing the command ``cat /dev/null'' is:.CWopen("/dev/null", O_RDONLY) = 3.CEErrors (typically a return value of \-1) have the errno symboland error string appended..CWopen("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory).CESignals are printed as a signal symbol and a signal string.An excerpt from stracing and interrupting the command ``sleep 666'' is:.CWsigsuspend([] <unfinished ...>--- SIGINT (Interrupt) ---+++ killed by SIGINT +++.CEArguments are printed in symbolic form with a passion.This example shows the shell peforming ``>>xyzzy'' output redirection:.CWopen("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3.CEHere the three argument form of open is decoded by breaking down theflag argument into its three bitwise-OR constituents and printing themode value in octal by tradition. Where traditional or nativeusage differs from ANSI or POSIX, the latter forms are preferred.In some cases,.B straceoutput has proven to be more readable than the source..LPStructure pointers are dereferenced and the members are displayedas appropriate. In all cases arguments are formatted in the most C-likefashion possible.For example, the essence of the command ``ls \-l /dev/null'' is captured as:.CWlstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0.CENotice how the `struct stat' argument is dereferenced and how each member isdisplayed symbolically. In particular, observe how the st_mode memberis carefully decoded into a bitwise-OR of symbolic and numeric values.Also notice in this example that the first argument to lstat is an inputto the system call and the second argument is an output. Since outputarguments are not modified if the system call fails, arguments may notalways be dereferenced. For example, retrying the ``ls \-l'' examplewith a non-existent file produces the following line:.CWlstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory).CEIn this case the porch light is on but nobody is home..LPCharacter pointers are dereferenced and printed as C strings.Non-printing characters in strings are normally represented byordinary C escape codes.Only the first.I strsize(32 by default) bytes of strings are printed;longer strings have an ellipsis appended following the closing quote.Here is a line from ``ls \-l'' where the.B getpwuidlibrary routine is reading the password file:.CWread(3, "root::0:0:System Administrator:/"..., 1024) = 422.CEWhile structures are annotated using curly braces, simple pointersand arrays are printed using square brackets with commas separatingelements. Here is an example from the command ``id'' on a system withsupplementary group ids:.CWgetgroups(32, [100, 0]) = 2.CEOn the other hand, bit-sets are also shown using square bracketsbut set elements are separated only by a space. Here is the shellpreparing to execute an external command:.CWsigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0.CEHere the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.In some cases the bit-set is so full that printing out the unsetelements is more valuable. In that case, the bit-set is prefixed bya tilde like this:.CWsigprocmask(SIG_UNBLOCK, ~[], NULL) = 0.CEHere the second argument represents the full set of all signals..SH OPTIONS.TP 12.TP.B \-cCount time, calls, and errors for each system call and report asummary on program exit..TP.B \-dShow some debugging output of.B straceitself on the standard error..TP.B \-fTrace child processes as they are created by currently tracedprocesses as a result of the.BR fork (2)system call. The new process isattached to as soon as its pid is known (through the return value of.BR fork (2)in the parent process). This means that such children may rununcontrolled for a while (especially in the case of a.BR vfork (2)),until the parent is scheduled again to complete its.RB ( v ) fork (2)call.If the parent process decides to.BR wait (2)for a child that is currentlybeing traced, it is suspended until an appropriate child process eitherterminates or incurs a signal that would cause it to terminate (asdetermined from the child's current signal disposition)..TP.B \-ffIf the.B \-o.I filenameoption is in effect, each processes trace is written to.I filename.pidwhere pid is the numeric process id of each process..TP.B \-FAttempt to follow.BR vfork s.(On SunOS 4.x, this is accomplished withsome dynamic linking trickery. On Linux, it requires some kernelfunctionality not yet in the standard kernel.) Otherwise,.BR vfork swillnot be followed even if.B \-fhas been given..TP.B \-hPrint the help summary..TP.B \-iPrint the instruction pointer at the time of the system call..TP.B \-qSuppress messages about attaching, detaching etc. This happensautomatically when output is redirected to a file and the commandis run directly instead of attaching..TP.B \-rPrint a relative timestamp upon entry to each system call. Thisrecords the time difference between the beginning of successivesystem calls..TP.B \-tPrefix each line of the trace with the time of day..TP.B \-ttIf given twice, the time printed will include the microseconds..TP.B \-tttIf given thrice, the time printed will include the microsecondsand the leading portion will be printed as the numberof seconds since the epoch..TP.B \-TShow the time spent in system calls. This records the timedifference between the beginning and the end of each system call..TP.B \-vPrint unabbreviated versions of environment, stat, termios, etc.calls. These structures are very common in calls and so the defaultbehavior displays a reasonable subset of structure members. Usethis option to get all of the gory details..TP.B \-VPrint the version number of.BR strace ..TP.B \-xPrint all non-ASCII strings in hexadecimal string format..TP.B \-xxPrint all strings in hexadecimal string format..TP.BI "\-a " columnAlign return values in a specific column (default column 40)..TP.BI "\-e " exprA qualifying expression which modifies which events to traceor how to trace them. The format of the expression is:.RS 15.IP[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]....RE.IPwhere.I qualifier
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -