1*8269e767SBrooks Davis.\" Copyright (c) 1993 2*8269e767SBrooks Davis.\" The Regents of the University of California. All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors 13*8269e767SBrooks Davis.\" may be used to endorse or promote products derived from this software 14*8269e767SBrooks Davis.\" without specific prior written permission. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd November 2, 2022 29*8269e767SBrooks Davis.Dt KTRACE 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm ktrace 33*8269e767SBrooks Davis.Nd process tracing 34*8269e767SBrooks Davis.Sh LIBRARY 35*8269e767SBrooks Davis.Lb libc 36*8269e767SBrooks Davis.Sh SYNOPSIS 37*8269e767SBrooks Davis.In sys/param.h 38*8269e767SBrooks Davis.In sys/time.h 39*8269e767SBrooks Davis.In sys/uio.h 40*8269e767SBrooks Davis.In sys/ktrace.h 41*8269e767SBrooks Davis.Ft int 42*8269e767SBrooks Davis.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid" 43*8269e767SBrooks Davis.Sh DESCRIPTION 44*8269e767SBrooks DavisThe 45*8269e767SBrooks Davis.Fn ktrace 46*8269e767SBrooks Davissystem call enables or disables tracing of one or more processes. 47*8269e767SBrooks DavisUsers may only trace their own processes. 48*8269e767SBrooks DavisOnly the super-user can trace setuid or setgid programs. 49*8269e767SBrooks Davis.Pp 50*8269e767SBrooks DavisThe 51*8269e767SBrooks Davis.Fa tracefile 52*8269e767SBrooks Davisargument 53*8269e767SBrooks Davisgives the pathname of the file to be used for tracing. 54*8269e767SBrooks DavisThe file must exist and be a regular file writable by the calling process. 55*8269e767SBrooks DavisAll trace records are always appended to the file, 56*8269e767SBrooks Davisso the file must be truncated to zero length to discard 57*8269e767SBrooks Davisprevious trace data. 58*8269e767SBrooks DavisIf tracing points are being disabled (see KTROP_CLEAR below), 59*8269e767SBrooks Davis.Fa tracefile 60*8269e767SBrooks Davismay be NULL. 61*8269e767SBrooks Davis.Pp 62*8269e767SBrooks DavisThe 63*8269e767SBrooks Davis.Fa ops 64*8269e767SBrooks Davisargument specifies the requested ktrace operation. 65*8269e767SBrooks DavisThe defined operations are: 66*8269e767SBrooks Davis.Bl -column KTRFLAG_DESCENDXXX -offset indent 67*8269e767SBrooks Davis.It KTROP_SET Ta "Enable trace points specified in" 68*8269e767SBrooks Davis.Fa trpoints . 69*8269e767SBrooks Davis.It KTROP_CLEAR Ta "Disable trace points specified in" 70*8269e767SBrooks Davis.Fa trpoints . 71*8269e767SBrooks Davis.It KTROP_CLEARFILE Ta "Stop all tracing." 72*8269e767SBrooks Davis.It KTRFLAG_DESCEND Ta "The tracing change should apply to the" 73*8269e767SBrooks Davisspecified process and all its current children. 74*8269e767SBrooks Davis.El 75*8269e767SBrooks Davis.Pp 76*8269e767SBrooks DavisThe 77*8269e767SBrooks Davis.Fa trpoints 78*8269e767SBrooks Davisargument specifies the trace points of interest. 79*8269e767SBrooks DavisThe defined trace points are: 80*8269e767SBrooks Davis.Bl -column KTRFAC_PROCCTORXXX -offset indent 81*8269e767SBrooks Davis.It KTRFAC_SYSCALL Ta "Trace system calls." 82*8269e767SBrooks Davis.It KTRFAC_SYSRET Ta "Trace return values from system calls." 83*8269e767SBrooks Davis.It KTRFAC_NAMEI Ta "Trace name lookup operations." 84*8269e767SBrooks Davis.It KTRFAC_GENIO Ta "Trace all I/O (note that this option can" 85*8269e767SBrooks Davisgenerate much output). 86*8269e767SBrooks Davis.It KTRFAC_PSIG Ta "Trace posted signals." 87*8269e767SBrooks Davis.It KTRFAC_CSW Ta "Trace context switch points." 88*8269e767SBrooks Davis.It KTRFAC_USER Ta "Trace application-specific events." 89*8269e767SBrooks Davis.It KTRFAC_STRUCT Ta "Trace certain data structures." 90*8269e767SBrooks Davis.It KTRFAC_SYSCTL Ta "Trace sysctls." 91*8269e767SBrooks Davis.It KTRFAC_PROCCTOR Ta "Trace process construction." 92*8269e767SBrooks Davis.It KTRFAC_PROCDTOR Ta "Trace process destruction." 93*8269e767SBrooks Davis.It KTRFAC_CAPFAIL Ta "Trace capability failures." 94*8269e767SBrooks Davis.It KTRFAC_FAULT Ta "Trace page faults." 95*8269e767SBrooks Davis.It KTRFAC_FAULTEND Ta "Trace the end of page faults." 96*8269e767SBrooks Davis.It KTRFAC_STRUCT_ARRAY Ta "Trace arrays of certain data structures." 97*8269e767SBrooks Davis.It KTRFAC_INHERIT Ta "Inherit tracing to future children." 98*8269e767SBrooks Davis.El 99*8269e767SBrooks Davis.Pp 100*8269e767SBrooks DavisEach tracing event outputs a record composed of a generic header 101*8269e767SBrooks Davisfollowed by a trace point specific structure. 102*8269e767SBrooks DavisThe generic header is: 103*8269e767SBrooks Davis.Bd -literal 104*8269e767SBrooks Davisstruct ktr_header { 105*8269e767SBrooks Davis int ktr_len; /* length of buf */ 106*8269e767SBrooks Davis short ktr_type; /* trace record type */ 107*8269e767SBrooks Davis pid_t ktr_pid; /* process id */ 108*8269e767SBrooks Davis char ktr_comm[MAXCOMLEN+1]; /* command name */ 109*8269e767SBrooks Davis struct timeval ktr_time; /* timestamp */ 110*8269e767SBrooks Davis long ktr_tid; /* thread id */ 111*8269e767SBrooks Davis}; 112*8269e767SBrooks Davis.Ed 113*8269e767SBrooks Davis.Pp 114*8269e767SBrooks DavisThe 115*8269e767SBrooks Davis.Va ktr_len 116*8269e767SBrooks Davisfield specifies the length of the 117*8269e767SBrooks Davis.Va ktr_type 118*8269e767SBrooks Davisdata that follows this header. 119*8269e767SBrooks DavisThe 120*8269e767SBrooks Davis.Va ktr_pid 121*8269e767SBrooks Davisand 122*8269e767SBrooks Davis.Va ktr_comm 123*8269e767SBrooks Davisfields specify the process and command generating the record. 124*8269e767SBrooks DavisThe 125*8269e767SBrooks Davis.Va ktr_time 126*8269e767SBrooks Davisfield gives the time (with microsecond resolution) 127*8269e767SBrooks Davisthat the record was generated. 128*8269e767SBrooks DavisThe 129*8269e767SBrooks Davis.Va ktr_tid 130*8269e767SBrooks Davisfield holds a thread id. 131*8269e767SBrooks Davis.Pp 132*8269e767SBrooks DavisThe generic header is followed by 133*8269e767SBrooks Davis.Va ktr_len 134*8269e767SBrooks Davisbytes of a 135*8269e767SBrooks Davis.Va ktr_type 136*8269e767SBrooks Davisrecord. 137*8269e767SBrooks DavisThe type specific records are defined in the 138*8269e767SBrooks Davis.In sys/ktrace.h 139*8269e767SBrooks Davisinclude file. 140*8269e767SBrooks Davis.Sh SYSCTL TUNABLES 141*8269e767SBrooks DavisThe following 142*8269e767SBrooks Davis.Xr sysctl 8 143*8269e767SBrooks Davistunables influence the behaviour of 144*8269e767SBrooks Davis.Fn ktrace : 145*8269e767SBrooks Davis.Bl -tag -width indent 146*8269e767SBrooks Davis.It Va kern.ktrace.genio_size 147*8269e767SBrooks Davisbounds the amount of data a traced I/O request will log 148*8269e767SBrooks Davisto the trace file. 149*8269e767SBrooks Davis.It Va kern.ktrace.request_pool 150*8269e767SBrooks Davisbounds the number of trace events being logged at a time. 151*8269e767SBrooks Davis.El 152*8269e767SBrooks Davis.Pp 153*8269e767SBrooks DavisSysctl tunables that control process debuggability (as determined by 154*8269e767SBrooks Davis.Xr p_candebug 9 ) 155*8269e767SBrooks Davisalso affect the operation of 156*8269e767SBrooks Davis.Fn ktrace . 157*8269e767SBrooks Davis.Sh RETURN VALUES 158*8269e767SBrooks Davis.Rv -std ktrace 159*8269e767SBrooks Davis.Sh ERRORS 160*8269e767SBrooks DavisThe 161*8269e767SBrooks Davis.Fn ktrace 162*8269e767SBrooks Davissystem call 163*8269e767SBrooks Daviswill fail if: 164*8269e767SBrooks Davis.Bl -tag -width Er 165*8269e767SBrooks Davis.It Bq Er ENOTDIR 166*8269e767SBrooks DavisA component of the path prefix is not a directory. 167*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG 168*8269e767SBrooks DavisA component of a pathname exceeded 255 characters, 169*8269e767SBrooks Davisor an entire path name exceeded 1023 characters. 170*8269e767SBrooks Davis.It Bq Er ENOENT 171*8269e767SBrooks DavisThe named tracefile does not exist. 172*8269e767SBrooks Davis.It Bq Er EACCES 173*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix. 174*8269e767SBrooks Davis.It Bq Er ELOOP 175*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname. 176*8269e767SBrooks Davis.It Bq Er EIO 177*8269e767SBrooks DavisAn I/O error occurred while reading from or writing to the file system. 178*8269e767SBrooks Davis.It Bq Er EINTEGRITY 179*8269e767SBrooks DavisCorrupted data was detected while reading from the file system. 180*8269e767SBrooks Davis.It Bq Er ENOSYS 181*8269e767SBrooks DavisThe kernel was not compiled with 182*8269e767SBrooks Davis.Nm 183*8269e767SBrooks Davissupport. 184*8269e767SBrooks Davis.El 185*8269e767SBrooks Davis.Pp 186*8269e767SBrooks DavisA thread may be unable to log one or more tracing events due to a 187*8269e767SBrooks Davistemporary shortage of resources. 188*8269e767SBrooks DavisThis condition is remembered by the kernel, and the next tracing request 189*8269e767SBrooks Davisthat succeeds will have the flag 190*8269e767SBrooks Davis.Li KTR_DROP 191*8269e767SBrooks Davisset in its 192*8269e767SBrooks Davis.Va ktr_type 193*8269e767SBrooks Davisfield. 194*8269e767SBrooks Davis.Sh SEE ALSO 195*8269e767SBrooks Davis.Xr kdump 1 , 196*8269e767SBrooks Davis.Xr ktrace 1 , 197*8269e767SBrooks Davis.Xr utrace 2 , 198*8269e767SBrooks Davis.Xr sysctl 8 , 199*8269e767SBrooks Davis.Xr p_candebug 9 200*8269e767SBrooks Davis.Sh HISTORY 201*8269e767SBrooks DavisThe 202*8269e767SBrooks Davis.Fn ktrace 203*8269e767SBrooks Davissystem call first appeared in 204*8269e767SBrooks Davis.Bx 4.4 . 205