xref: /netbsd-src/lib/libc/sys/ktrace.2 (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1.\"	$NetBSD: ktrace.2,v 1.2 1995/02/27 12:33:58 cgd Exp $
2.\"
3.\" Copyright (c) 1993
4.\"	The Regents of the University of California.  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. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)ktrace.2	8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt KTRACE 2
38.Os BSD 4
39.Sh NAME
40.Nm ktrace
41.Nd process tracing
42.Sh SYNOPSIS
43.Fd #include <sys/types.h>
44.Fd #include <sys/ktrace.h>
45.Ft int
46.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
47.Sh DESCRIPTION
48The
49.Fn ktrace
50function enables or disables tracing of one or more processes.
51Users may only trace their own processes.
52Only the super-user can trace setuid or setgid programs.
53.Pp
54The
55.Ar tracefile
56gives the pathname of the file to be used for tracing.
57The file must exist and be writable by the calling process.
58All trace records are always appended to the file,
59so the file must be truncated to zero length to discard
60previous trace data.
61If tracing points are being disabled (see KTROP_CLEAR below),
62.Ar tracefile
63may be NULL.
64.Pp
65The
66.Nm ops
67parameter specifies the requested ktrace operation.
68The defined operations are:
69.Bl -column KTRFLAG_DESCENDXXX -offset indent
70.It KTROP_SET	Enable trace points specified in Ar trpoints .
71.It KTROP_CLEAR	Disable trace points specified in Ar trpoints .
72.It KTROP_CLEARFILE	Stop all tracing.
73.It KTRFLAG_DESCEND	The tracing change should apply to the
74specified process and all its current children.
75.El
76.Pp
77The
78.Nm trpoints
79parameter specifies the trace points of interest.
80The defined trace points are:
81.Bl -column KTRFAC_SYSCALLXXX -offset indent
82.It KTRFAC_SYSCALL	Trace system calls.
83.It KTRFAC_SYSRET	Trace return values from system calls.
84.It KTRFAC_NAMEI	Trace name lookup operations.
85.It KTRFAC_GENIO	Trace all I/O (note that this option can
86generate much output).
87.It KTRFAC_PSIG	Trace posted signals.
88.It KTRFAC_CSW	Trace context switch points.
89.It KTRFAC_INHERIT	Inherit tracing to future children.
90.El
91.Pp
92Each tracing event outputs a record composed of a generic header
93followed by a trace point specific structure.
94The generic header is:
95.Bd -literal
96struct ktr_header {
97	int	ktr_len;		/* length of buf */
98	short	ktr_type;		/* trace record type */
99	pid_t	ktr_pid;		/* process id */
100	char	ktr_comm[MAXCOMLEN+1];	/* command name */
101	struct	timeval ktr_time;	/* timestamp */
102	caddr_t	ktr_buf;
103};
104.Ed
105.Pp
106The
107.Nm ktr_len
108field specifies the length of the
109.Nm ktr_type
110data that follows this header.
111The
112.Nm ktr_pid
113and
114.Nm ktr_comm
115fields specify the process and command generating the record.
116The
117.Nm ktr_time
118field gives the time (with microsecond resolution)
119that the record was generated.
120The
121.Nm ktr_buf
122is an internal kernel pointer and is not useful.
123.Pp
124The generic header is followed by
125.Nm ktr_len
126bytes of a
127.Nm ktr_type
128record.
129The type specific records are defined in the
130.Pa <sys/ktrace.h>
131include file.
132.Sh RETURN VALUES
133On successful completion a value of 0 is returned.
134Otherwise, a value of -1 is returned and
135.Va errno
136is set to show the error.
137.Sh ERRORS
138.Fn Ktrace
139will fail if:
140.Bl -tag -width ENAMETOOLONGAA
141.It Bq Er ENOTDIR
142A component of the path prefix is not a directory.
143.It Bq Er EINVAL
144The pathname contains a character with the high-order bit set.
145.It Bq Er ENAMETOOLONG
146A component of a pathname exceeded 255 characters,
147or an entire path name exceeded 1023 characters.
148.It Bq Er ENOENT
149The named tracefile does not exist.
150.It Bq Er EACCES
151Search permission is denied for a component of the path prefix.
152.It Bq Er ELOOP
153Too many symbolic links were encountered in translating the pathname.
154.It Bq Er EIO
155An I/O error occurred while reading from or writing to the file system.
156.El
157.Sh SEE ALSO
158.Xr ktrace 1 ,
159.Xr kdump 1
160.Sh HISTORY
161A
162.Nm ktrace
163function call first appeared in
164.Bx 4.4 .
165