xref: /freebsd/share/man/man4/gdb.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1a9215590SGreg Lehey.\" Copyright (c) 2003 Greg Lehey
2a9215590SGreg Lehey.\" All rights reserved.
3a9215590SGreg Lehey.\"
4a9215590SGreg Lehey.\" Redistribution and use in source and binary forms, with or without
5a9215590SGreg Lehey.\" modification, are permitted provided that the following conditions
6a9215590SGreg Lehey.\" are met:
7a9215590SGreg Lehey.\" 1. Redistributions of source code must retain the above copyright
8a9215590SGreg Lehey.\"    notice, this list of conditions and the following disclaimer.
9a9215590SGreg Lehey.\" 2. Redistributions in binary form must reproduce the above copyright
10a9215590SGreg Lehey.\"    notice, this list of conditions and the following disclaimer in the
11a9215590SGreg Lehey.\"    documentation and/or other materials provided with the distribution.
12a9215590SGreg Lehey.\"
13a9215590SGreg Lehey.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14a9215590SGreg Lehey.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15a9215590SGreg Lehey.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16a9215590SGreg Lehey.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17a9215590SGreg Lehey.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18a9215590SGreg Lehey.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19a9215590SGreg Lehey.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20a9215590SGreg Lehey.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21a9215590SGreg Lehey.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22a9215590SGreg Lehey.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23a9215590SGreg Lehey.\" SUCH DAMAGE.
24a9215590SGreg Lehey.\"
25c42a9b6aSGlen Barber.Dd May 17, 2016
261159af41SGreg Lehey.Dt GDB 4
271159af41SGreg Lehey.Os
281159af41SGreg Lehey.Sh NAME
291159af41SGreg Lehey.Nm gdb
301159af41SGreg Lehey.Nd external kernel debugger
311159af41SGreg Lehey.Sh SYNOPSIS
32a9215590SGreg Lehey.Cd "makeoptions DEBUG=-g"
33a9215590SGreg Lehey.Cd "options DDB"
341159af41SGreg Lehey.Sh DESCRIPTION
351159af41SGreg LeheyThe
361159af41SGreg Lehey.Nm
371159af41SGreg Leheykernel debugger is a variation of
38*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
391159af41SGreg Leheywhich understands some aspects of the
401159af41SGreg Lehey.Fx
41a9215590SGreg Leheykernel environment.
42a9215590SGreg LeheyIt can be used in a number of ways:
43a9215590SGreg Lehey.Bl -bullet
441159af41SGreg Lehey.It
458da02496SGreg LeheyIt can be used to examine the memory of the processor on which it runs.
468da02496SGreg Lehey.It
478da02496SGreg LeheyIt can be used to analyse a processor dump after a panic.
488da02496SGreg Lehey.It
491159af41SGreg LeheyIt can be used to debug another system interactively via a serial or firewire
50a9215590SGreg Leheylink.
51a9215590SGreg LeheyIn this mode, the processor can be stopped and single stepped.
521159af41SGreg Lehey.It
538da02496SGreg LeheyWith a firewire link, it can be used to examine the memory of a remote system
548da02496SGreg Leheywithout the participation of that system.
558da02496SGreg LeheyIn this mode, the processor cannot be stopped and single stepped, but it can be
568da02496SGreg Leheyof use when the remote system has crashed and is no longer responding.
571159af41SGreg Lehey.El
581159af41SGreg Lehey.Pp
591159af41SGreg LeheyWhen used for remote debugging,
601159af41SGreg Lehey.Nm
611159af41SGreg Leheyrequires the presence of the
621159af41SGreg Lehey.Xr ddb 4
631159af41SGreg Leheykernel debugger.
641159af41SGreg LeheyCommands exist to switch between
651159af41SGreg Lehey.Nm
661159af41SGreg Leheyand
671159af41SGreg Lehey.Xr ddb 4 .
681159af41SGreg Lehey.Sh PREPARING FOR DEBUGGING
691159af41SGreg LeheyWhen debugging kernels, it is practically essential to have built a kernel with
701159af41SGreg Leheydebugging symbols
71a9215590SGreg Lehey.Pq Cd "makeoptions DEBUG=-g" .
72a9215590SGreg LeheyIt is easiest to perform operations from the kernel build directory, by default
73a9215590SGreg Lehey.Pa /usr/obj/usr/src/sys/GENERIC .
741159af41SGreg Lehey.Pp
751159af41SGreg LeheyFirst, ensure you have a copy of the debug macros in the directory:
76a9215590SGreg Lehey.Pp
77a9215590SGreg Lehey.Dl "make gdbinit"
781159af41SGreg Lehey.Pp
791159af41SGreg LeheyThis command performs some transformations on the macros installed in
801159af41SGreg Lehey.Pa /usr/src/tools/debugscripts
811159af41SGreg Leheyto adapt them to the local environment.
828da02496SGreg Lehey.Ss "Inspecting the environment of the local machine"
83a9215590SGreg LeheyTo look at and change the contents of the memory of the system you are running
841159af41SGreg Leheyon,
85a9215590SGreg Lehey.Pp
86a9215590SGreg Lehey.Dl "gdb -k -wcore kernel.debug /dev/mem"
871159af41SGreg Lehey.Pp
881159af41SGreg LeheyIn this mode, you need the
891159af41SGreg Lehey.Fl k
901159af41SGreg Leheyflag to indicate to
91*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
92a9215590SGreg Leheythat the
93a9215590SGreg Lehey.Dq "dump file"
941159af41SGreg Lehey.Pa /dev/mem
951159af41SGreg Leheyis a kernel data file.
961159af41SGreg LeheyYou can look at live data, and if you include the
971159af41SGreg Lehey.Fl wcore
981159af41SGreg Leheyoption, you can change it at your peril.
991159af41SGreg LeheyThe system does not stop (obviously), so a number of things will not work.
100a9215590SGreg LeheyYou can set breakpoints, but you cannot
101a9215590SGreg Lehey.Dq continue
102a9215590SGreg Leheyexecution, so they will not work.
1038da02496SGreg Lehey.Ss "Debugging a crash dump"
1048cfbf24fSGreg LeheyBy default, crash dumps are stored in the directory
1051159af41SGreg Lehey.Pa /var/crash .
1061159af41SGreg LeheyInvestigate them from the kernel build directory with:
107a9215590SGreg Lehey.Pp
108a9215590SGreg Lehey.Dl "gdb -k kernel.debug /var/crash/vmcore.29"
1091159af41SGreg Lehey.Pp
1101159af41SGreg LeheyIn this mode, the system is obviously stopped, so you can only look at it.
1118da02496SGreg Lehey.Ss "Debugging a live system with a remote link"
112a9215590SGreg LeheyIn the following discussion, the term
113a9215590SGreg Lehey.Dq "local system"
114a9215590SGreg Leheyrefers to the system running the debugger, and
115a9215590SGreg Lehey.Dq "remote system"
116a9215590SGreg Leheyrefers to the live system being debugged.
117783a364bSGreg Lehey.Pp
1181159af41SGreg LeheyTo debug a live system with a remote link, the kernel must be compiled with the
119783a364bSGreg Leheyoption
120a9215590SGreg Lehey.Cd "options DDB" .
1211159af41SGreg LeheyThe option
122a9215590SGreg Lehey.Cd "options BREAK_TO_DEBUGGER"
1231159af41SGreg Leheyenables the debugging machine stop the debugged machine once a connection has
1241159af41SGreg Leheybeen established by pressing
125a9215590SGreg Lehey.Ql ^C .
1268da02496SGreg Lehey.Ss "Debugging a live system with a remote serial link"
127a9215590SGreg LeheyWhen using a serial port for the remote link on the i386 platform, the serial
1281159af41SGreg Leheyport must be identified by setting the flag bit
1291159af41SGreg Lehey.Li 0x80
1301159af41SGreg Leheyfor the specified interface.
131a9215590SGreg LeheyGenerally, this port will also be used as a serial console (flag bit
132a9215590SGreg Lehey.Li 0x10 ) ,
1331159af41SGreg Leheyso the entry in
1341159af41SGreg Lehey.Pa /boot/device.hints
1351159af41SGreg Leheyshould be:
136a9215590SGreg Lehey.Pp
137a9215590SGreg Lehey.Dl hint.sio.0.flags="0x90"
1388da02496SGreg Lehey.Ss "Debugging a live system with a remote firewire link"
1391159af41SGreg LeheyAs with serial debugging, to debug a live system with a firewire link, the
140783a364bSGreg Leheykernel must be compiled with the option
141a9215590SGreg Lehey.Cd "options DDB" .
1421159af41SGreg Lehey.Pp
1431159af41SGreg LeheyA number of steps must be performed to set up a firewire link:
144a9215590SGreg Lehey.Bl -bullet
1451159af41SGreg Lehey.It
146a9215590SGreg LeheyEnsure that both systems have
147a9215590SGreg Lehey.Xr firewire 4
148a9215590SGreg Leheysupport, and that the kernel of the remote system includes the
149a9215590SGreg Lehey.Xr dcons 4
150783a364bSGreg Leheyand
151a9215590SGreg Lehey.Xr dcons_crom 4
152783a364bSGreg Leheydrivers.
153a9215590SGreg LeheyIf they are not compiled into the kernel, load the KLDs:
154a9215590SGreg Lehey.Pp
155a9215590SGreg Lehey.Dl "kldload firewire"
156a9215590SGreg Lehey.Pp
157a9215590SGreg LeheyOn the remote system only:
158a9215590SGreg Lehey.Bd -literal -offset indent
159a9215590SGreg Leheykldload dcons
160a9215590SGreg Leheykldload dcons_crom
1611159af41SGreg Lehey.Ed
1621159af41SGreg Lehey.Pp
1631159af41SGreg LeheyYou should see something like this in the
164a9215590SGreg Lehey.Xr dmesg 8
165783a364bSGreg Leheyoutput of the remote system:
166a9215590SGreg Lehey.Bd -literal -offset indent
1671159af41SGreg Leheyfwohci0: BUS reset
1681159af41SGreg Leheyfwohci0: node_id=0x8800ffc0, gen=2, non CYCLEMASTER mode
1691159af41SGreg Leheyfirewire0: 2 nodes, maxhop <= 1, cable IRM = 1
1701159af41SGreg Leheyfirewire0: bus manager 1
1711159af41SGreg Leheyfirewire0: New S400 device ID:00c04f3226e88061
1721159af41SGreg Leheydcons_crom0: <dcons configuration ROM> on firewire0
1731159af41SGreg Leheydcons_crom0: bus_addr 0x22a000
1741159af41SGreg Lehey.Ed
1751159af41SGreg Lehey.Pp
176a9215590SGreg LeheyIt is a good idea to load these modules at boot time with the following entry in
1771159af41SGreg Lehey.Pa /boot/loader.conf :
1781159af41SGreg Lehey.Pp
179a9215590SGreg Lehey.Dl dcons_crom_enable="YES"
1801159af41SGreg Lehey.Pp
181783a364bSGreg LeheyThis ensures that all three modules are loaded.
182783a364bSGreg LeheyThere is no harm in loading
183a9215590SGreg Lehey.Xr dcons 4
184783a364bSGreg Leheyand
185a9215590SGreg Lehey.Xr dcons_crom 4
186a9215590SGreg Leheyon the local system, but if you only want to load the
187a9215590SGreg Lehey.Xr firewire 4
188a9215590SGreg Leheymodule, include the following in
189783a364bSGreg Lehey.Pa /boot/loader.conf :
190783a364bSGreg Lehey.Pp
191a9215590SGreg Lehey.Dl firewire_enable="YES"
1921159af41SGreg Lehey.It
1931159af41SGreg LeheyNext, use
194a9215590SGreg Lehey.Xr fwcontrol 8
195783a364bSGreg Leheyto find the firewire node corresponding to the remote machine.
196783a364bSGreg LeheyOn the local machine you might see:
197a9215590SGreg Lehey.Bd -literal -offset indent
198a9215590SGreg Lehey# fwcontrol
1991159af41SGreg Lehey2 devices (info_len=2)
2001159af41SGreg Leheynode        EUI64        status
2011159af41SGreg Lehey   1  0x00c04f3226e88061      0
2021159af41SGreg Lehey   0  0x000199000003622b      1
2031159af41SGreg Lehey.Ed
2041159af41SGreg Lehey.Pp
2051159af41SGreg LeheyThe first node is always the local system, so in this case, node 0 is the remote
2061159af41SGreg Leheysystem.
2071159af41SGreg LeheyIf there are more than two systems, check from the other end to find which node
2081159af41SGreg Leheycorresponds to the remote system.
2096d8cac85SGreg LeheyOn the remote machine, it looks like this:
210a9215590SGreg Lehey.Bd -literal -offset indent
211a9215590SGreg Lehey# fwcontrol
2121159af41SGreg Lehey2 devices (info_len=2)
2131159af41SGreg Leheynode        EUI64        status
2141159af41SGreg Lehey   0  0x000199000003622b      0
2151159af41SGreg Lehey   1  0x00c04f3226e88061      1
2161159af41SGreg Lehey.Ed
2171159af41SGreg Lehey.It
2181159af41SGreg LeheyNext, establish a firewire connection with
219a9215590SGreg Lehey.Xr dconschat 8 :
2201159af41SGreg Lehey.Pp
221a9215590SGreg Lehey.Dl "dconschat -br -G 5556 -t 0x000199000003622b"
2221159af41SGreg Lehey.Pp
223a9215590SGreg Lehey.Li 0x000199000003622b
224783a364bSGreg Leheyis the EUI64 address of the remote node, as determined from the output of
225a9215590SGreg Lehey.Xr fwcontrol 8
226783a364bSGreg Leheyabove.
227783a364bSGreg LeheyWhen started in this manner,
228a9215590SGreg Lehey.Xr dconschat 8
229783a364bSGreg Leheyestablishes a local tunnel connection from port
230a9215590SGreg Lehey.Li localhost:5556
231783a364bSGreg Leheyto the remote debugger.
232783a364bSGreg LeheyYou can also establish a console port connection with the
233783a364bSGreg Lehey.Fl C
234783a364bSGreg Leheyoption to the same invocation
235a9215590SGreg Lehey.Xr dconschat 8 .
236a9215590SGreg LeheySee the
237783a364bSGreg Lehey.Xr dconschat 8
238a9215590SGreg Leheymanpage for further details.
239783a364bSGreg Lehey.Pp
240a9215590SGreg LeheyThe
241a9215590SGreg Lehey.Xr dconschat 8
242a9215590SGreg Leheyutility
2436d8cac85SGreg Leheydoes not return control to the user.
244a9215590SGreg LeheyIt displays error messages and console output for the remote system, so it is a
245783a364bSGreg Leheygood idea to start it in its own window.
2466d8cac85SGreg Lehey.It
2476d8cac85SGreg LeheyFinally, establish connection:
248a9215590SGreg Lehey.Bd -literal -offset indent
249a9215590SGreg Lehey# gdb kernel.debug
2506d8cac85SGreg LeheyGNU gdb 5.2.1 (FreeBSD)
251a9215590SGreg Lehey.Em "(political statements omitted)"
2526d8cac85SGreg LeheyReady to go.  Enter 'tr' to connect to the remote target
253839f11a4SEitan Adlerwith /dev/cuau0, 'tr /dev/cuau1' to connect to a different port
2546d8cac85SGreg Leheyor 'trf portno' to connect to the remote target with the firewire
2556d8cac85SGreg Leheyinterface.  portno defaults to 5556.
2566d8cac85SGreg Lehey
2576d8cac85SGreg LeheyType 'getsyms' after connection to load kld symbols.
2586d8cac85SGreg Lehey
25936a142c4SRuslan ErmilovIf you are debugging a local system, you can use 'kldsyms' instead
26036a142c4SRuslan Ermilovto load the kld symbols.  That is a less obnoxious interface.
261a9215590SGreg Lehey(gdb) trf
2626d8cac85SGreg Lehey0xc21bd378 in ?? ()
2636d8cac85SGreg Lehey.Ed
2646d8cac85SGreg Lehey.Pp
265783a364bSGreg LeheyThe
266a9215590SGreg Lehey.Ic trf
267783a364bSGreg Leheymacro assumes a connection on port 5556.
268783a364bSGreg LeheyIf you want to use a different port (by changing the invocation of
269a9215590SGreg Lehey.Xr dconschat 8
270783a364bSGreg Leheyabove), use the
271a9215590SGreg Lehey.Ic tr
272783a364bSGreg Leheymacro instead.
273783a364bSGreg LeheyFor example, if you want to use port 4711, run
274a9215590SGreg Lehey.Xr dconschat 8
275783a364bSGreg Leheylike this:
276783a364bSGreg Lehey.Pp
277a9215590SGreg Lehey.Dl "dconschat -br -G 4711 -t 0x000199000003622b"
2786d8cac85SGreg Lehey.Pp
279783a364bSGreg LeheyThen establish connection with:
280a9215590SGreg Lehey.Bd -literal -offset indent
281a9215590SGreg Lehey(gdb) tr localhost:4711
282783a364bSGreg Lehey0xc21bd378 in ?? ()
283783a364bSGreg Lehey.Ed
2846d8cac85SGreg Lehey.El
2858da02496SGreg Lehey.Ss "Non-cooperative debugging a live system with a remote firewire link"
286279b7e12SGreg LeheyIn addition to the conventional debugging via firewire described in the previous
287279b7e12SGreg Leheysection, it is possible to debug a remote system without its cooperation, once
288279b7e12SGreg Leheyan initial connection has been established.
289279b7e12SGreg LeheyThis corresponds to debugging a local machine using
290279b7e12SGreg Lehey.Pa /dev/mem .
291279b7e12SGreg LeheyIt can be very useful if a system crashes and the debugger no longer responds.
292279b7e12SGreg LeheyTo use this method, set the
293a9215590SGreg Lehey.Xr sysctl 8
294279b7e12SGreg Leheyvariables
295279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_hi
296279b7e12SGreg Leheyand
297279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_lo
298a9215590SGreg Leheyto the upper and lower halves of the EUI64 ID of the remote system,
299a9215590SGreg Leheyrespectively.
300279b7e12SGreg LeheyFrom the previous example, the remote machine shows:
301a9215590SGreg Lehey.Bd -literal -offset indent
302a9215590SGreg Lehey# fwcontrol
303279b7e12SGreg Lehey2 devices (info_len=2)
304279b7e12SGreg Leheynode        EUI64        status
305279b7e12SGreg Lehey   0  0x000199000003622b      0
306279b7e12SGreg Lehey   1  0x00c04f3226e88061      1
307279b7e12SGreg Lehey.Ed
308279b7e12SGreg Lehey.Pp
309279b7e12SGreg LeheyEnter:
310a9215590SGreg Lehey.Bd -literal -offset indent
311a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_hi=0x00019900
312279b7e12SGreg Leheyhw.firewire.fwmem.eui64_hi: 0 -> 104704
313a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_lo=0x0003622b
314279b7e12SGreg Leheyhw.firewire.fwmem.eui64_lo: 0 -> 221739
315279b7e12SGreg Lehey.Ed
316279b7e12SGreg Lehey.Pp
317279b7e12SGreg LeheyNote that the variables must be explicitly stated in hexadecimal.
318279b7e12SGreg LeheyAfter this, you can examine the remote machine's state with the following input:
319a9215590SGreg Lehey.Bd -literal -offset indent
320a9215590SGreg Lehey# gdb -k kernel.debug /dev/fwmem0.0
321279b7e12SGreg LeheyGNU gdb 5.2.1 (FreeBSD)
322a9215590SGreg Lehey.Em "(messages omitted)"
323279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons.ko...done.
324279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons.ko
325279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons_crom.ko...done.
326279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons_crom.ko
327279b7e12SGreg Lehey#0  sched_switch (td=0xc0922fe0) at /usr/src/sys/kern/sched_4bsd.c:621
328279b7e12SGreg Lehey0xc21bd378 in ?? ()
329279b7e12SGreg Lehey.Ed
330279b7e12SGreg Lehey.Pp
331a9215590SGreg LeheyIn this case, it is not necessary to load the symbols explicitly.
332279b7e12SGreg LeheyThe remote system continues to run.
3331159af41SGreg Lehey.Sh COMMANDS
3341159af41SGreg LeheyThe user interface to
3351159af41SGreg Lehey.Nm
3361159af41SGreg Leheyis via
337*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb ,
3381159af41SGreg Leheyso
339*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
3401159af41SGreg Leheycommands also work.
3411159af41SGreg LeheyThis section discusses only the extensions for kernel debugging that get
3421159af41SGreg Leheyinstalled in the kernel build directory.
3438da02496SGreg Lehey.Ss "Debugging environment"
3441159af41SGreg LeheyThe following macros manipulate the debugging environment:
345a9215590SGreg Lehey.Bl -tag -width indent
346a9215590SGreg Lehey.It Ic ddb
3471159af41SGreg LeheySwitch back to
348a9215590SGreg Lehey.Xr ddb 4 .
3491159af41SGreg LeheyThis command is only meaningful when performing remote debugging.
350a9215590SGreg Lehey.It Ic getsyms
3511159af41SGreg LeheyDisplay
352a9215590SGreg Lehey.Ic kldstat
3531159af41SGreg Leheyinformation for the target machine and invite user to paste it back in.
3541159af41SGreg LeheyThis is required because
355a9215590SGreg Lehey.Nm
3561159af41SGreg Leheydoes not allow data to be passed to shell scripts.
357a9215590SGreg LeheyIt is necessary for remote debugging and crash dumps; for local memory debugging
3581159af41SGreg Leheyuse
359a9215590SGreg Lehey.Ic kldsyms
3601159af41SGreg Leheyinstead.
361a9215590SGreg Lehey.It Ic kldsyms
362a9215590SGreg LeheyRead in the symbol tables for the debugging machine.
363a9215590SGreg LeheyThis does not work for
3641159af41SGreg Leheyremote debugging and crash dumps; use
365a9215590SGreg Lehey.Ic getsyms
3661159af41SGreg Leheyinstead.
367a9215590SGreg Lehey.It Ic tr Ar interface
3681159af41SGreg LeheyDebug a remote system via the specified serial or firewire interface.
369a9215590SGreg Lehey.It Ic tr0
3701159af41SGreg LeheyDebug a remote system via serial interface
371839f11a4SEitan Adler.Pa /dev/cuau0 .
372a9215590SGreg Lehey.It Ic tr1
3731159af41SGreg LeheyDebug a remote system via serial interface
374839f11a4SEitan Adler.Pa /dev/cuau1 .
375a9215590SGreg Lehey.It Ic trf
3761159af41SGreg LeheyDebug a remote system via firewire interface at default port 5556.
3771159af41SGreg Lehey.El
3781159af41SGreg Lehey.Pp
3791159af41SGreg LeheyThe commands
380a9215590SGreg Lehey.Ic tr0 , tr1
3811159af41SGreg Leheyand
382a9215590SGreg Lehey.Ic trf
3831159af41SGreg Leheyare convenience commands which invoke
384a9215590SGreg Lehey.Ic tr .
3858da02496SGreg Lehey.Ss "The current process environment"
3861159af41SGreg LeheyThe following macros are convenience functions intended to make things easier
3871159af41SGreg Leheythan the standard
388*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
3891159af41SGreg Leheycommands.
390a9215590SGreg Lehey.Bl -tag -width indent
391a9215590SGreg Lehey.It Ic f0
3921159af41SGreg LeheySelect stack frame 0 and show assembler-level details.
393a9215590SGreg Lehey.It Ic f1
3941159af41SGreg LeheySelect stack frame 1 and show assembler-level details.
395a9215590SGreg Lehey.It Ic f2
3961159af41SGreg LeheySelect stack frame 2 and show assembler-level details.
397a9215590SGreg Lehey.It Ic f3
3981159af41SGreg LeheySelect stack frame 3 and show assembler-level details.
399a9215590SGreg Lehey.It Ic f4
4001159af41SGreg LeheySelect stack frame 4 and show assembler-level details.
401a9215590SGreg Lehey.It Ic f5
4021159af41SGreg LeheySelect stack frame 5 and show assembler-level details.
403a9215590SGreg Lehey.It Ic xb
4041159af41SGreg LeheyShow 12 words in hex, starting at current
4051159af41SGreg Lehey.Va ebp
4061159af41SGreg Leheyvalue.
407a9215590SGreg Lehey.It Ic xi
4081159af41SGreg LeheyList the next 10 instructions from the current
4091159af41SGreg Lehey.Va eip
4101159af41SGreg Leheyvalue.
411a9215590SGreg Lehey.It Ic xp
4121159af41SGreg LeheyShow the register contents and the first four parameters of the current stack
4131159af41SGreg Leheyframe.
414a9215590SGreg Lehey.It Ic xp0
4151159af41SGreg LeheyShow the first parameter of current stack frame in various formats.
416a9215590SGreg Lehey.It Ic xp1
4171159af41SGreg LeheyShow the second parameter of current stack frame in various formats.
418a9215590SGreg Lehey.It Ic xp2
4191159af41SGreg LeheyShow the third parameter of current stack frame in various formats.
420a9215590SGreg Lehey.It Ic xp3
4211159af41SGreg LeheyShow the fourth parameter of current stack frame in various formats.
422a9215590SGreg Lehey.It Ic xp4
4231159af41SGreg LeheyShow the fifth parameter of current stack frame in various formats.
424a9215590SGreg Lehey.It Ic xs
4251159af41SGreg LeheyShow the last 12 words on stack in hexadecimal.
426a9215590SGreg Lehey.It Ic xxp
4271159af41SGreg LeheyShow the register contents and the first ten parameters.
428a9215590SGreg Lehey.It Ic z
4291159af41SGreg LeheySingle step 1 instruction (over calls) and show next instruction.
430a9215590SGreg Lehey.It Ic zs
4311159af41SGreg LeheySingle step 1 instruction (through calls) and show next instruction.
4321159af41SGreg Lehey.El
4338da02496SGreg Lehey.Ss "Examining other processes"
4341159af41SGreg LeheyThe following macros access other processes.
435a9215590SGreg LeheyThe
436a9215590SGreg Lehey.Nm
437a9215590SGreg Leheydebugger
4381159af41SGreg Leheydoes not understand the concept of multiple processes, so they effectively
4391159af41SGreg Leheybypass the entire
440a9215590SGreg Lehey.Nm
4411159af41SGreg Leheyenvironment.
442a9215590SGreg Lehey.Bl -tag -width indent
443a9215590SGreg Lehey.It Ic btp Ar pid
4441159af41SGreg LeheyShow a backtrace for the process
445a9215590SGreg Lehey.Ar pid .
446a9215590SGreg Lehey.It Ic btpa
4471159af41SGreg LeheyShow backtraces for all processes in the system.
448a9215590SGreg Lehey.It Ic btpp
4491159af41SGreg LeheyShow a backtrace for the process previously selected with
450a9215590SGreg Lehey.Ic defproc .
451a9215590SGreg Lehey.It Ic btr Ar ebp
4521159af41SGreg LeheyShow a backtrace from the
453a9215590SGreg Lehey.Ar ebp
454a9215590SGreg Leheyaddress specified.
455a9215590SGreg Lehey.It Ic defproc Ar pid
4561159af41SGreg LeheySpecify the PID of the process for some other commands in this section.
457a9215590SGreg Lehey.It Ic fr Ar frame
4581159af41SGreg LeheyShow frame
459a9215590SGreg Lehey.Ar frame
4601159af41SGreg Leheyof the stack of the process previously selected with
461a9215590SGreg Lehey.Ic defproc .
462a9215590SGreg Lehey.It Ic pcb Ar proc
463a9215590SGreg LeheyShow some PCB contents of the process
4641159af41SGreg Lehey.Ar proc .
4651159af41SGreg Lehey.El
4668da02496SGreg Lehey.Ss "Examining data structures"
4671159af41SGreg LeheyYou can use standard
468*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
469a9215590SGreg Leheycommands to look at most data structures.
470a9215590SGreg LeheyThe macros in this section are
4711159af41SGreg Leheyconvenience functions which typically display the data in a more readable
4721159af41SGreg Leheyformat, or which omit less interesting parts of the structure.
473a9215590SGreg Lehey.Bl -tag -width indent
474a9215590SGreg Lehey.It Ic bp
4751159af41SGreg LeheyShow information about the buffer header pointed to by the variable
4761159af41SGreg Lehey.Va bp
4771159af41SGreg Leheyin the current frame.
478a9215590SGreg Lehey.It Ic bpd
4791159af41SGreg LeheyShow the contents
480a9215590SGreg Lehey.Pq Vt "char *"
4811159af41SGreg Leheyof
4821159af41SGreg Lehey.Va bp->data
4831159af41SGreg Leheyin the current frame.
484a9215590SGreg Lehey.It Ic bpl
4851159af41SGreg LeheyShow detailed information about the buffer header
486a9215590SGreg Lehey.Pq Vt "struct bp"
4871159af41SGreg Leheypointed at by the local variable
4881159af41SGreg Lehey.Va bp .
489a9215590SGreg Lehey.It Ic bpp Ar bp
4901159af41SGreg LeheyShow summary information about the buffer header
491a9215590SGreg Lehey.Pq Vt "struct bp"
4921159af41SGreg Leheypointed at by the parameter
493a9215590SGreg Lehey.Ar bp .
494a9215590SGreg Lehey.It Ic bx
4951159af41SGreg LeheyPrint a number of fields from the buffer header pointed at in by the pointer
496a9215590SGreg Lehey.Ar bp
4971159af41SGreg Leheyin the current environment.
498a9215590SGreg Lehey.It Ic vdev
499a9215590SGreg LeheyShow some information of the
500a9215590SGreg Lehey.Vt vnode
501a9215590SGreg Leheypointed to by the local variable
5021159af41SGreg Lehey.Va vp .
5031159af41SGreg Lehey.El
5048da02496SGreg Lehey.Ss "Miscellaneous macros"
505a9215590SGreg Lehey.Bl -tag -width indent
506a9215590SGreg Lehey.It Ic checkmem
5071159af41SGreg LeheyCheck unallocated memory for modifications.
5081159af41SGreg LeheyThis assumes that the kernel has been compiled with
50950d922a0SGlen Barber.Cd "options DIAGNOSTIC" .
5101159af41SGreg LeheyThis causes the contents of free memory to be set to
5111159af41SGreg Lehey.Li 0xdeadc0de .
512a9215590SGreg Lehey.It Ic dmesg
513a9215590SGreg LeheyPrint the system message buffer.
514a9215590SGreg LeheyThis corresponds to the
515783a364bSGreg Lehey.Xr dmesg 8
516a9215590SGreg Leheyutility.
5173f333d6bSGreg LeheyThis macro used to be called
5183f333d6bSGreg Lehey.Ic msgbuf .
519a9215590SGreg LeheyIt can take a very long time over a serial line,
520a9215590SGreg Leheyand it is even slower via firewire
5211159af41SGreg Leheyor local memory due to inefficiencies in
522a9215590SGreg Lehey.Nm .
5233f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start
5243f333d6bSGreg Lehey.Nm
5253f333d6bSGreg Leheyto access the message buffer: instead, use an appropriate variation of
5263f333d6bSGreg Lehey.Bd -literal -offset indent
5273f333d6bSGreg Leheydmesg -M /var/crash/vmcore.0 -N kernel.debug
5283f333d6bSGreg Leheydmesg -M /dev/fwmem0.0 -N kernel.debug
5293f333d6bSGreg Lehey.Ed
530a9215590SGreg Lehey.It Ic kldstat
531a9215590SGreg LeheyEquivalent of the
532a9215590SGreg Lehey.Xr kldstat 8
533a9215590SGreg Leheyutility without options.
534a9215590SGreg Lehey.It Ic pname
5351159af41SGreg LeheyPrint the command name of the current process.
536a9215590SGreg Lehey.It Ic ps
5371159af41SGreg LeheyShow process status.
5381159af41SGreg LeheyThis corresponds in concept, but not in appearance, to the
539a9215590SGreg Lehey.Xr ps 1
540a9215590SGreg Leheyutility.
5413f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start
5423f333d6bSGreg Lehey.Nm
5433f333d6bSGreg Leheyto display the
5443f333d6bSGreg Lehey.Xr ps 1
5453f333d6bSGreg Leheyoutput: instead, use an appropriate variation of
5463f333d6bSGreg Lehey.Bd -literal -offset indent
5473f333d6bSGreg Leheyps -M /var/crash/vmcore.0 -N kernel.debug
5483f333d6bSGreg Leheyps -M /dev/fwmem0.0 -N kernel.debug
5493f333d6bSGreg Lehey.Ed
550a9215590SGreg Lehey.It Ic y
551a9215590SGreg LeheyKludge for writing macros.
552a9215590SGreg LeheyWhen writing macros, it is convenient to paste them
5531159af41SGreg Leheyback into the
554a9215590SGreg Lehey.Nm
555a9215590SGreg Leheywindow.
556a9215590SGreg LeheyUnfortunately, if the macro is already defined,
557a9215590SGreg Lehey.Nm
5581159af41SGreg Leheyinsists on asking
5591159af41SGreg Lehey.Pp
560a9215590SGreg Lehey.Dl "Redefine foo?"
561a9215590SGreg Lehey.Pp
562a9215590SGreg LeheyIt will not give up until you answer
563a9215590SGreg Lehey.Ql y .
564a9215590SGreg LeheyThis command is that answer.
565a9215590SGreg LeheyIt does nothing else except to print a warning
5661159af41SGreg Leheymessage to remind you to remove it again.
5671159af41SGreg Lehey.El
5681159af41SGreg Lehey.Sh SEE ALSO
569*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb ,
5703f333d6bSGreg Lehey.Xr ps 1 ,
571a1db2f59SGreg Lehey.Xr ddb 4 ,
572a1db2f59SGreg Lehey.Xr firewire 4 ,
573a1db2f59SGreg Lehey.Xr dconschat 8 ,
574a1db2f59SGreg Lehey.Xr dmesg 8 ,
575a1db2f59SGreg Lehey.Xr fwcontrol 8 ,
576a1db2f59SGreg Lehey.Xr kldload 8
5779cbda590SRuslan Ermilov.Sh AUTHORS
5789cbda590SRuslan ErmilovThis man page was written by
5796c899950SBaptiste Daroussin.An Greg Lehey Aq Mt grog@FreeBSD.org .
5801159af41SGreg Lehey.Sh BUGS
581783a364bSGreg LeheyThe
582*3c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb
583a9215590SGreg Leheydebugger
584a9215590SGreg Leheywas never designed to debug kernels, and it is not a very good match.
585a9215590SGreg LeheyMany problems exist.
586a9215590SGreg Lehey.Pp
587a9215590SGreg LeheyThe
588a9215590SGreg Lehey.Nm
589783a364bSGreg Leheyimplementation is very inefficient, and many operations are slow.
590a9215590SGreg Lehey.Pp
591783a364bSGreg LeheySerial debugging is even slower, and race conditions can make it difficult to
592a9215590SGreg Leheyrun the link at more than 9600 bps.
593a9215590SGreg LeheyFirewire connections do not have this problem.
594a9215590SGreg Lehey.Pp
595a9215590SGreg LeheyThe debugging macros
596c42a9b6aSGlen Barber.Dq just grew.
5971159af41SGreg LeheyIn general, the person who wrote them did so while looking for a specific
5981159af41SGreg Leheyproblem, so they may not be general enough, and they may behave badly when used
5991159af41SGreg Leheyin ways for which they were not intended, even if those ways make sense.
600a9215590SGreg Lehey.Pp
6011159af41SGreg LeheyMany of these commands only work on the ia32 architecture.
602