xref: /freebsd/share/man/man4/gdb.4 (revision 3f333d6b1bae873e8fe8849d0dd971ece013e163)
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.\"
251159af41SGreg Lehey.\" $FreeBSD$
26a9215590SGreg Lehey.\"
271159af41SGreg Lehey.Dd December 30, 2003
281159af41SGreg Lehey.Dt GDB 4
291159af41SGreg Lehey.Os
301159af41SGreg Lehey.Sh NAME
311159af41SGreg Lehey.Nm gdb
321159af41SGreg Lehey.Nd external kernel debugger
331159af41SGreg Lehey.Sh SYNOPSIS
34a9215590SGreg Lehey.Cd "makeoptions DEBUG=-g"
35a9215590SGreg Lehey.Cd "options DDB"
36a9215590SGreg Lehey.Cd "options GDB_REMOTE_CHAT"
371159af41SGreg Lehey.Sh DESCRIPTION
381159af41SGreg LeheyThe
391159af41SGreg Lehey.Nm
401159af41SGreg Leheykernel debugger is a variation of
411159af41SGreg Lehey.Xr gdb 1
421159af41SGreg Leheywhich understands some aspects of the
431159af41SGreg Lehey.Fx
44a9215590SGreg Leheykernel environment.
45a9215590SGreg LeheyIt can be used in a number of ways:
46a9215590SGreg Lehey.Bl -bullet
471159af41SGreg Lehey.It
488da02496SGreg LeheyIt can be used to examine the memory of the processor on which it runs.
498da02496SGreg Lehey.It
508da02496SGreg LeheyIt can be used to analyse a processor dump after a panic.
518da02496SGreg Lehey.It
521159af41SGreg LeheyIt can be used to debug another system interactively via a serial or firewire
53a9215590SGreg Leheylink.
54a9215590SGreg LeheyIn this mode, the processor can be stopped and single stepped.
551159af41SGreg Lehey.It
568da02496SGreg LeheyWith a firewire link, it can be used to examine the memory of a remote system
578da02496SGreg Leheywithout the participation of that system.
588da02496SGreg LeheyIn this mode, the processor cannot be stopped and single stepped, but it can be
598da02496SGreg Leheyof use when the remote system has crashed and is no longer responding.
601159af41SGreg Lehey.El
611159af41SGreg Lehey.Pp
621159af41SGreg LeheyWhen used for remote debugging,
631159af41SGreg Lehey.Nm
641159af41SGreg Leheyrequires the presence of the
651159af41SGreg Lehey.Xr ddb 4
661159af41SGreg Leheykernel debugger.
671159af41SGreg LeheyCommands exist to switch between
681159af41SGreg Lehey.Nm
691159af41SGreg Leheyand
701159af41SGreg Lehey.Xr ddb 4 .
711159af41SGreg Lehey.Sh PREPARING FOR DEBUGGING
721159af41SGreg LeheyWhen debugging kernels, it is practically essential to have built a kernel with
731159af41SGreg Leheydebugging symbols
74a9215590SGreg Lehey.Pq Cd "makeoptions DEBUG=-g" .
75a9215590SGreg LeheyIt is easiest to perform operations from the kernel build directory, by default
76a9215590SGreg Lehey.Pa /usr/obj/usr/src/sys/GENERIC .
771159af41SGreg Lehey.Pp
781159af41SGreg LeheyFirst, ensure you have a copy of the debug macros in the directory:
79a9215590SGreg Lehey.Pp
80a9215590SGreg Lehey.Dl "make gdbinit"
811159af41SGreg Lehey.Pp
821159af41SGreg LeheyThis command performs some transformations on the macros installed in
831159af41SGreg Lehey.Pa /usr/src/tools/debugscripts
841159af41SGreg Leheyto adapt them to the local environment.
858da02496SGreg Lehey.Ss "Inspecting the environment of the local machine"
86a9215590SGreg LeheyTo look at and change the contents of the memory of the system you are running
871159af41SGreg Leheyon,
88a9215590SGreg Lehey.Pp
89a9215590SGreg Lehey.Dl "gdb -k -wcore kernel.debug /dev/mem"
901159af41SGreg Lehey.Pp
911159af41SGreg LeheyIn this mode, you need the
921159af41SGreg Lehey.Fl k
931159af41SGreg Leheyflag to indicate to
94a9215590SGreg Lehey.Xr gdb 1
95a9215590SGreg Leheythat the
96a9215590SGreg Lehey.Dq "dump file"
971159af41SGreg Lehey.Pa /dev/mem
981159af41SGreg Leheyis a kernel data file.
991159af41SGreg LeheyYou can look at live data, and if you include the
1001159af41SGreg Lehey.Fl wcore
1011159af41SGreg Leheyoption, you can change it at your peril.
1021159af41SGreg LeheyThe system does not stop (obviously), so a number of things will not work.
103a9215590SGreg LeheyYou can set breakpoints, but you cannot
104a9215590SGreg Lehey.Dq continue
105a9215590SGreg Leheyexecution, so they will not work.
1068da02496SGreg Lehey.Ss "Debugging a crash dump"
1078cfbf24fSGreg LeheyBy default, crash dumps are stored in the directory
1081159af41SGreg Lehey.Pa /var/crash .
1091159af41SGreg LeheyInvestigate them from the kernel build directory with:
110a9215590SGreg Lehey.Pp
111a9215590SGreg Lehey.Dl "gdb -k kernel.debug /var/crash/vmcore.29"
1121159af41SGreg Lehey.Pp
1131159af41SGreg LeheyIn this mode, the system is obviously stopped, so you can only look at it.
1148da02496SGreg Lehey.Ss "Debugging a live system with a remote link"
115a9215590SGreg LeheyIn the following discussion, the term
116a9215590SGreg Lehey.Dq "local system"
117a9215590SGreg Leheyrefers to the system running the debugger, and
118a9215590SGreg Lehey.Dq "remote system"
119a9215590SGreg Leheyrefers to the live system being debugged.
120783a364bSGreg Lehey.Pp
1211159af41SGreg LeheyTo debug a live system with a remote link, the kernel must be compiled with the
122783a364bSGreg Leheyoption
123a9215590SGreg Lehey.Cd "options DDB" .
1241159af41SGreg LeheyThe option
125a9215590SGreg Lehey.Cd "options BREAK_TO_DEBUGGER"
1261159af41SGreg Leheyenables the debugging machine stop the debugged machine once a connection has
1271159af41SGreg Leheybeen established by pressing
128a9215590SGreg Lehey.Ql ^C .
1298da02496SGreg Lehey.Ss "Debugging a live system with a remote serial link"
130a9215590SGreg LeheyWhen using a serial port for the remote link on the i386 platform, the serial
1311159af41SGreg Leheyport must be identified by setting the flag bit
1321159af41SGreg Lehey.Li 0x80
1331159af41SGreg Leheyfor the specified interface.
134a9215590SGreg LeheyGenerally, this port will also be used as a serial console (flag bit
135a9215590SGreg Lehey.Li 0x10 ) ,
1361159af41SGreg Leheyso the entry in
1371159af41SGreg Lehey.Pa /boot/device.hints
1381159af41SGreg Leheyshould be:
139a9215590SGreg Lehey.Pp
140a9215590SGreg Lehey.Dl hint.sio.0.flags="0x90"
141783a364bSGreg Lehey.Pp
142783a364bSGreg LeheyTo share a console and debug connection on a serial line, use the
143a9215590SGreg Lehey.Cd "options GDB_REMOTE_CHAT"
144783a364bSGreg Leheyoption.
1458da02496SGreg Lehey.Ss "Debugging a live system with a remote firewire link"
1461159af41SGreg LeheyAs with serial debugging, to debug a live system with a firewire link, the
147783a364bSGreg Leheykernel must be compiled with the option
148a9215590SGreg Lehey.Cd "options DDB" .
149783a364bSGreg LeheyThe
150a9215590SGreg Lehey.Cd "options GDB_REMOTE_CHAT"
151783a364bSGreg Leheyis not necessary, since the firewire implementation uses separate ports for the
152783a364bSGreg Leheyconsole and debug connection.
1531159af41SGreg Lehey.Pp
1541159af41SGreg LeheyA number of steps must be performed to set up a firewire link:
155a9215590SGreg Lehey.Bl -bullet
1561159af41SGreg Lehey.It
157a9215590SGreg LeheyEnsure that both systems have
158a9215590SGreg Lehey.Xr firewire 4
159a9215590SGreg Leheysupport, and that the kernel of the remote system includes the
160a9215590SGreg Lehey.Xr dcons 4
161783a364bSGreg Leheyand
162a9215590SGreg Lehey.Xr dcons_crom 4
163783a364bSGreg Leheydrivers.
164a9215590SGreg LeheyIf they are not compiled into the kernel, load the KLDs:
165a9215590SGreg Lehey.Pp
166a9215590SGreg Lehey.Dl "kldload firewire"
167a9215590SGreg Lehey.Pp
168a9215590SGreg LeheyOn the remote system only:
169a9215590SGreg Lehey.Bd -literal -offset indent
170a9215590SGreg Leheykldload dcons
171a9215590SGreg Leheykldload dcons_crom
1721159af41SGreg Lehey.Ed
1731159af41SGreg Lehey.Pp
1741159af41SGreg LeheyYou should see something like this in the
175a9215590SGreg Lehey.Xr dmesg 8
176783a364bSGreg Leheyoutput of the remote system:
177a9215590SGreg Lehey.Bd -literal -offset indent
1781159af41SGreg Leheyfwohci0: BUS reset
1791159af41SGreg Leheyfwohci0: node_id=0x8800ffc0, gen=2, non CYCLEMASTER mode
1801159af41SGreg Leheyfirewire0: 2 nodes, maxhop <= 1, cable IRM = 1
1811159af41SGreg Leheyfirewire0: bus manager 1
1821159af41SGreg Leheyfirewire0: New S400 device ID:00c04f3226e88061
1831159af41SGreg Leheydcons_crom0: <dcons configuration ROM> on firewire0
1841159af41SGreg Leheydcons_crom0: bus_addr 0x22a000
1851159af41SGreg Lehey.Ed
1861159af41SGreg Lehey.Pp
187a9215590SGreg LeheyIt is a good idea to load these modules at boot time with the following entry in
1881159af41SGreg Lehey.Pa /boot/loader.conf :
1891159af41SGreg Lehey.Pp
190a9215590SGreg Lehey.Dl dcons_crom_enable="YES"
1911159af41SGreg Lehey.Pp
192783a364bSGreg LeheyThis ensures that all three modules are loaded.
193783a364bSGreg LeheyThere is no harm in loading
194a9215590SGreg Lehey.Xr dcons 4
195783a364bSGreg Leheyand
196a9215590SGreg Lehey.Xr dcons_crom 4
197a9215590SGreg Leheyon the local system, but if you only want to load the
198a9215590SGreg Lehey.Xr firewire 4
199a9215590SGreg Leheymodule, include the following in
200783a364bSGreg Lehey.Pa /boot/loader.conf :
201783a364bSGreg Lehey.Pp
202a9215590SGreg Lehey.Dl firewire_enable="YES"
2031159af41SGreg Lehey.It
2041159af41SGreg LeheyNext, use
205a9215590SGreg Lehey.Xr fwcontrol 8
206783a364bSGreg Leheyto find the firewire node corresponding to the remote machine.
207783a364bSGreg LeheyOn the local machine you might see:
208a9215590SGreg Lehey.Bd -literal -offset indent
209a9215590SGreg Lehey# fwcontrol
2101159af41SGreg Lehey2 devices (info_len=2)
2111159af41SGreg Leheynode        EUI64        status
2121159af41SGreg Lehey   1  0x00c04f3226e88061      0
2131159af41SGreg Lehey   0  0x000199000003622b      1
2141159af41SGreg Lehey.Ed
2151159af41SGreg Lehey.Pp
2161159af41SGreg LeheyThe first node is always the local system, so in this case, node 0 is the remote
2171159af41SGreg Leheysystem.
2181159af41SGreg LeheyIf there are more than two systems, check from the other end to find which node
2191159af41SGreg Leheycorresponds to the remote system.
2206d8cac85SGreg LeheyOn the remote machine, it looks like this:
221a9215590SGreg Lehey.Bd -literal -offset indent
222a9215590SGreg Lehey# fwcontrol
2231159af41SGreg Lehey2 devices (info_len=2)
2241159af41SGreg Leheynode        EUI64        status
2251159af41SGreg Lehey   0  0x000199000003622b      0
2261159af41SGreg Lehey   1  0x00c04f3226e88061      1
2271159af41SGreg Lehey.Ed
2281159af41SGreg Lehey.It
2291159af41SGreg LeheyNext, establish a firewire connection with
230a9215590SGreg Lehey.Xr dconschat 8 :
2311159af41SGreg Lehey.Pp
232a9215590SGreg Lehey.Dl "dconschat -br -G 5556 -t 0x000199000003622b"
2331159af41SGreg Lehey.Pp
234a9215590SGreg Lehey.Li 0x000199000003622b
235783a364bSGreg Leheyis the EUI64 address of the remote node, as determined from the output of
236a9215590SGreg Lehey.Xr fwcontrol 8
237783a364bSGreg Leheyabove.
238783a364bSGreg LeheyWhen started in this manner,
239a9215590SGreg Lehey.Xr dconschat 8
240783a364bSGreg Leheyestablishes a local tunnel connection from port
241a9215590SGreg Lehey.Li localhost:5556
242783a364bSGreg Leheyto the remote debugger.
243783a364bSGreg LeheyYou can also establish a console port connection with the
244783a364bSGreg Lehey.Fl C
245783a364bSGreg Leheyoption to the same invocation
246a9215590SGreg Lehey.Xr dconschat 8 .
247a9215590SGreg LeheySee the
248783a364bSGreg Lehey.Xr dconschat 8
249a9215590SGreg Leheymanpage for further details.
250783a364bSGreg Lehey.Pp
251a9215590SGreg LeheyThe
252a9215590SGreg Lehey.Xr dconschat 8
253a9215590SGreg Leheyutility
2546d8cac85SGreg Leheydoes not return control to the user.
255a9215590SGreg LeheyIt displays error messages and console output for the remote system, so it is a
256783a364bSGreg Leheygood idea to start it in its own window.
2576d8cac85SGreg Lehey.It
2586d8cac85SGreg LeheyFinally, establish connection:
259a9215590SGreg Lehey.Bd -literal -offset indent
260a9215590SGreg Lehey# gdb kernel.debug
2616d8cac85SGreg LeheyGNU gdb 5.2.1 (FreeBSD)
262a9215590SGreg Lehey.Em "(political statements omitted)"
2636d8cac85SGreg LeheyReady to go.  Enter 'tr' to connect to the remote target
2646d8cac85SGreg Leheywith /dev/cuaa0, 'tr /dev/cuaa1' to connect to a different port
2656d8cac85SGreg Leheyor 'trf portno' to connect to the remote target with the firewire
2666d8cac85SGreg Leheyinterface.  portno defaults to 5556.
2676d8cac85SGreg Lehey
2686d8cac85SGreg LeheyType 'getsyms' after connection to load kld symbols.
2696d8cac85SGreg Lehey
2706d8cac85SGreg LeheyIf you're debugging a local system, you can use 'kldsyms' instead
2716d8cac85SGreg Leheyto load the kld symbols.  That's a less obnoxious interface.
272a9215590SGreg Lehey(gdb) trf
2736d8cac85SGreg Lehey0xc21bd378 in ?? ()
2746d8cac85SGreg Lehey.Ed
2756d8cac85SGreg Lehey.Pp
276783a364bSGreg LeheyThe
277a9215590SGreg Lehey.Ic trf
278783a364bSGreg Leheymacro assumes a connection on port 5556.
279783a364bSGreg LeheyIf you want to use a different port (by changing the invocation of
280a9215590SGreg Lehey.Xr dconschat 8
281783a364bSGreg Leheyabove), use the
282a9215590SGreg Lehey.Ic tr
283783a364bSGreg Leheymacro instead.
284783a364bSGreg LeheyFor example, if you want to use port 4711, run
285a9215590SGreg Lehey.Xr dconschat 8
286783a364bSGreg Leheylike this:
287783a364bSGreg Lehey.Pp
288a9215590SGreg Lehey.Dl "dconschat -br -G 4711 -t 0x000199000003622b"
2896d8cac85SGreg Lehey.Pp
290783a364bSGreg LeheyThen establish connection with:
291a9215590SGreg Lehey.Bd -literal -offset indent
292a9215590SGreg Lehey(gdb) tr localhost:4711
293783a364bSGreg Lehey0xc21bd378 in ?? ()
294783a364bSGreg Lehey.Ed
2956d8cac85SGreg Lehey.El
2968da02496SGreg Lehey.Ss "Non-cooperative debugging a live system with a remote firewire link"
297279b7e12SGreg LeheyIn addition to the conventional debugging via firewire described in the previous
298279b7e12SGreg Leheysection, it is possible to debug a remote system without its cooperation, once
299279b7e12SGreg Leheyan initial connection has been established.
300279b7e12SGreg LeheyThis corresponds to debugging a local machine using
301279b7e12SGreg Lehey.Pa /dev/mem .
302279b7e12SGreg LeheyIt can be very useful if a system crashes and the debugger no longer responds.
303279b7e12SGreg LeheyTo use this method, set the
304a9215590SGreg Lehey.Xr sysctl 8
305279b7e12SGreg Leheyvariables
306279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_hi
307279b7e12SGreg Leheyand
308279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_lo
309a9215590SGreg Leheyto the upper and lower halves of the EUI64 ID of the remote system,
310a9215590SGreg Leheyrespectively.
311279b7e12SGreg LeheyFrom the previous example, the remote machine shows:
312a9215590SGreg Lehey.Bd -literal -offset indent
313a9215590SGreg Lehey# fwcontrol
314279b7e12SGreg Lehey2 devices (info_len=2)
315279b7e12SGreg Leheynode        EUI64        status
316279b7e12SGreg Lehey   0  0x000199000003622b      0
317279b7e12SGreg Lehey   1  0x00c04f3226e88061      1
318279b7e12SGreg Lehey.Ed
319279b7e12SGreg Lehey.Pp
320279b7e12SGreg LeheyEnter:
321a9215590SGreg Lehey.Bd -literal -offset indent
322a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_hi=0x00019900
323279b7e12SGreg Leheyhw.firewire.fwmem.eui64_hi: 0 -> 104704
324a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_lo=0x0003622b
325279b7e12SGreg Leheyhw.firewire.fwmem.eui64_lo: 0 -> 221739
326279b7e12SGreg Lehey.Ed
327279b7e12SGreg Lehey.Pp
328279b7e12SGreg LeheyNote that the variables must be explicitly stated in hexadecimal.
329279b7e12SGreg LeheyAfter this, you can examine the remote machine's state with the following input:
330a9215590SGreg Lehey.Bd -literal -offset indent
331a9215590SGreg Lehey# gdb -k kernel.debug /dev/fwmem0.0
332279b7e12SGreg LeheyGNU gdb 5.2.1 (FreeBSD)
333a9215590SGreg Lehey.Em "(messages omitted)"
334279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons.ko...done.
335279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons.ko
336279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons_crom.ko...done.
337279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons_crom.ko
338279b7e12SGreg Lehey#0  sched_switch (td=0xc0922fe0) at /usr/src/sys/kern/sched_4bsd.c:621
339279b7e12SGreg Lehey0xc21bd378 in ?? ()
340279b7e12SGreg Lehey.Ed
341279b7e12SGreg Lehey.Pp
342a9215590SGreg LeheyIn this case, it is not necessary to load the symbols explicitly.
343279b7e12SGreg LeheyThe remote system continues to run.
3441159af41SGreg Lehey.Sh COMMANDS
3451159af41SGreg LeheyThe user interface to
3461159af41SGreg Lehey.Nm
3471159af41SGreg Leheyis via
3481159af41SGreg Lehey.Xr gdb 1 ,
3491159af41SGreg Leheyso
3501159af41SGreg Lehey.Xr gdb 1
3511159af41SGreg Leheycommands also work.
3521159af41SGreg LeheyThis section discusses only the extensions for kernel debugging that get
3531159af41SGreg Leheyinstalled in the kernel build directory.
3548da02496SGreg Lehey.Ss "Debugging environment"
3551159af41SGreg LeheyThe following macros manipulate the debugging environment:
356a9215590SGreg Lehey.Bl -tag -width indent
357a9215590SGreg Lehey.It Ic ddb
3581159af41SGreg LeheySwitch back to
359a9215590SGreg Lehey.Xr ddb 4 .
3601159af41SGreg LeheyThis command is only meaningful when performing remote debugging.
361a9215590SGreg Lehey.It Ic getsyms
3621159af41SGreg LeheyDisplay
363a9215590SGreg Lehey.Ic kldstat
3641159af41SGreg Leheyinformation for the target machine and invite user to paste it back in.
3651159af41SGreg LeheyThis is required because
366a9215590SGreg Lehey.Nm
3671159af41SGreg Leheydoes not allow data to be passed to shell scripts.
368a9215590SGreg LeheyIt is necessary for remote debugging and crash dumps; for local memory debugging
3691159af41SGreg Leheyuse
370a9215590SGreg Lehey.Ic kldsyms
3711159af41SGreg Leheyinstead.
372a9215590SGreg Lehey.It Ic kldsyms
373a9215590SGreg LeheyRead in the symbol tables for the debugging machine.
374a9215590SGreg LeheyThis does not work for
3751159af41SGreg Leheyremote debugging and crash dumps; use
376a9215590SGreg Lehey.Ic getsyms
3771159af41SGreg Leheyinstead.
378a9215590SGreg Lehey.It Ic tr Ar interface
3791159af41SGreg LeheyDebug a remote system via the specified serial or firewire interface.
380a9215590SGreg Lehey.It Ic tr0
3811159af41SGreg LeheyDebug a remote system via serial interface
3821159af41SGreg Lehey.Pa /dev/cuaa0 .
383a9215590SGreg Lehey.It Ic tr1
3841159af41SGreg LeheyDebug a remote system via serial interface
3851159af41SGreg Lehey.Pa /dev/cuaa1 .
386a9215590SGreg Lehey.It Ic trf
3871159af41SGreg LeheyDebug a remote system via firewire interface at default port 5556.
3881159af41SGreg Lehey.El
3891159af41SGreg Lehey.Pp
3901159af41SGreg LeheyThe commands
391a9215590SGreg Lehey.Ic tr0 , tr1
3921159af41SGreg Leheyand
393a9215590SGreg Lehey.Ic trf
3941159af41SGreg Leheyare convenience commands which invoke
395a9215590SGreg Lehey.Ic tr .
3968da02496SGreg Lehey.Ss "The current process environment"
3971159af41SGreg LeheyThe following macros are convenience functions intended to make things easier
3981159af41SGreg Leheythan the standard
399a9215590SGreg Lehey.Xr gdb 1
4001159af41SGreg Leheycommands.
401a9215590SGreg Lehey.Bl -tag -width indent
402a9215590SGreg Lehey.It Ic f0
4031159af41SGreg LeheySelect stack frame 0 and show assembler-level details.
404a9215590SGreg Lehey.It Ic f1
4051159af41SGreg LeheySelect stack frame 1 and show assembler-level details.
406a9215590SGreg Lehey.It Ic f2
4071159af41SGreg LeheySelect stack frame 2 and show assembler-level details.
408a9215590SGreg Lehey.It Ic f3
4091159af41SGreg LeheySelect stack frame 3 and show assembler-level details.
410a9215590SGreg Lehey.It Ic f4
4111159af41SGreg LeheySelect stack frame 4 and show assembler-level details.
412a9215590SGreg Lehey.It Ic f5
4131159af41SGreg LeheySelect stack frame 5 and show assembler-level details.
414a9215590SGreg Lehey.It Ic xb
4151159af41SGreg LeheyShow 12 words in hex, starting at current
4161159af41SGreg Lehey.Va ebp
4171159af41SGreg Leheyvalue.
418a9215590SGreg Lehey.It Ic xi
4191159af41SGreg LeheyList the next 10 instructions from the current
4201159af41SGreg Lehey.Va eip
4211159af41SGreg Leheyvalue.
422a9215590SGreg Lehey.It Ic xp
4231159af41SGreg LeheyShow the register contents and the first four parameters of the current stack
4241159af41SGreg Leheyframe.
425a9215590SGreg Lehey.It Ic xp0
4261159af41SGreg LeheyShow the first parameter of current stack frame in various formats.
427a9215590SGreg Lehey.It Ic xp1
4281159af41SGreg LeheyShow the second parameter of current stack frame in various formats.
429a9215590SGreg Lehey.It Ic xp2
4301159af41SGreg LeheyShow the third parameter of current stack frame in various formats.
431a9215590SGreg Lehey.It Ic xp3
4321159af41SGreg LeheyShow the fourth parameter of current stack frame in various formats.
433a9215590SGreg Lehey.It Ic xp4
4341159af41SGreg LeheyShow the fifth parameter of current stack frame in various formats.
435a9215590SGreg Lehey.It Ic xs
4361159af41SGreg LeheyShow the last 12 words on stack in hexadecimal.
437a9215590SGreg Lehey.It Ic xxp
4381159af41SGreg LeheyShow the register contents and the first ten parameters.
439a9215590SGreg Lehey.It Ic z
4401159af41SGreg LeheySingle step 1 instruction (over calls) and show next instruction.
441a9215590SGreg Lehey.It Ic zs
4421159af41SGreg LeheySingle step 1 instruction (through calls) and show next instruction.
4431159af41SGreg Lehey.El
4448da02496SGreg Lehey.Ss "Examining other processes"
4451159af41SGreg LeheyThe following macros access other processes.
446a9215590SGreg LeheyThe
447a9215590SGreg Lehey.Nm
448a9215590SGreg Leheydebugger
4491159af41SGreg Leheydoes not understand the concept of multiple processes, so they effectively
4501159af41SGreg Leheybypass the entire
451a9215590SGreg Lehey.Nm
4521159af41SGreg Leheyenvironment.
453a9215590SGreg Lehey.Bl -tag -width indent
454a9215590SGreg Lehey.It Ic btp Ar pid
4551159af41SGreg LeheyShow a backtrace for the process
456a9215590SGreg Lehey.Ar pid .
457a9215590SGreg Lehey.It Ic btpa
4581159af41SGreg LeheyShow backtraces for all processes in the system.
459a9215590SGreg Lehey.It Ic btpp
4601159af41SGreg LeheyShow a backtrace for the process previously selected with
461a9215590SGreg Lehey.Ic defproc .
462a9215590SGreg Lehey.It Ic btr Ar ebp
4631159af41SGreg LeheyShow a backtrace from the
464a9215590SGreg Lehey.Ar ebp
465a9215590SGreg Leheyaddress specified.
466a9215590SGreg Lehey.It Ic defproc Ar pid
4671159af41SGreg LeheySpecify the PID of the process for some other commands in this section.
468a9215590SGreg Lehey.It Ic fr Ar frame
4691159af41SGreg LeheyShow frame
470a9215590SGreg Lehey.Ar frame
4711159af41SGreg Leheyof the stack of the process previously selected with
472a9215590SGreg Lehey.Ic defproc .
473a9215590SGreg Lehey.It Ic pcb Ar proc
474a9215590SGreg LeheyShow some PCB contents of the process
4751159af41SGreg Lehey.Ar proc .
4761159af41SGreg Lehey.El
4778da02496SGreg Lehey.Ss "Examining data structures"
4781159af41SGreg LeheyYou can use standard
479a9215590SGreg Lehey.Xr gdb 1
480a9215590SGreg Leheycommands to look at most data structures.
481a9215590SGreg LeheyThe macros in this section are
4821159af41SGreg Leheyconvenience functions which typically display the data in a more readable
4831159af41SGreg Leheyformat, or which omit less interesting parts of the structure.
484a9215590SGreg Lehey.Bl -tag -width indent
485a9215590SGreg Lehey.It Ic bp
4861159af41SGreg LeheyShow information about the buffer header pointed to by the variable
4871159af41SGreg Lehey.Va bp
4881159af41SGreg Leheyin the current frame.
489a9215590SGreg Lehey.It Ic bpd
4901159af41SGreg LeheyShow the contents
491a9215590SGreg Lehey.Pq Vt "char *"
4921159af41SGreg Leheyof
4931159af41SGreg Lehey.Va bp->data
4941159af41SGreg Leheyin the current frame.
495a9215590SGreg Lehey.It Ic bpl
4961159af41SGreg LeheyShow detailed information about the buffer header
497a9215590SGreg Lehey.Pq Vt "struct bp"
4981159af41SGreg Leheypointed at by the local variable
4991159af41SGreg Lehey.Va bp .
500a9215590SGreg Lehey.It Ic bpp Ar bp
5011159af41SGreg LeheyShow summary information about the buffer header
502a9215590SGreg Lehey.Pq Vt "struct bp"
5031159af41SGreg Leheypointed at by the parameter
504a9215590SGreg Lehey.Ar bp .
505a9215590SGreg Lehey.It Ic bx
5061159af41SGreg LeheyPrint a number of fields from the buffer header pointed at in by the pointer
507a9215590SGreg Lehey.Ar bp
5081159af41SGreg Leheyin the current environment.
509a9215590SGreg Lehey.It Ic vdev
510a9215590SGreg LeheyShow some information of the
511a9215590SGreg Lehey.Vt vnode
512a9215590SGreg Leheypointed to by the local variable
5131159af41SGreg Lehey.Va vp .
5141159af41SGreg Lehey.El
5158da02496SGreg Lehey.Ss "Miscellaneous macros"
516a9215590SGreg Lehey.Bl -tag -width indent
517a9215590SGreg Lehey.It Ic checkmem
5181159af41SGreg LeheyCheck unallocated memory for modifications.
5191159af41SGreg LeheyThis assumes that the kernel has been compiled with
520a9215590SGreg Lehey.Cd "options DIAGNOSTIC"
5211159af41SGreg LeheyThis causes the contents of free memory to be set to
5221159af41SGreg Lehey.Li 0xdeadc0de .
523a9215590SGreg Lehey.It Ic dmesg
524a9215590SGreg LeheyPrint the system message buffer.
525a9215590SGreg LeheyThis corresponds to the
526783a364bSGreg Lehey.Xr dmesg 8
527a9215590SGreg Leheyutility.
5283f333d6bSGreg LeheyThis macro used to be called
5293f333d6bSGreg Lehey.Ic msgbuf .
530a9215590SGreg LeheyIt can take a very long time over a serial line,
531a9215590SGreg Leheyand it is even slower via firewire
5321159af41SGreg Leheyor local memory due to inefficiencies in
533a9215590SGreg Lehey.Nm .
5343f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start
5353f333d6bSGreg Lehey.Nm
5363f333d6bSGreg Leheyto access the message buffer: instead, use an appropriate variation of
5373f333d6bSGreg Lehey.Bd -literal -offset indent
5383f333d6bSGreg Leheydmesg -M /var/crash/vmcore.0 -N kernel.debug
5393f333d6bSGreg Leheydmesg -M /dev/fwmem0.0 -N kernel.debug
5403f333d6bSGreg Lehey.Ed
541a9215590SGreg Lehey.It Ic kldstat
542a9215590SGreg LeheyEquivalent of the
543a9215590SGreg Lehey.Xr kldstat 8
544a9215590SGreg Leheyutility without options.
545a9215590SGreg Lehey.It Ic pname
5461159af41SGreg LeheyPrint the command name of the current process.
547a9215590SGreg Lehey.It Ic ps
5481159af41SGreg LeheyShow process status.
5491159af41SGreg LeheyThis corresponds in concept, but not in appearance, to the
550a9215590SGreg Lehey.Xr ps 1
551a9215590SGreg Leheyutility.
5523f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start
5533f333d6bSGreg Lehey.Nm
5543f333d6bSGreg Leheyto display the
5553f333d6bSGreg Lehey.Xr ps 1
5563f333d6bSGreg Leheyoutput: instead, use an appropriate variation of
5573f333d6bSGreg Lehey.Bd -literal -offset indent
5583f333d6bSGreg Leheyps -M /var/crash/vmcore.0 -N kernel.debug
5593f333d6bSGreg Leheyps -M /dev/fwmem0.0 -N kernel.debug
5603f333d6bSGreg Lehey.Ed
561a9215590SGreg Lehey.It Ic y
562a9215590SGreg LeheyKludge for writing macros.
563a9215590SGreg LeheyWhen writing macros, it is convenient to paste them
5641159af41SGreg Leheyback into the
565a9215590SGreg Lehey.Nm
566a9215590SGreg Leheywindow.
567a9215590SGreg LeheyUnfortunately, if the macro is already defined,
568a9215590SGreg Lehey.Nm
5691159af41SGreg Leheyinsists on asking
5701159af41SGreg Lehey.Pp
571a9215590SGreg Lehey.Dl "Redefine foo?"
572a9215590SGreg Lehey.Pp
573a9215590SGreg LeheyIt will not give up until you answer
574a9215590SGreg Lehey.Ql y .
575a9215590SGreg LeheyThis command is that answer.
576a9215590SGreg LeheyIt does nothing else except to print a warning
5771159af41SGreg Leheymessage to remind you to remove it again.
5781159af41SGreg Lehey.El
5791159af41SGreg Lehey.Sh AUTHORS
5801159af41SGreg LeheyThis man page was written by
581a9215590SGreg Lehey.An "Greg Lehey" Aq grog@FreeBSD.org .
5821159af41SGreg Lehey.Sh SEE ALSO
583a9215590SGreg Lehey.Xr dconschat 8 ,
5843f333d6bSGreg Lehey.Xr ddb 4 ,
5853f333d6bSGreg Lehey.Xr dmesg 8 ,
5863f333d6bSGreg Lehey.Xr firewire 4 ,
587a9215590SGreg Lehey.Xr fwcontrol 8 ,
5883f333d6bSGreg Lehey.Xr gdb 1 ,
5893f333d6bSGreg Lehey.Xr kldload 8 ,
5903f333d6bSGreg Lehey.Xr ps 1 ,
5913f333d6bSGreg Lehey.Xr vinumdebug 4 .
5921159af41SGreg Lehey.Sh BUGS
593783a364bSGreg LeheyThe
594a9215590SGreg Lehey.Xr gdb 1
595a9215590SGreg Leheydebugger
596a9215590SGreg Leheywas never designed to debug kernels, and it is not a very good match.
597a9215590SGreg LeheyMany problems exist.
598a9215590SGreg Lehey.Pp
599a9215590SGreg LeheyThe
600a9215590SGreg Lehey.Nm
601783a364bSGreg Leheyimplementation is very inefficient, and many operations are slow.
602a9215590SGreg Lehey.Pp
603783a364bSGreg LeheySerial debugging is even slower, and race conditions can make it difficult to
604a9215590SGreg Leheyrun the link at more than 9600 bps.
605a9215590SGreg LeheyFirewire connections do not have this problem.
606a9215590SGreg Lehey.Pp
607a9215590SGreg LeheyThe debugging macros
6088da02496SGreg Lehey.Dq "just growed" .
6091159af41SGreg LeheyIn general, the person who wrote them did so while looking for a specific
6101159af41SGreg Leheyproblem, so they may not be general enough, and they may behave badly when used
6111159af41SGreg Leheyin ways for which they were not intended, even if those ways make sense.
612a9215590SGreg Lehey.Pp
6131159af41SGreg LeheyMany of these commands only work on the ia32 architecture.
614