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.\" 27050892f9SChristian Brueffer.Dd February 8, 2005 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" 361159af41SGreg Lehey.Sh DESCRIPTION 371159af41SGreg LeheyThe 381159af41SGreg Lehey.Nm 391159af41SGreg Leheykernel debugger is a variation of 401159af41SGreg Lehey.Xr gdb 1 411159af41SGreg Leheywhich understands some aspects of the 421159af41SGreg Lehey.Fx 43a9215590SGreg Leheykernel environment. 44a9215590SGreg LeheyIt can be used in a number of ways: 45a9215590SGreg Lehey.Bl -bullet 461159af41SGreg Lehey.It 478da02496SGreg LeheyIt can be used to examine the memory of the processor on which it runs. 488da02496SGreg Lehey.It 498da02496SGreg LeheyIt can be used to analyse a processor dump after a panic. 508da02496SGreg Lehey.It 511159af41SGreg LeheyIt can be used to debug another system interactively via a serial or firewire 52a9215590SGreg Leheylink. 53a9215590SGreg LeheyIn this mode, the processor can be stopped and single stepped. 541159af41SGreg Lehey.It 558da02496SGreg LeheyWith a firewire link, it can be used to examine the memory of a remote system 568da02496SGreg Leheywithout the participation of that system. 578da02496SGreg LeheyIn this mode, the processor cannot be stopped and single stepped, but it can be 588da02496SGreg Leheyof use when the remote system has crashed and is no longer responding. 591159af41SGreg Lehey.El 601159af41SGreg Lehey.Pp 611159af41SGreg LeheyWhen used for remote debugging, 621159af41SGreg Lehey.Nm 631159af41SGreg Leheyrequires the presence of the 641159af41SGreg Lehey.Xr ddb 4 651159af41SGreg Leheykernel debugger. 661159af41SGreg LeheyCommands exist to switch between 671159af41SGreg Lehey.Nm 681159af41SGreg Leheyand 691159af41SGreg Lehey.Xr ddb 4 . 701159af41SGreg Lehey.Sh PREPARING FOR DEBUGGING 711159af41SGreg LeheyWhen debugging kernels, it is practically essential to have built a kernel with 721159af41SGreg Leheydebugging symbols 73a9215590SGreg Lehey.Pq Cd "makeoptions DEBUG=-g" . 74a9215590SGreg LeheyIt is easiest to perform operations from the kernel build directory, by default 75a9215590SGreg Lehey.Pa /usr/obj/usr/src/sys/GENERIC . 761159af41SGreg Lehey.Pp 771159af41SGreg LeheyFirst, ensure you have a copy of the debug macros in the directory: 78a9215590SGreg Lehey.Pp 79a9215590SGreg Lehey.Dl "make gdbinit" 801159af41SGreg Lehey.Pp 811159af41SGreg LeheyThis command performs some transformations on the macros installed in 821159af41SGreg Lehey.Pa /usr/src/tools/debugscripts 831159af41SGreg Leheyto adapt them to the local environment. 848da02496SGreg Lehey.Ss "Inspecting the environment of the local machine" 85a9215590SGreg LeheyTo look at and change the contents of the memory of the system you are running 861159af41SGreg Leheyon, 87a9215590SGreg Lehey.Pp 88a9215590SGreg Lehey.Dl "gdb -k -wcore kernel.debug /dev/mem" 891159af41SGreg Lehey.Pp 901159af41SGreg LeheyIn this mode, you need the 911159af41SGreg Lehey.Fl k 921159af41SGreg Leheyflag to indicate to 93a9215590SGreg Lehey.Xr gdb 1 94a9215590SGreg Leheythat the 95a9215590SGreg Lehey.Dq "dump file" 961159af41SGreg Lehey.Pa /dev/mem 971159af41SGreg Leheyis a kernel data file. 981159af41SGreg LeheyYou can look at live data, and if you include the 991159af41SGreg Lehey.Fl wcore 1001159af41SGreg Leheyoption, you can change it at your peril. 1011159af41SGreg LeheyThe system does not stop (obviously), so a number of things will not work. 102a9215590SGreg LeheyYou can set breakpoints, but you cannot 103a9215590SGreg Lehey.Dq continue 104a9215590SGreg Leheyexecution, so they will not work. 1058da02496SGreg Lehey.Ss "Debugging a crash dump" 1068cfbf24fSGreg LeheyBy default, crash dumps are stored in the directory 1071159af41SGreg Lehey.Pa /var/crash . 1081159af41SGreg LeheyInvestigate them from the kernel build directory with: 109a9215590SGreg Lehey.Pp 110a9215590SGreg Lehey.Dl "gdb -k kernel.debug /var/crash/vmcore.29" 1111159af41SGreg Lehey.Pp 1121159af41SGreg LeheyIn this mode, the system is obviously stopped, so you can only look at it. 1138da02496SGreg Lehey.Ss "Debugging a live system with a remote link" 114a9215590SGreg LeheyIn the following discussion, the term 115a9215590SGreg Lehey.Dq "local system" 116a9215590SGreg Leheyrefers to the system running the debugger, and 117a9215590SGreg Lehey.Dq "remote system" 118a9215590SGreg Leheyrefers to the live system being debugged. 119783a364bSGreg Lehey.Pp 1201159af41SGreg LeheyTo debug a live system with a remote link, the kernel must be compiled with the 121783a364bSGreg Leheyoption 122a9215590SGreg Lehey.Cd "options DDB" . 1231159af41SGreg LeheyThe option 124a9215590SGreg Lehey.Cd "options BREAK_TO_DEBUGGER" 1251159af41SGreg Leheyenables the debugging machine stop the debugged machine once a connection has 1261159af41SGreg Leheybeen established by pressing 127a9215590SGreg Lehey.Ql ^C . 1288da02496SGreg Lehey.Ss "Debugging a live system with a remote serial link" 129a9215590SGreg LeheyWhen using a serial port for the remote link on the i386 platform, the serial 1301159af41SGreg Leheyport must be identified by setting the flag bit 1311159af41SGreg Lehey.Li 0x80 1321159af41SGreg Leheyfor the specified interface. 133a9215590SGreg LeheyGenerally, this port will also be used as a serial console (flag bit 134a9215590SGreg Lehey.Li 0x10 ) , 1351159af41SGreg Leheyso the entry in 1361159af41SGreg Lehey.Pa /boot/device.hints 1371159af41SGreg Leheyshould be: 138a9215590SGreg Lehey.Pp 139a9215590SGreg Lehey.Dl hint.sio.0.flags="0x90" 1408da02496SGreg Lehey.Ss "Debugging a live system with a remote firewire link" 1411159af41SGreg LeheyAs with serial debugging, to debug a live system with a firewire link, the 142783a364bSGreg Leheykernel must be compiled with the option 143a9215590SGreg Lehey.Cd "options DDB" . 1441159af41SGreg Lehey.Pp 1451159af41SGreg LeheyA number of steps must be performed to set up a firewire link: 146a9215590SGreg Lehey.Bl -bullet 1471159af41SGreg Lehey.It 148a9215590SGreg LeheyEnsure that both systems have 149a9215590SGreg Lehey.Xr firewire 4 150a9215590SGreg Leheysupport, and that the kernel of the remote system includes the 151a9215590SGreg Lehey.Xr dcons 4 152783a364bSGreg Leheyand 153a9215590SGreg Lehey.Xr dcons_crom 4 154783a364bSGreg Leheydrivers. 155a9215590SGreg LeheyIf they are not compiled into the kernel, load the KLDs: 156a9215590SGreg Lehey.Pp 157a9215590SGreg Lehey.Dl "kldload firewire" 158a9215590SGreg Lehey.Pp 159a9215590SGreg LeheyOn the remote system only: 160a9215590SGreg Lehey.Bd -literal -offset indent 161a9215590SGreg Leheykldload dcons 162a9215590SGreg Leheykldload dcons_crom 1631159af41SGreg Lehey.Ed 1641159af41SGreg Lehey.Pp 1651159af41SGreg LeheyYou should see something like this in the 166a9215590SGreg Lehey.Xr dmesg 8 167783a364bSGreg Leheyoutput of the remote system: 168a9215590SGreg Lehey.Bd -literal -offset indent 1691159af41SGreg Leheyfwohci0: BUS reset 1701159af41SGreg Leheyfwohci0: node_id=0x8800ffc0, gen=2, non CYCLEMASTER mode 1711159af41SGreg Leheyfirewire0: 2 nodes, maxhop <= 1, cable IRM = 1 1721159af41SGreg Leheyfirewire0: bus manager 1 1731159af41SGreg Leheyfirewire0: New S400 device ID:00c04f3226e88061 1741159af41SGreg Leheydcons_crom0: <dcons configuration ROM> on firewire0 1751159af41SGreg Leheydcons_crom0: bus_addr 0x22a000 1761159af41SGreg Lehey.Ed 1771159af41SGreg Lehey.Pp 178a9215590SGreg LeheyIt is a good idea to load these modules at boot time with the following entry in 1791159af41SGreg Lehey.Pa /boot/loader.conf : 1801159af41SGreg Lehey.Pp 181a9215590SGreg Lehey.Dl dcons_crom_enable="YES" 1821159af41SGreg Lehey.Pp 183783a364bSGreg LeheyThis ensures that all three modules are loaded. 184783a364bSGreg LeheyThere is no harm in loading 185a9215590SGreg Lehey.Xr dcons 4 186783a364bSGreg Leheyand 187a9215590SGreg Lehey.Xr dcons_crom 4 188a9215590SGreg Leheyon the local system, but if you only want to load the 189a9215590SGreg Lehey.Xr firewire 4 190a9215590SGreg Leheymodule, include the following in 191783a364bSGreg Lehey.Pa /boot/loader.conf : 192783a364bSGreg Lehey.Pp 193a9215590SGreg Lehey.Dl firewire_enable="YES" 1941159af41SGreg Lehey.It 1951159af41SGreg LeheyNext, use 196a9215590SGreg Lehey.Xr fwcontrol 8 197783a364bSGreg Leheyto find the firewire node corresponding to the remote machine. 198783a364bSGreg LeheyOn the local machine you might see: 199a9215590SGreg Lehey.Bd -literal -offset indent 200a9215590SGreg Lehey# fwcontrol 2011159af41SGreg Lehey2 devices (info_len=2) 2021159af41SGreg Leheynode EUI64 status 2031159af41SGreg Lehey 1 0x00c04f3226e88061 0 2041159af41SGreg Lehey 0 0x000199000003622b 1 2051159af41SGreg Lehey.Ed 2061159af41SGreg Lehey.Pp 2071159af41SGreg LeheyThe first node is always the local system, so in this case, node 0 is the remote 2081159af41SGreg Leheysystem. 2091159af41SGreg LeheyIf there are more than two systems, check from the other end to find which node 2101159af41SGreg Leheycorresponds to the remote system. 2116d8cac85SGreg LeheyOn the remote machine, it looks like this: 212a9215590SGreg Lehey.Bd -literal -offset indent 213a9215590SGreg Lehey# fwcontrol 2141159af41SGreg Lehey2 devices (info_len=2) 2151159af41SGreg Leheynode EUI64 status 2161159af41SGreg Lehey 0 0x000199000003622b 0 2171159af41SGreg Lehey 1 0x00c04f3226e88061 1 2181159af41SGreg Lehey.Ed 2191159af41SGreg Lehey.It 2201159af41SGreg LeheyNext, establish a firewire connection with 221a9215590SGreg Lehey.Xr dconschat 8 : 2221159af41SGreg Lehey.Pp 223a9215590SGreg Lehey.Dl "dconschat -br -G 5556 -t 0x000199000003622b" 2241159af41SGreg Lehey.Pp 225a9215590SGreg Lehey.Li 0x000199000003622b 226783a364bSGreg Leheyis the EUI64 address of the remote node, as determined from the output of 227a9215590SGreg Lehey.Xr fwcontrol 8 228783a364bSGreg Leheyabove. 229783a364bSGreg LeheyWhen started in this manner, 230a9215590SGreg Lehey.Xr dconschat 8 231783a364bSGreg Leheyestablishes a local tunnel connection from port 232a9215590SGreg Lehey.Li localhost:5556 233783a364bSGreg Leheyto the remote debugger. 234783a364bSGreg LeheyYou can also establish a console port connection with the 235783a364bSGreg Lehey.Fl C 236783a364bSGreg Leheyoption to the same invocation 237a9215590SGreg Lehey.Xr dconschat 8 . 238a9215590SGreg LeheySee the 239783a364bSGreg Lehey.Xr dconschat 8 240a9215590SGreg Leheymanpage for further details. 241783a364bSGreg Lehey.Pp 242a9215590SGreg LeheyThe 243a9215590SGreg Lehey.Xr dconschat 8 244a9215590SGreg Leheyutility 2456d8cac85SGreg Leheydoes not return control to the user. 246a9215590SGreg LeheyIt displays error messages and console output for the remote system, so it is a 247783a364bSGreg Leheygood idea to start it in its own window. 2486d8cac85SGreg Lehey.It 2496d8cac85SGreg LeheyFinally, establish connection: 250a9215590SGreg Lehey.Bd -literal -offset indent 251a9215590SGreg Lehey# gdb kernel.debug 2526d8cac85SGreg LeheyGNU gdb 5.2.1 (FreeBSD) 253a9215590SGreg Lehey.Em "(political statements omitted)" 2546d8cac85SGreg LeheyReady to go. Enter 'tr' to connect to the remote target 255118fd131SPhilip Paepswith /dev/cuad0, 'tr /dev/cuad1' to connect to a different port 2566d8cac85SGreg Leheyor 'trf portno' to connect to the remote target with the firewire 2576d8cac85SGreg Leheyinterface. portno defaults to 5556. 2586d8cac85SGreg Lehey 2596d8cac85SGreg LeheyType 'getsyms' after connection to load kld symbols. 2606d8cac85SGreg Lehey 26136a142c4SRuslan ErmilovIf you are debugging a local system, you can use 'kldsyms' instead 26236a142c4SRuslan Ermilovto load the kld symbols. That is a less obnoxious interface. 263a9215590SGreg Lehey(gdb) trf 2646d8cac85SGreg Lehey0xc21bd378 in ?? () 2656d8cac85SGreg Lehey.Ed 2666d8cac85SGreg Lehey.Pp 267783a364bSGreg LeheyThe 268a9215590SGreg Lehey.Ic trf 269783a364bSGreg Leheymacro assumes a connection on port 5556. 270783a364bSGreg LeheyIf you want to use a different port (by changing the invocation of 271a9215590SGreg Lehey.Xr dconschat 8 272783a364bSGreg Leheyabove), use the 273a9215590SGreg Lehey.Ic tr 274783a364bSGreg Leheymacro instead. 275783a364bSGreg LeheyFor example, if you want to use port 4711, run 276a9215590SGreg Lehey.Xr dconschat 8 277783a364bSGreg Leheylike this: 278783a364bSGreg Lehey.Pp 279a9215590SGreg Lehey.Dl "dconschat -br -G 4711 -t 0x000199000003622b" 2806d8cac85SGreg Lehey.Pp 281783a364bSGreg LeheyThen establish connection with: 282a9215590SGreg Lehey.Bd -literal -offset indent 283a9215590SGreg Lehey(gdb) tr localhost:4711 284783a364bSGreg Lehey0xc21bd378 in ?? () 285783a364bSGreg Lehey.Ed 2866d8cac85SGreg Lehey.El 2878da02496SGreg Lehey.Ss "Non-cooperative debugging a live system with a remote firewire link" 288279b7e12SGreg LeheyIn addition to the conventional debugging via firewire described in the previous 289279b7e12SGreg Leheysection, it is possible to debug a remote system without its cooperation, once 290279b7e12SGreg Leheyan initial connection has been established. 291279b7e12SGreg LeheyThis corresponds to debugging a local machine using 292279b7e12SGreg Lehey.Pa /dev/mem . 293279b7e12SGreg LeheyIt can be very useful if a system crashes and the debugger no longer responds. 294279b7e12SGreg LeheyTo use this method, set the 295a9215590SGreg Lehey.Xr sysctl 8 296279b7e12SGreg Leheyvariables 297279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_hi 298279b7e12SGreg Leheyand 299279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_lo 300a9215590SGreg Leheyto the upper and lower halves of the EUI64 ID of the remote system, 301a9215590SGreg Leheyrespectively. 302279b7e12SGreg LeheyFrom the previous example, the remote machine shows: 303a9215590SGreg Lehey.Bd -literal -offset indent 304a9215590SGreg Lehey# fwcontrol 305279b7e12SGreg Lehey2 devices (info_len=2) 306279b7e12SGreg Leheynode EUI64 status 307279b7e12SGreg Lehey 0 0x000199000003622b 0 308279b7e12SGreg Lehey 1 0x00c04f3226e88061 1 309279b7e12SGreg Lehey.Ed 310279b7e12SGreg Lehey.Pp 311279b7e12SGreg LeheyEnter: 312a9215590SGreg Lehey.Bd -literal -offset indent 313a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_hi=0x00019900 314279b7e12SGreg Leheyhw.firewire.fwmem.eui64_hi: 0 -> 104704 315a9215590SGreg Lehey# sysctl -w hw.firewire.fwmem.eui64_lo=0x0003622b 316279b7e12SGreg Leheyhw.firewire.fwmem.eui64_lo: 0 -> 221739 317279b7e12SGreg Lehey.Ed 318279b7e12SGreg Lehey.Pp 319279b7e12SGreg LeheyNote that the variables must be explicitly stated in hexadecimal. 320279b7e12SGreg LeheyAfter this, you can examine the remote machine's state with the following input: 321a9215590SGreg Lehey.Bd -literal -offset indent 322a9215590SGreg Lehey# gdb -k kernel.debug /dev/fwmem0.0 323279b7e12SGreg LeheyGNU gdb 5.2.1 (FreeBSD) 324a9215590SGreg Lehey.Em "(messages omitted)" 325279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons.ko...done. 326279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons.ko 327279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons_crom.ko...done. 328279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons_crom.ko 329279b7e12SGreg Lehey#0 sched_switch (td=0xc0922fe0) at /usr/src/sys/kern/sched_4bsd.c:621 330279b7e12SGreg Lehey0xc21bd378 in ?? () 331279b7e12SGreg Lehey.Ed 332279b7e12SGreg Lehey.Pp 333a9215590SGreg LeheyIn this case, it is not necessary to load the symbols explicitly. 334279b7e12SGreg LeheyThe remote system continues to run. 3351159af41SGreg Lehey.Sh COMMANDS 3361159af41SGreg LeheyThe user interface to 3371159af41SGreg Lehey.Nm 3381159af41SGreg Leheyis via 3391159af41SGreg Lehey.Xr gdb 1 , 3401159af41SGreg Leheyso 3411159af41SGreg Lehey.Xr gdb 1 3421159af41SGreg Leheycommands also work. 3431159af41SGreg LeheyThis section discusses only the extensions for kernel debugging that get 3441159af41SGreg Leheyinstalled in the kernel build directory. 3458da02496SGreg Lehey.Ss "Debugging environment" 3461159af41SGreg LeheyThe following macros manipulate the debugging environment: 347a9215590SGreg Lehey.Bl -tag -width indent 348a9215590SGreg Lehey.It Ic ddb 3491159af41SGreg LeheySwitch back to 350a9215590SGreg Lehey.Xr ddb 4 . 3511159af41SGreg LeheyThis command is only meaningful when performing remote debugging. 352a9215590SGreg Lehey.It Ic getsyms 3531159af41SGreg LeheyDisplay 354a9215590SGreg Lehey.Ic kldstat 3551159af41SGreg Leheyinformation for the target machine and invite user to paste it back in. 3561159af41SGreg LeheyThis is required because 357a9215590SGreg Lehey.Nm 3581159af41SGreg Leheydoes not allow data to be passed to shell scripts. 359a9215590SGreg LeheyIt is necessary for remote debugging and crash dumps; for local memory debugging 3601159af41SGreg Leheyuse 361a9215590SGreg Lehey.Ic kldsyms 3621159af41SGreg Leheyinstead. 363a9215590SGreg Lehey.It Ic kldsyms 364a9215590SGreg LeheyRead in the symbol tables for the debugging machine. 365a9215590SGreg LeheyThis does not work for 3661159af41SGreg Leheyremote debugging and crash dumps; use 367a9215590SGreg Lehey.Ic getsyms 3681159af41SGreg Leheyinstead. 369a9215590SGreg Lehey.It Ic tr Ar interface 3701159af41SGreg LeheyDebug a remote system via the specified serial or firewire interface. 371a9215590SGreg Lehey.It Ic tr0 3721159af41SGreg LeheyDebug a remote system via serial interface 373118fd131SPhilip Paeps.Pa /dev/cuad0 . 374a9215590SGreg Lehey.It Ic tr1 3751159af41SGreg LeheyDebug a remote system via serial interface 376118fd131SPhilip Paeps.Pa /dev/cuad1 . 377a9215590SGreg Lehey.It Ic trf 3781159af41SGreg LeheyDebug a remote system via firewire interface at default port 5556. 3791159af41SGreg Lehey.El 3801159af41SGreg Lehey.Pp 3811159af41SGreg LeheyThe commands 382a9215590SGreg Lehey.Ic tr0 , tr1 3831159af41SGreg Leheyand 384a9215590SGreg Lehey.Ic trf 3851159af41SGreg Leheyare convenience commands which invoke 386a9215590SGreg Lehey.Ic tr . 3878da02496SGreg Lehey.Ss "The current process environment" 3881159af41SGreg LeheyThe following macros are convenience functions intended to make things easier 3891159af41SGreg Leheythan the standard 390a9215590SGreg Lehey.Xr gdb 1 3911159af41SGreg Leheycommands. 392a9215590SGreg Lehey.Bl -tag -width indent 393a9215590SGreg Lehey.It Ic f0 3941159af41SGreg LeheySelect stack frame 0 and show assembler-level details. 395a9215590SGreg Lehey.It Ic f1 3961159af41SGreg LeheySelect stack frame 1 and show assembler-level details. 397a9215590SGreg Lehey.It Ic f2 3981159af41SGreg LeheySelect stack frame 2 and show assembler-level details. 399a9215590SGreg Lehey.It Ic f3 4001159af41SGreg LeheySelect stack frame 3 and show assembler-level details. 401a9215590SGreg Lehey.It Ic f4 4021159af41SGreg LeheySelect stack frame 4 and show assembler-level details. 403a9215590SGreg Lehey.It Ic f5 4041159af41SGreg LeheySelect stack frame 5 and show assembler-level details. 405a9215590SGreg Lehey.It Ic xb 4061159af41SGreg LeheyShow 12 words in hex, starting at current 4071159af41SGreg Lehey.Va ebp 4081159af41SGreg Leheyvalue. 409a9215590SGreg Lehey.It Ic xi 4101159af41SGreg LeheyList the next 10 instructions from the current 4111159af41SGreg Lehey.Va eip 4121159af41SGreg Leheyvalue. 413a9215590SGreg Lehey.It Ic xp 4141159af41SGreg LeheyShow the register contents and the first four parameters of the current stack 4151159af41SGreg Leheyframe. 416a9215590SGreg Lehey.It Ic xp0 4171159af41SGreg LeheyShow the first parameter of current stack frame in various formats. 418a9215590SGreg Lehey.It Ic xp1 4191159af41SGreg LeheyShow the second parameter of current stack frame in various formats. 420a9215590SGreg Lehey.It Ic xp2 4211159af41SGreg LeheyShow the third parameter of current stack frame in various formats. 422a9215590SGreg Lehey.It Ic xp3 4231159af41SGreg LeheyShow the fourth parameter of current stack frame in various formats. 424a9215590SGreg Lehey.It Ic xp4 4251159af41SGreg LeheyShow the fifth parameter of current stack frame in various formats. 426a9215590SGreg Lehey.It Ic xs 4271159af41SGreg LeheyShow the last 12 words on stack in hexadecimal. 428a9215590SGreg Lehey.It Ic xxp 4291159af41SGreg LeheyShow the register contents and the first ten parameters. 430a9215590SGreg Lehey.It Ic z 4311159af41SGreg LeheySingle step 1 instruction (over calls) and show next instruction. 432a9215590SGreg Lehey.It Ic zs 4331159af41SGreg LeheySingle step 1 instruction (through calls) and show next instruction. 4341159af41SGreg Lehey.El 4358da02496SGreg Lehey.Ss "Examining other processes" 4361159af41SGreg LeheyThe following macros access other processes. 437a9215590SGreg LeheyThe 438a9215590SGreg Lehey.Nm 439a9215590SGreg Leheydebugger 4401159af41SGreg Leheydoes not understand the concept of multiple processes, so they effectively 4411159af41SGreg Leheybypass the entire 442a9215590SGreg Lehey.Nm 4431159af41SGreg Leheyenvironment. 444a9215590SGreg Lehey.Bl -tag -width indent 445a9215590SGreg Lehey.It Ic btp Ar pid 4461159af41SGreg LeheyShow a backtrace for the process 447a9215590SGreg Lehey.Ar pid . 448a9215590SGreg Lehey.It Ic btpa 4491159af41SGreg LeheyShow backtraces for all processes in the system. 450a9215590SGreg Lehey.It Ic btpp 4511159af41SGreg LeheyShow a backtrace for the process previously selected with 452a9215590SGreg Lehey.Ic defproc . 453a9215590SGreg Lehey.It Ic btr Ar ebp 4541159af41SGreg LeheyShow a backtrace from the 455a9215590SGreg Lehey.Ar ebp 456a9215590SGreg Leheyaddress specified. 457a9215590SGreg Lehey.It Ic defproc Ar pid 4581159af41SGreg LeheySpecify the PID of the process for some other commands in this section. 459a9215590SGreg Lehey.It Ic fr Ar frame 4601159af41SGreg LeheyShow frame 461a9215590SGreg Lehey.Ar frame 4621159af41SGreg Leheyof the stack of the process previously selected with 463a9215590SGreg Lehey.Ic defproc . 464a9215590SGreg Lehey.It Ic pcb Ar proc 465a9215590SGreg LeheyShow some PCB contents of the process 4661159af41SGreg Lehey.Ar proc . 4671159af41SGreg Lehey.El 4688da02496SGreg Lehey.Ss "Examining data structures" 4691159af41SGreg LeheyYou can use standard 470a9215590SGreg Lehey.Xr gdb 1 471a9215590SGreg Leheycommands to look at most data structures. 472a9215590SGreg LeheyThe macros in this section are 4731159af41SGreg Leheyconvenience functions which typically display the data in a more readable 4741159af41SGreg Leheyformat, or which omit less interesting parts of the structure. 475a9215590SGreg Lehey.Bl -tag -width indent 476a9215590SGreg Lehey.It Ic bp 4771159af41SGreg LeheyShow information about the buffer header pointed to by the variable 4781159af41SGreg Lehey.Va bp 4791159af41SGreg Leheyin the current frame. 480a9215590SGreg Lehey.It Ic bpd 4811159af41SGreg LeheyShow the contents 482a9215590SGreg Lehey.Pq Vt "char *" 4831159af41SGreg Leheyof 4841159af41SGreg Lehey.Va bp->data 4851159af41SGreg Leheyin the current frame. 486a9215590SGreg Lehey.It Ic bpl 4871159af41SGreg LeheyShow detailed information about the buffer header 488a9215590SGreg Lehey.Pq Vt "struct bp" 4891159af41SGreg Leheypointed at by the local variable 4901159af41SGreg Lehey.Va bp . 491a9215590SGreg Lehey.It Ic bpp Ar bp 4921159af41SGreg LeheyShow summary information about the buffer header 493a9215590SGreg Lehey.Pq Vt "struct bp" 4941159af41SGreg Leheypointed at by the parameter 495a9215590SGreg Lehey.Ar bp . 496a9215590SGreg Lehey.It Ic bx 4971159af41SGreg LeheyPrint a number of fields from the buffer header pointed at in by the pointer 498a9215590SGreg Lehey.Ar bp 4991159af41SGreg Leheyin the current environment. 500a9215590SGreg Lehey.It Ic vdev 501a9215590SGreg LeheyShow some information of the 502a9215590SGreg Lehey.Vt vnode 503a9215590SGreg Leheypointed to by the local variable 5041159af41SGreg Lehey.Va vp . 5051159af41SGreg Lehey.El 5068da02496SGreg Lehey.Ss "Miscellaneous macros" 507a9215590SGreg Lehey.Bl -tag -width indent 508a9215590SGreg Lehey.It Ic checkmem 5091159af41SGreg LeheyCheck unallocated memory for modifications. 5101159af41SGreg LeheyThis assumes that the kernel has been compiled with 511*50d922a0SGlen Barber.Cd "options DIAGNOSTIC" . 5121159af41SGreg LeheyThis causes the contents of free memory to be set to 5131159af41SGreg Lehey.Li 0xdeadc0de . 514a9215590SGreg Lehey.It Ic dmesg 515a9215590SGreg LeheyPrint the system message buffer. 516a9215590SGreg LeheyThis corresponds to the 517783a364bSGreg Lehey.Xr dmesg 8 518a9215590SGreg Leheyutility. 5193f333d6bSGreg LeheyThis macro used to be called 5203f333d6bSGreg Lehey.Ic msgbuf . 521a9215590SGreg LeheyIt can take a very long time over a serial line, 522a9215590SGreg Leheyand it is even slower via firewire 5231159af41SGreg Leheyor local memory due to inefficiencies in 524a9215590SGreg Lehey.Nm . 5253f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start 5263f333d6bSGreg Lehey.Nm 5273f333d6bSGreg Leheyto access the message buffer: instead, use an appropriate variation of 5283f333d6bSGreg Lehey.Bd -literal -offset indent 5293f333d6bSGreg Leheydmesg -M /var/crash/vmcore.0 -N kernel.debug 5303f333d6bSGreg Leheydmesg -M /dev/fwmem0.0 -N kernel.debug 5313f333d6bSGreg Lehey.Ed 532a9215590SGreg Lehey.It Ic kldstat 533a9215590SGreg LeheyEquivalent of the 534a9215590SGreg Lehey.Xr kldstat 8 535a9215590SGreg Leheyutility without options. 536a9215590SGreg Lehey.It Ic pname 5371159af41SGreg LeheyPrint the command name of the current process. 538a9215590SGreg Lehey.It Ic ps 5391159af41SGreg LeheyShow process status. 5401159af41SGreg LeheyThis corresponds in concept, but not in appearance, to the 541a9215590SGreg Lehey.Xr ps 1 542a9215590SGreg Leheyutility. 5433f333d6bSGreg LeheyWhen debugging a crash dump or over firewire, it is not necessary to start 5443f333d6bSGreg Lehey.Nm 5453f333d6bSGreg Leheyto display the 5463f333d6bSGreg Lehey.Xr ps 1 5473f333d6bSGreg Leheyoutput: instead, use an appropriate variation of 5483f333d6bSGreg Lehey.Bd -literal -offset indent 5493f333d6bSGreg Leheyps -M /var/crash/vmcore.0 -N kernel.debug 5503f333d6bSGreg Leheyps -M /dev/fwmem0.0 -N kernel.debug 5513f333d6bSGreg Lehey.Ed 552a9215590SGreg Lehey.It Ic y 553a9215590SGreg LeheyKludge for writing macros. 554a9215590SGreg LeheyWhen writing macros, it is convenient to paste them 5551159af41SGreg Leheyback into the 556a9215590SGreg Lehey.Nm 557a9215590SGreg Leheywindow. 558a9215590SGreg LeheyUnfortunately, if the macro is already defined, 559a9215590SGreg Lehey.Nm 5601159af41SGreg Leheyinsists on asking 5611159af41SGreg Lehey.Pp 562a9215590SGreg Lehey.Dl "Redefine foo?" 563a9215590SGreg Lehey.Pp 564a9215590SGreg LeheyIt will not give up until you answer 565a9215590SGreg Lehey.Ql y . 566a9215590SGreg LeheyThis command is that answer. 567a9215590SGreg LeheyIt does nothing else except to print a warning 5681159af41SGreg Leheymessage to remind you to remove it again. 5691159af41SGreg Lehey.El 5701159af41SGreg Lehey.Sh SEE ALSO 5713f333d6bSGreg Lehey.Xr gdb 1 , 5723f333d6bSGreg Lehey.Xr ps 1 , 573a1db2f59SGreg Lehey.Xr ddb 4 , 574a1db2f59SGreg Lehey.Xr firewire 4 , 575a1db2f59SGreg Lehey.Xr dconschat 8 , 576a1db2f59SGreg Lehey.Xr dmesg 8 , 577a1db2f59SGreg Lehey.Xr fwcontrol 8 , 578a1db2f59SGreg Lehey.Xr kldload 8 5799cbda590SRuslan Ermilov.Sh AUTHORS 5809cbda590SRuslan ErmilovThis man page was written by 5819cbda590SRuslan Ermilov.An "Greg Lehey" Aq grog@FreeBSD.org . 5821159af41SGreg Lehey.Sh BUGS 583783a364bSGreg LeheyThe 584a9215590SGreg Lehey.Xr gdb 1 585a9215590SGreg Leheydebugger 586a9215590SGreg Leheywas never designed to debug kernels, and it is not a very good match. 587a9215590SGreg LeheyMany problems exist. 588a9215590SGreg Lehey.Pp 589a9215590SGreg LeheyThe 590a9215590SGreg Lehey.Nm 591783a364bSGreg Leheyimplementation is very inefficient, and many operations are slow. 592a9215590SGreg Lehey.Pp 593783a364bSGreg LeheySerial debugging is even slower, and race conditions can make it difficult to 594a9215590SGreg Leheyrun the link at more than 9600 bps. 595a9215590SGreg LeheyFirewire connections do not have this problem. 596a9215590SGreg Lehey.Pp 597a9215590SGreg LeheyThe debugging macros 598*50d922a0SGlen Barber.Dq "just grown" . 5991159af41SGreg LeheyIn general, the person who wrote them did so while looking for a specific 6001159af41SGreg Leheyproblem, so they may not be general enough, and they may behave badly when used 6011159af41SGreg Leheyin ways for which they were not intended, even if those ways make sense. 602a9215590SGreg Lehey.Pp 6031159af41SGreg LeheyMany of these commands only work on the ia32 architecture. 604