xref: /freebsd/usr.bin/ktrace/ktrace.1 (revision 2a657b4ee9008207bd099884c1d4697425a67cd1)
19b50d902SRodney W. Grimes.\" Copyright (c) 1990, 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\"
49b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
59b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
69b50d902SRodney W. Grimes.\" are met:
79b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
89b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
99b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
109b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
119b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
12fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
139b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
149b50d902SRodney W. Grimes.\"    without specific prior written permission.
159b50d902SRodney W. Grimes.\"
169b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
179b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
209b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269b50d902SRodney W. Grimes.\" SUCH DAMAGE.
279b50d902SRodney W. Grimes.\"
28*2a657b4eSJose Luis Duran.Dd November 17, 2024
299b50d902SRodney W. Grimes.Dt KTRACE 1
3062500372SRuslan Ermilov.Os
319b50d902SRodney W. Grimes.Sh NAME
329b50d902SRodney W. Grimes.Nm ktrace
339b50d902SRodney W. Grimes.Nd enable kernel process tracing
349b50d902SRodney W. Grimes.Sh SYNOPSIS
358fe908efSRuslan Ermilov.Nm
369b50d902SRodney W. Grimes.Op Fl aCcdi
379b50d902SRodney W. Grimes.Op Fl f Ar trfile
3824b9685cSMike Heffner.Op Fl g Ar pgrp | Fl p Ar pid
39da647ae9SRuslan Ermilov.Op Fl t Ar trstr
408fe908efSRuslan Ermilov.Nm
419b50d902SRodney W. Grimes.Op Fl adi
429b50d902SRodney W. Grimes.Op Fl f Ar trfile
43da647ae9SRuslan Ermilov.Op Fl t Ar trstr
4433f69855SRuslan Ermilov.Ar command
459b50d902SRodney W. Grimes.Sh DESCRIPTION
4693e0d62dSJohn-Mark GurneyThe
4793e0d62dSJohn-Mark Gurney.Nm
48e8937ba0SPhilippe Charnierutility enables kernel trace logging for the specified processes.
499b50d902SRodney W. GrimesKernel trace data is logged to the file
509b50d902SRodney W. Grimes.Pa ktrace.out .
510277c0c6SEd MasteThe kernel operations that are traced include system calls
520277c0c6SEd Maste.Pq see Xr intro 2 ,
530277c0c6SEd Mastefile system path lookups
540277c0c6SEd Maste.Pq Xr namei 9 ,
550277c0c6SEd Mastesignal processing
560277c0c6SEd Maste.Pq Xr sigaction 2 ,
570277c0c6SEd Masteand
589b50d902SRodney W. Grimes.Tn I/O .
599b50d902SRodney W. Grimes.Pp
609b50d902SRodney W. GrimesOnce tracing is enabled on a process, trace data will be logged until
619b50d902SRodney W. Grimeseither the process exits or the trace point is cleared.
629b50d902SRodney W. GrimesA traced process can generate enormous amounts of log data quickly;
639b50d902SRodney W. GrimesIt is strongly suggested that users memorize how to disable tracing before
649b50d902SRodney W. Grimesattempting to trace a process.
65df449c35STom RhodesThe following command is sufficient to disable tracing on all user-owned
669b50d902SRodney W. Grimesprocesses, and, if executed by root, all processes:
679b50d902SRodney W. Grimes.Pp
6816964daeSPeter Wemm.Dl \&$ ktrace -C
699b50d902SRodney W. Grimes.Pp
709b50d902SRodney W. GrimesThe trace file is not human readable; use
719b50d902SRodney W. Grimes.Xr kdump 1
729b50d902SRodney W. Grimesto decode it.
739b50d902SRodney W. Grimes.Pp
74df449c35STom RhodesThe utility may be used only with a kernel that has been built with the
75df449c35STom Rhodes.Dq KTRACE
76df449c35STom Rhodesoption in the kernel configuration file.
77df449c35STom Rhodes.Pp
78df449c35STom RhodesThe options are:
799b50d902SRodney W. Grimes.Bl -tag -width indent
809b50d902SRodney W. Grimes.It Fl a
819bedbe6cSJoerg WunschAppend to the trace file instead of recreating it.
829b50d902SRodney W. Grimes.It Fl C
83df449c35STom RhodesDisable tracing on all user-owned processes, and, if executed by root, all
849b50d902SRodney W. Grimesprocesses in the system.
859b50d902SRodney W. Grimes.It Fl c
860b976534SJohn BaldwinClear the specified trace points associated with the given file or processes.
879b50d902SRodney W. Grimes.It Fl d
889b50d902SRodney W. GrimesDescendants; perform the operation for all current children of the
899b50d902SRodney W. Grimesdesignated processes.
906e5f5f90SEdward Tomasz NapieralaSee also the
916e5f5f90SEdward Tomasz Napierala.Fl i
926e5f5f90SEdward Tomasz Napieralaoption.
93943c2638SGiorgos Keramidas.It Fl f Ar trfile
949b50d902SRodney W. GrimesLog trace records to
95943c2638SGiorgos Keramidas.Ar trfile
969b50d902SRodney W. Grimesinstead of
979b50d902SRodney W. Grimes.Pa ktrace.out .
989b50d902SRodney W. Grimes.It Fl g Ar pgid
999b50d902SRodney W. GrimesEnable (disable) tracing on all processes in the process group (only one
1009b50d902SRodney W. Grimes.Fl g
1019b50d902SRodney W. Grimesflag is permitted).
1029b50d902SRodney W. Grimes.It Fl i
1039b50d902SRodney W. GrimesInherit; pass the trace flags to all future children of the designated
1049b50d902SRodney W. Grimesprocesses.
1056e5f5f90SEdward Tomasz NapieralaSee also the
1066e5f5f90SEdward Tomasz Napierala.Fl d
1076e5f5f90SEdward Tomasz Napieralaoption.
1089b50d902SRodney W. Grimes.It Fl p Ar pid
1099b50d902SRodney W. GrimesEnable (disable) tracing on the indicated process id (only one
1109b50d902SRodney W. Grimes.Fl p
1119b50d902SRodney W. Grimesflag is permitted).
112da647ae9SRuslan Ermilov.It Fl t Ar trstr
1130b976534SJohn BaldwinSpecify the list of trace points to enable or disable, one per letter.
1140b976534SJohn BaldwinIf an explicit list is not specified, the default set of trace points is used.
1150b976534SJohn Baldwin.Pp
1160b976534SJohn BaldwinThe following trace points are supported:
1179b50d902SRodney W. Grimes.Pp
1189b50d902SRodney W. Grimes.Bl -tag -width flag -compact
1199b50d902SRodney W. Grimes.It Cm c
1209b50d902SRodney W. Grimestrace system calls
12135818d2eSJohn Baldwin.It Cm f
12235818d2eSJohn Baldwintrace page faults
1239b50d902SRodney W. Grimes.It Cm i
1249b50d902SRodney W. Grimestrace
1259b50d902SRodney W. Grimes.Tn I/O
126d4523bd9SJohn Baldwin.It Cm n
1270277c0c6SEd Mastetrace
1280277c0c6SEd Maste.Xr namei 9
1290277c0c6SEd Mastetranslations
130c601ad8eSDag-Erling Smørgrav.It Cm p
131c601ad8eSDag-Erling Smørgravtrace capability check failures
1329b50d902SRodney W. Grimes.It Cm s
1339b50d902SRodney W. Grimestrace signal processing
13460e15db9SDag-Erling Smørgrav.It Cm t
13560e15db9SDag-Erling Smørgravtrace various structures
13609ac2438SPoul-Henning Kamp.It Cm u
13790a7bed4SEdward Tomasz Napieralauserland traces generated by
13890a7bed4SEdward Tomasz Napierala.Xr utrace 2
13909ac2438SPoul-Henning Kamp.It Cm w
14009ac2438SPoul-Henning Kampcontext switches
141a56be37eSJohn Baldwin.It Cm y
142a56be37eSJohn Baldwintrace
143a56be37eSJohn Baldwin.Xr sysctl 3
144a56be37eSJohn Baldwinrequests
14565a4daeaSArtem Hevorhian.It Cm a
14665a4daeaSArtem Hevorhiantrace
14765a4daeaSArtem Hevorhian.Xr execve 2
14865a4daeaSArtem Hevorhianarguments
14965a4daeaSArtem Hevorhian.It Cm e
15065a4daeaSArtem Hevorhiantrace
15165a4daeaSArtem Hevorhian.Xr execve 2
15265a4daeaSArtem Hevorhianenvironment variables
153fef3edecSPeter Pentchev.It Cm +
154fef3edecSPeter Pentchevtrace the default set of trace points -
155*2a657b4eSJose Luis Duran.Cm a, c , e,  i , n , s , t , u , y
1569b50d902SRodney W. Grimes.El
1579b50d902SRodney W. Grimes.It Ar command
1589b50d902SRodney W. GrimesExecute
1599b50d902SRodney W. Grimes.Ar command
1609b50d902SRodney W. Grimeswith the specified trace flags.
1619b50d902SRodney W. Grimes.El
1629b50d902SRodney W. Grimes.Pp
1639b50d902SRodney W. GrimesThe
1649b50d902SRodney W. Grimes.Fl p ,
1659b50d902SRodney W. Grimes.Fl g ,
1669b50d902SRodney W. Grimesand
1679b50d902SRodney W. Grimes.Ar command
1689b50d902SRodney W. Grimesoptions are mutually exclusive.
1694f2ada0dSJake Freeland.Sh CAPABILITY VIOLATION TRACING
1704f2ada0dSJake FreelandWhen the
1714f2ada0dSJake Freeland.Cm p
1724f2ada0dSJake Freelandtrace point is specified,
1734f2ada0dSJake Freeland.Nm
1744f2ada0dSJake Freelandwill record
1754f2ada0dSJake Freeland.Xr capsicum 4
1764f2ada0dSJake Freelandcapability mode violations made by the traced process.
1774f2ada0dSJake FreelandViolations will be logged regardless of whether the process has actually
1784f2ada0dSJake Freelandentered capability mode.
1794f2ada0dSJake Freeland.Pp
1804f2ada0dSJake FreelandFor developers that are interested in Capsicumizing their programs, the
1814f2ada0dSJake Freeland.Cm c , n , p
1824f2ada0dSJake Freelandtrace points can help quickly identify any system calls and path lookups that
1834f2ada0dSJake Freelandare triggering violations.
1849b50d902SRodney W. Grimes.Sh EXAMPLES
1856e5f5f90SEdward Tomasz NapieralaRun "make", then trace it and any child processes:
1866e5f5f90SEdward Tomasz Napierala.Dl $ ktrace -i make
1876e5f5f90SEdward Tomasz Napierala.Pp
188c5ed2864SEdward Tomasz NapieralaTrace all kernel operations of process id 34:
1899b50d902SRodney W. Grimes.Dl $ ktrace -p 34
1909b50d902SRodney W. Grimes.Pp
191c5ed2864SEdward Tomasz NapieralaTrace all kernel operations of processes in process group 15 and
192c5ed2864SEdward Tomasz Napieralapass the trace flags to all current and future children:
1939b50d902SRodney W. Grimes.Dl $ ktrace -idg 15
1949b50d902SRodney W. Grimes.Pp
195c5ed2864SEdward Tomasz NapieralaDisable all tracing of process 65:
1969b50d902SRodney W. Grimes.Dl $ ktrace -cp 65
1979b50d902SRodney W. Grimes.Pp
198c5ed2864SEdward Tomasz NapieralaDisable tracing signals on process 70 and all current children:
1999b50d902SRodney W. Grimes.Dl $ ktrace -t s -cdp 70
2009b50d902SRodney W. Grimes.Pp
201c5ed2864SEdward Tomasz NapieralaEnable tracing of
2029b50d902SRodney W. Grimes.Tn I/O
203c5ed2864SEdward Tomasz Napieralaon process 67:
2049b50d902SRodney W. Grimes.Dl $ ktrace -ti -p 67
2059b50d902SRodney W. Grimes.Pp
206c5ed2864SEdward Tomasz NapieralaDisable all tracing to the file "tracedata":
2079b50d902SRodney W. Grimes.Dl $ ktrace -c -f tracedata
2089b50d902SRodney W. Grimes.Pp
209c5ed2864SEdward Tomasz NapieralaDisable tracing of all user-owned processes:
2109b50d902SRodney W. Grimes.Dl $ ktrace -C
2119b50d902SRodney W. Grimes.Sh SEE ALSO
2126e5f5f90SEdward Tomasz Napierala.Xr dtrace 1 ,
213f4864c27SBrooks Davis.Xr kdump 1 ,
2146e5f5f90SEdward Tomasz Napierala.Xr truss 1 ,
2150277c0c6SEd Maste.Xr intro 2 ,
21690a7bed4SEdward Tomasz Napierala.Xr ktrace 2 ,
2170277c0c6SEd Maste.Xr sigaction 2 ,
2184f2ada0dSJake Freeland.Xr utrace 2 ,
219a87651e2SEd Maste.Xr capsicum 4 ,
220a87651e2SEd Maste.Xr namei 9
2219b50d902SRodney W. Grimes.Sh HISTORY
2229b50d902SRodney W. GrimesThe
22393e0d62dSJohn-Mark Gurney.Nm
22493e0d62dSJohn-Mark Gurneycommand appeared in
2259b50d902SRodney W. Grimes.Bx 4.4 .
2266c7216dfSRuslan Ermilov.Sh BUGS
2276c7216dfSRuslan ErmilovOnly works if
2286c7216dfSRuslan Ermilov.Ar trfile
2296c7216dfSRuslan Ermilovis a regular file.
230