11159af41SGreg Lehey.\" $FreeBSD$ 21159af41SGreg Lehey.Dd December 30, 2003 31159af41SGreg Lehey.Dt GDB 4 41159af41SGreg Lehey.Os 51159af41SGreg Lehey.Sh NAME 61159af41SGreg Lehey.Nm gdb 71159af41SGreg Lehey.Nd external kernel debugger 81159af41SGreg Lehey.Sh SYNOPSIS 91159af41SGreg Lehey.Cd makeoptions DEBUG=-g 101159af41SGreg Lehey.Cd options DDB 111159af41SGreg Lehey.Cd options GDB_REMOTE_CHAT 121159af41SGreg Lehey.Pp 131159af41SGreg LeheyTo prevent activation of the debugger on kernel 141159af41SGreg Lehey.Xr panic 9 : 151159af41SGreg Lehey.Cd options DDB_UNATTENDED 161159af41SGreg Lehey.Sh DESCRIPTION 171159af41SGreg LeheyThe 181159af41SGreg Lehey.Nm 191159af41SGreg Leheykernel debugger is a variation of 201159af41SGreg Lehey.Xr gdb 1 211159af41SGreg Leheywhich understands some aspects of the 221159af41SGreg Lehey.Fx 231159af41SGreg Leheykernel environment. It can be used in a number of ways: 241159af41SGreg Lehey.Pp 251159af41SGreg Lehey.Bl -bullet -offset indent -compact 261159af41SGreg Lehey.It 271159af41SGreg LeheyIt can be used to debug another system interactively via a serial or firewire 281159af41SGreg Leheylink. In this mode, the processor can be stopped and single stepped. 291159af41SGreg Lehey.It 301159af41SGreg LeheyIt can be used to examine the memory of the processor on which it runs. 311159af41SGreg Lehey.It 321159af41SGreg LeheyIt can be used to analyse a processor dump after a panic. 331159af41SGreg Lehey.El 341159af41SGreg Lehey.Pp 351159af41SGreg LeheyWhen used for remote debugging, 361159af41SGreg Lehey.Nm 371159af41SGreg Leheyrequires the presence of the 381159af41SGreg Lehey.Xr ddb 4 391159af41SGreg Leheykernel debugger. 401159af41SGreg LeheyCommands exist to switch between 411159af41SGreg Lehey.Nm 421159af41SGreg Leheyand 431159af41SGreg Lehey.Xr ddb 4 . 441159af41SGreg Lehey.Sh PREPARING FOR DEBUGGING 451159af41SGreg LeheyWhen debugging kernels, it is practically essential to have built a kernel with 461159af41SGreg Leheydebugging symbols 471159af41SGreg Lehey.Cd ( makeoptions DEBUG=-g ). 481159af41SGreg LeheyIt's easiest to perform operations from the kernel build directory, by default 491159af41SGreg Lehey.Pa /usr/obj/sys/GENERIC . 501159af41SGreg Lehey.Pp 511159af41SGreg LeheyFirst, ensure you have a copy of the debug macros in the directory: 521159af41SGreg Lehey.Bd -literal -offset 5m 531159af41SGreg Lehey# \f(CBmake gdbinit\fP 541159af41SGreg Lehey.Ed 551159af41SGreg Lehey.Pp 561159af41SGreg LeheyThis command performs some transformations on the macros installed in 571159af41SGreg Lehey.Pa /usr/src/tools/debugscripts 581159af41SGreg Leheyto adapt them to the local environment. 591159af41SGreg Lehey.Ss Debugging a local machine 601159af41SGreg LeheyTo look at and change the contents of the memory of the system you're running 611159af41SGreg Leheyon, 621159af41SGreg Lehey.Bd -literal -offset 5m 631159af41SGreg Lehey# \f(CBgdb -k -wcore kernel.debug /dev/mem\fP 641159af41SGreg Lehey.Ed 651159af41SGreg Lehey.Pp 661159af41SGreg LeheyIn this mode, you need the 671159af41SGreg Lehey.Fl k 681159af41SGreg Leheyflag to indicate to 691159af41SGreg Lehey.Nm gdb 701159af41SGreg Leheythat the ``dump file'' 711159af41SGreg Lehey.Pa /dev/mem 721159af41SGreg Leheyis a kernel data file. 731159af41SGreg LeheyYou can look at live data, and if you include the 741159af41SGreg Lehey.Fl wcore 751159af41SGreg Leheyoption, you can change it at your peril. 761159af41SGreg LeheyThe system does not stop (obviously), so a number of things will not work. 771159af41SGreg LeheyYou can set breakpoints, but you can't ``continue'' execution, so they won't 781159af41SGreg Leheywork. 791159af41SGreg Lehey.Ss Debugging a crash dump 801159af41SGreg LeheyBy default, crash dumps are stored in the directory 811159af41SGreg Lehey.Pa /var/crash . 821159af41SGreg LeheyInvestigate them from the kernel build directory with: 831159af41SGreg Lehey.Bd -literal -offset 5m 841159af41SGreg Lehey# \f(CBgdb -k kernel.debug /var/crash/vmcore.29\fP 851159af41SGreg Lehey.Ed 861159af41SGreg Lehey.Pp 871159af41SGreg LeheyIn this mode, the system is obviously stopped, so you can only look at it. 881159af41SGreg Lehey.Ss Debugging a live system with a remote link 89783a364bSGreg LeheyIn the following discussion, the term ``local system'' refers to the system 90783a364bSGreg Leheyrunning the debugger, and ``remote system'' refers to the live system being 91783a364bSGreg Leheydebugged. 92783a364bSGreg Lehey.Pp 931159af41SGreg LeheyTo debug a live system with a remote link, the kernel must be compiled with the 94783a364bSGreg Leheyoption 95783a364bSGreg Lehey.Cd options DDB . 961159af41SGreg LeheyThe option 971159af41SGreg Lehey.Cd options BREAK_TO_DEBUGGER 981159af41SGreg Leheyenables the debugging machine stop the debugged machine once a connection has 991159af41SGreg Leheybeen established by pressing 1001159af41SGreg Lehey.Li ^C. 1011159af41SGreg Lehey.Ss Debugging a live system with a remote serial link 1021159af41SGreg LeheyWhen using a serial port for the remote link on the i386 platform the serial 1031159af41SGreg Leheyport must be identified by setting the flag bit 1041159af41SGreg Lehey.Li 0x80 1051159af41SGreg Leheyfor the specified interface. 1061159af41SGreg LeheyGenerally this port will also be used as a serial console (flag bit 1071159af41SGreg Lehey.Li 0x10a), 1081159af41SGreg Leheyso the entry in 1091159af41SGreg Lehey.Pa /boot/device.hints 1101159af41SGreg Leheyshould be: 1111159af41SGreg Lehey.Bd -literal -offset 5m 1121159af41SGreg Leheyhint.sio.0.flags="0x90" 1131159af41SGreg Lehey.Ed 114783a364bSGreg Lehey.Pp 115783a364bSGreg LeheyTo share a console and debug connection on a serial line, use the 116783a364bSGreg Lehey.Cd options GDB_REMOTE_CHAT 117783a364bSGreg Leheyoption. 1181159af41SGreg Lehey.Ss Debugging a live system with a remote firewire link 1191159af41SGreg LeheyAs with serial debugging, to debug a live system with a firewire link, the 120783a364bSGreg Leheykernel must be compiled with the option 121783a364bSGreg Lehey.Cd options DDB . 122783a364bSGreg LeheyThe 123783a364bSGreg Lehey.Cd options GDB_REMOTE_CHAT 124783a364bSGreg Leheyis not necessary, since the firewire implementation uses separate ports for the 125783a364bSGreg Leheyconsole and debug connection. 1261159af41SGreg Lehey.Pp 1271159af41SGreg LeheyA number of steps must be performed to set up a firewire link: 1281159af41SGreg Lehey.Pp 1291159af41SGreg Lehey.Bl -bullet -offset indent -compact 1301159af41SGreg Lehey.It 131783a364bSGreg LeheyEnsure that both systems have firewire support, and that the kernel of the 132783a364bSGreg Leheyremote system includes the 133783a364bSGreg Lehey.Nm dcons 134783a364bSGreg Leheyand 135783a364bSGreg Lehey.Nm dcons_crom 136783a364bSGreg Leheydrivers. 137783a364bSGreg LeheyIf they're not compiled into the kernel, load the klds: 1381159af41SGreg Lehey.Bd -literal -offset 5m 139783a364bSGreg Lehey# \f(CBkldload firewire\fP 140783a364bSGreg Lehey# \f(CBkldload dcons\fP \fI(remote system only)\fP\/ 141783a364bSGreg Lehey# \f(CBkldload dcons_crom\fP \fI(remote system only)\fP\/ 1421159af41SGreg Lehey.Ed 1431159af41SGreg Lehey.Pp 1441159af41SGreg LeheyYou should see something like this in the 1451159af41SGreg Lehey.Nm dmesg 146783a364bSGreg Leheyoutput of the remote system: 1471159af41SGreg Lehey.Pp 1481159af41SGreg Lehey.Bd -literal -offset 5m 1491159af41SGreg Leheyfwohci0: BUS reset 1501159af41SGreg Leheyfwohci0: node_id=0x8800ffc0, gen=2, non CYCLEMASTER mode 1511159af41SGreg Leheyfirewire0: 2 nodes, maxhop <= 1, cable IRM = 1 1521159af41SGreg Leheyfirewire0: bus manager 1 1531159af41SGreg Leheyfirewire0: New S400 device ID:00c04f3226e88061 1541159af41SGreg Leheydcons_crom0: <dcons configuration ROM> on firewire0 1551159af41SGreg Leheydcons_crom0: bus_addr 0x22a000 1561159af41SGreg Lehey.Ed 1571159af41SGreg Lehey.Pp 1581159af41SGreg LeheyIt's a good idea to load these modules at boot time with the following entry in 1591159af41SGreg Lehey.Pa /boot/loader.conf : 1601159af41SGreg Lehey.Pp 1611159af41SGreg Lehey.Bd -literal -offset 5m 162783a364bSGreg Leheydcons_crom_enable=YES 1631159af41SGreg Lehey.Ed 1641159af41SGreg Lehey.Pp 165783a364bSGreg LeheyThis ensures that all three modules are loaded. 166783a364bSGreg LeheyThere is no harm in loading 167783a364bSGreg Lehey.Nm dcons 168783a364bSGreg Leheyand 169783a364bSGreg Lehey.Nm dcons_crom 170783a364bSGreg Leheyon the local system, but if you only want to load the firewire module, include 171783a364bSGreg Leheythe following in 172783a364bSGreg Lehey.Pa /boot/loader.conf : 173783a364bSGreg Lehey.Pp 174783a364bSGreg Lehey.Bd -literal -offset 5m 175783a364bSGreg Leheyfirewire_enable=YES 176783a364bSGreg Lehey.Ed 177783a364bSGreg Lehey.Pp 178783a364bSGreg Lehey.Pp 1791159af41SGreg Lehey.It 1801159af41SGreg LeheyNext, use 1811159af41SGreg Lehey.Nm fwcontrol 182783a364bSGreg Leheyto find the firewire node corresponding to the remote machine. 183783a364bSGreg LeheyOn the local machine you might see: 1841159af41SGreg Lehey.Pp 1851159af41SGreg Lehey.Bd -literal -offset 5m 1861159af41SGreg Lehey# \f(CBfwcontrol\fP 1871159af41SGreg Lehey2 devices (info_len=2) 1881159af41SGreg Leheynode EUI64 status 1891159af41SGreg Lehey 1 0x00c04f3226e88061 0 1901159af41SGreg Lehey 0 0x000199000003622b 1 1911159af41SGreg Lehey.Ed 1921159af41SGreg Lehey.Pp 1931159af41SGreg LeheyThe first node is always the local system, so in this case, node 0 is the remote 1941159af41SGreg Leheysystem. 1951159af41SGreg LeheyIf there are more than two systems, check from the other end to find which node 1961159af41SGreg Leheycorresponds to the remote system. 1976d8cac85SGreg LeheyOn the remote machine, it looks like this: 1981159af41SGreg Lehey.Pp 1991159af41SGreg Lehey.Bd -literal -offset 5m 2001159af41SGreg Lehey# \f(CBfwcontrol\fP 2011159af41SGreg Lehey2 devices (info_len=2) 2021159af41SGreg Leheynode EUI64 status 2031159af41SGreg Lehey 0 0x000199000003622b 0 2041159af41SGreg Lehey 1 0x00c04f3226e88061 1 2051159af41SGreg Lehey.Ed 2061159af41SGreg Lehey.Pp 2071159af41SGreg Lehey.It 2081159af41SGreg LeheyNext, establish a firewire connection with 209783a364bSGreg Lehey.Nm dconschat : 2101159af41SGreg Lehey.Pp 2111159af41SGreg Lehey.Bd -literal -offset 5m 212783a364bSGreg Lehey# \f(CBdconschat -br -G 5556 -t 0x000199000003622b\fP 2131159af41SGreg Lehey.Ed 2141159af41SGreg Lehey.Pp 215783a364bSGreg Lehey.Ar 0x000199000003622b 216783a364bSGreg Leheyis the EUI64 address of the remote node, as determined from the output of 2176d8cac85SGreg Lehey.Nm fwcontrol 218783a364bSGreg Leheyabove. 219783a364bSGreg LeheyWhen started in this manner, 220783a364bSGreg Lehey.Nm dconschat 221783a364bSGreg Leheyestablishes a local tunnel connection from port 222783a364bSGreg Lehey.Ar localhost:5556 223783a364bSGreg Leheyto the remote debugger. 224783a364bSGreg LeheyYou can also establish a console port connection with the 225783a364bSGreg Lehey.Fl C 226783a364bSGreg Leheyoption to the same invocation 227783a364bSGreg Lehey.Nm dconschat . 228783a364bSGreg LeheySee 229783a364bSGreg Lehey.Xr dconschat 8 230783a364bSGreg Leheyfor further details. 231783a364bSGreg Lehey.Pp 232783a364bSGreg Lehey.Nm dconschat 2336d8cac85SGreg Leheydoes not return control to the user. 234783a364bSGreg LeheyIt displays error messages and console output for the remote system, so it's a 235783a364bSGreg Leheygood idea to start it in its own window. 2366d8cac85SGreg Lehey.Pp 2376d8cac85SGreg Lehey.It 2386d8cac85SGreg LeheyFinally, establish connection: 2396d8cac85SGreg Lehey.Bd -literal -offset 5m 2406d8cac85SGreg Lehey# \f(CBgdb kernel.debug\fP 2416d8cac85SGreg LeheyGNU gdb 5.2.1 (FreeBSD) 242279b7e12SGreg Lehey\&\fI(political statements omitted)\fP\/ 2436d8cac85SGreg LeheyReady to go. Enter 'tr' to connect to the remote target 2446d8cac85SGreg Leheywith /dev/cuaa0, 'tr /dev/cuaa1' to connect to a different port 2456d8cac85SGreg Leheyor 'trf portno' to connect to the remote target with the firewire 2466d8cac85SGreg Leheyinterface. portno defaults to 5556. 2476d8cac85SGreg Lehey 2486d8cac85SGreg LeheyType 'getsyms' after connection to load kld symbols. 2496d8cac85SGreg Lehey 2506d8cac85SGreg LeheyIf you're debugging a local system, you can use 'kldsyms' instead 2516d8cac85SGreg Leheyto load the kld symbols. That's a less obnoxious interface. 2526d8cac85SGreg Lehey(gdb) \f(CBtrf\fP 2536d8cac85SGreg Lehey0xc21bd378 in ?? () 2546d8cac85SGreg Lehey.Ed 2556d8cac85SGreg Lehey.Pp 256783a364bSGreg LeheyThe 257783a364bSGreg Lehey.Nm trf 258783a364bSGreg Leheymacro assumes a connection on port 5556. 259783a364bSGreg LeheyIf you want to use a different port (by changing the invocation of 260783a364bSGreg Lehey.Nm dconschat 261783a364bSGreg Leheyabove), use the 262783a364bSGreg Lehey.Nm tr 263783a364bSGreg Leheymacro instead. 264783a364bSGreg LeheyFor example, if you want to use port 4711, run 265783a364bSGreg Lehey.Nm dconschat 266783a364bSGreg Leheylike this: 267783a364bSGreg Lehey.Pp 2686d8cac85SGreg Lehey.Bd -literal -offset 5m 269783a364bSGreg Lehey# \f(CBdconschat -br -G 4711 -t 0x000199000003622b\fP 2706d8cac85SGreg Lehey.Ed 2716d8cac85SGreg Lehey.Pp 272783a364bSGreg LeheyThen establish connection with: 2736d8cac85SGreg Lehey.Pp 2746d8cac85SGreg Lehey.Bd -literal -offset 5m 275783a364bSGreg Lehey(gdb) \f(CBtr localhost:4711\fP 276783a364bSGreg Lehey0xc21bd378 in ?? () 277783a364bSGreg Lehey.Ed 278783a364bSGreg Lehey.Pp 2796d8cac85SGreg Lehey.El 280279b7e12SGreg Lehey.Ss Non-cooperative debugging a live system with a remote firewire link 281279b7e12SGreg LeheyIn addition to the conventional debugging via firewire described in the previous 282279b7e12SGreg Leheysection, it is possible to debug a remote system without its cooperation, once 283279b7e12SGreg Leheyan initial connection has been established. 284279b7e12SGreg LeheyThis corresponds to debugging a local machine using 285279b7e12SGreg Lehey.Pa /dev/mem . 286279b7e12SGreg LeheyIt can be very useful if a system crashes and the debugger no longer responds. 287279b7e12SGreg LeheyTo use this method, set the 288279b7e12SGreg Lehey.Nm sysctl 289279b7e12SGreg Leheyvariables 290279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_hi 291279b7e12SGreg Leheyand 292279b7e12SGreg Lehey.Va hw.firewire.fwmem.eui64_lo 293279b7e12SGreg Leheyto the upper and lower halves of the EUI64 ID of the remote system respectively. 294279b7e12SGreg LeheyFrom the previous example, the remote machine shows: 295279b7e12SGreg Lehey.Bd -literal -offset 5m 296279b7e12SGreg Lehey# \f(CBfwcontrol\fP 297279b7e12SGreg Lehey2 devices (info_len=2) 298279b7e12SGreg Leheynode EUI64 status 299279b7e12SGreg Lehey 0 0x000199000003622b 0 300279b7e12SGreg Lehey 1 0x00c04f3226e88061 1 301279b7e12SGreg Lehey.Ed 302279b7e12SGreg Lehey.Pp 303279b7e12SGreg LeheyEnter: 304279b7e12SGreg Lehey.Bd -literal -offset 5m 305279b7e12SGreg Lehey# \f(CBsysctl -w hw.firewire.fwmem.eui64_hi=0x00019900\fP 306279b7e12SGreg Leheyhw.firewire.fwmem.eui64_hi: 0 -> 104704 307279b7e12SGreg Lehey# \f(CBsysctl -w hw.firewire.fwmem.eui64_lo=0x0003622b\fP 308279b7e12SGreg Leheyhw.firewire.fwmem.eui64_lo: 0 -> 221739 309279b7e12SGreg Lehey.Ed 310279b7e12SGreg Lehey.Pp 311279b7e12SGreg LeheyNote that the variables must be explicitly stated in hexadecimal. 312279b7e12SGreg LeheyAfter this, you can examine the remote machine's state with the following input: 313279b7e12SGreg Lehey.Bd -literal -offset 5m 314279b7e12SGreg Lehey# \f(CBgdb -k kernel.debug /dev/fwmem0.0\fP 315279b7e12SGreg LeheyGNU gdb 5.2.1 (FreeBSD) 316279b7e12SGreg Lehey\&\fI(messages omitted)\fP\/ 317279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons.ko...done. 318279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons.ko 319279b7e12SGreg LeheyReading symbols from /boot/kernel/dcons_crom.ko...done. 320279b7e12SGreg LeheyLoaded symbols for /boot/kernel/dcons_crom.ko 321279b7e12SGreg Lehey#0 sched_switch (td=0xc0922fe0) at /usr/src/sys/kern/sched_4bsd.c:621 322279b7e12SGreg Lehey0xc21bd378 in ?? () 323279b7e12SGreg Lehey.Ed 324279b7e12SGreg Lehey.Pp 325279b7e12SGreg LeheyIn this case, it's not necessary to load the symbols explicitly. 326279b7e12SGreg LeheyThe remote system continues to run. 3271159af41SGreg Lehey.Sh COMMANDS 3281159af41SGreg LeheyThe user interface to 3291159af41SGreg Lehey.Nm 3301159af41SGreg Leheyis via 3311159af41SGreg Lehey.Xr gdb 1 , 3321159af41SGreg Leheyso 3331159af41SGreg Lehey.Xr gdb 1 3341159af41SGreg Leheycommands also work. 3351159af41SGreg LeheyThis section discusses only the extensions for kernel debugging that get 3361159af41SGreg Leheyinstalled in the kernel build directory. 3371159af41SGreg Lehey.Ss "Debugging Environment" 3381159af41SGreg LeheyThe following macros manipulate the debugging environment: 3391159af41SGreg Lehey.Bl -ohang -offset 3m 3401159af41SGreg Lehey.It Cm ddb 3411159af41SGreg LeheySwitch back to 3421159af41SGreg Lehey.Nm ddb . 3431159af41SGreg LeheyThis command is only meaningful when performing remote debugging. 3441159af41SGreg Lehey.It Cm getsyms 3451159af41SGreg LeheyDisplay 3461159af41SGreg Lehey.Nm kldstat 3471159af41SGreg Leheyinformation for the target machine and invite user to paste it back in. 3481159af41SGreg LeheyThis is required because 3491159af41SGreg Lehey.Nm gdb 3501159af41SGreg Leheydoes not allow data to be passed to shell scripts. 3511159af41SGreg LeheyIt's necessary for remote debugging and crash dumps; for local memory debugging 3521159af41SGreg Leheyuse 3531159af41SGreg Lehey.Nm kldsyms 3541159af41SGreg Leheyinstead. 3551159af41SGreg Lehey.It Cm kldsyms 3561159af41SGreg LeheyRead in the symbol tables for the debugging machine. This doesn't work for 3571159af41SGreg Leheyremote debugging and crash dumps; use 3581159af41SGreg Lehey.Nm getsyms 3591159af41SGreg Leheyinstead. 3601159af41SGreg Lehey.It Cm tr Ar interface 3611159af41SGreg LeheyDebug a remote system via the specified serial or firewire interface. 3621159af41SGreg Lehey.It Cm tr0 3631159af41SGreg LeheyDebug a remote system via serial interface 3641159af41SGreg Lehey.Pa /dev/cuaa0 . 3651159af41SGreg Lehey.It Cm tr1 3661159af41SGreg LeheyDebug a remote system via serial interface 3671159af41SGreg Lehey.Pa /dev/cuaa1 . 3681159af41SGreg Lehey.It Cm trf 3691159af41SGreg LeheyDebug a remote system via firewire interface at default port 5556. 3701159af41SGreg Lehey.El 3711159af41SGreg Lehey.Pp 3721159af41SGreg LeheyThe commands 3731159af41SGreg Lehey.Nm tr0 , 3741159af41SGreg Lehey.Nm tr1 3751159af41SGreg Leheyand 3761159af41SGreg Lehey.Nm trf 3771159af41SGreg Leheyare convenience commands which invoke 3781159af41SGreg Lehey.Nm tr . 3791159af41SGreg Lehey.Ss "The current process environment" 3801159af41SGreg LeheyThe following macros are convenience functions intended to make things easier 3811159af41SGreg Leheythan the standard 3821159af41SGreg Lehey.Nm gdb 3831159af41SGreg Leheycommands. 3841159af41SGreg Lehey.Bl -ohang -offset 3m 3851159af41SGreg Lehey.It Cm f0 3861159af41SGreg LeheySelect stack frame 0 and show assembler-level details. 3871159af41SGreg Lehey.It Cm f1 3881159af41SGreg LeheySelect stack frame 1 and show assembler-level details. 3891159af41SGreg Lehey.It Cm f2 3901159af41SGreg LeheySelect stack frame 2 and show assembler-level details. 3911159af41SGreg Lehey.It Cm f3 3921159af41SGreg LeheySelect stack frame 3 and show assembler-level details. 3931159af41SGreg Lehey.It Cm f4 3941159af41SGreg LeheySelect stack frame 4 and show assembler-level details. 3951159af41SGreg Lehey.It Cm f5 3961159af41SGreg LeheySelect stack frame 5 and show assembler-level details. 3971159af41SGreg Lehey.It Cm xb 3981159af41SGreg LeheyShow 12 words in hex, starting at current 3991159af41SGreg Lehey.Va ebp 4001159af41SGreg Leheyvalue. 4011159af41SGreg Lehey.It Cm xi 4021159af41SGreg LeheyList the next 10 instructions from the current 4031159af41SGreg Lehey.Va eip 4041159af41SGreg Leheyvalue. 4051159af41SGreg Lehey.It Cm xp 4061159af41SGreg LeheyShow the register contents and the first four parameters of the current stack 4071159af41SGreg Leheyframe. 4081159af41SGreg Lehey.It Cm xp0 4091159af41SGreg LeheyShow the first parameter of current stack frame in various formats. 4101159af41SGreg Lehey.It Cm xp1 4111159af41SGreg LeheyShow the second parameter of current stack frame in various formats. 4121159af41SGreg Lehey.It Cm xp2 4131159af41SGreg LeheyShow the third parameter of current stack frame in various formats. 4141159af41SGreg Lehey.It Cm xp3 4151159af41SGreg LeheyShow the fourth parameter of current stack frame in various formats. 4161159af41SGreg Lehey.It Cm xp4 4171159af41SGreg LeheyShow the fifth parameter of current stack frame in various formats. 4181159af41SGreg Lehey.It Cm xs 4191159af41SGreg LeheyShow the last 12 words on stack in hexadecimal. 4201159af41SGreg Lehey.It Cm xxp 4211159af41SGreg LeheyShow the register contents and the first ten parameters. 4221159af41SGreg Lehey.It Cm z 4231159af41SGreg LeheySingle step 1 instruction (over calls) and show next instruction. 4241159af41SGreg Lehey.It Cm zs 4251159af41SGreg LeheySingle step 1 instruction (through calls) and show next instruction. 4261159af41SGreg Lehey.El 4271159af41SGreg Lehey.Ss "Examining other processes" 4281159af41SGreg LeheyThe following macros access other processes. 4291159af41SGreg Lehey.Nm gdb 4301159af41SGreg Leheydoes not understand the concept of multiple processes, so they effectively 4311159af41SGreg Leheybypass the entire 4321159af41SGreg Lehey.Nm gdb 4331159af41SGreg Leheyenvironment. 4341159af41SGreg Lehey.Bl -ohang -offset 3m 4351159af41SGreg Lehey.It Cm btp Ar pid 4361159af41SGreg LeheyShow a backtrace for the process 4371159af41SGreg Lehey.Va pid . 4381159af41SGreg Lehey.It Cm btpa 4391159af41SGreg LeheyShow backtraces for all processes in the system. 4401159af41SGreg Lehey.It Cm btpp 4411159af41SGreg LeheyShow a backtrace for the process previously selected with 4421159af41SGreg Lehey.Nm defproc . 4431159af41SGreg Lehey.It Cm btr Ar ebp 4441159af41SGreg LeheyShow a backtrace from the 4451159af41SGreg Lehey.Va ebp 4461159af41SGreg Leheyaddress specified 4471159af41SGreg Lehey.It Cm defproc Ar pid 4481159af41SGreg LeheySpecify the PID of the process for some other commands in this section. 4491159af41SGreg Lehey.It Cm fr Ar frame 4501159af41SGreg LeheyShow frame 4511159af41SGreg Lehey.Va frame 4521159af41SGreg Leheyof the stack of the process previously selected with 4531159af41SGreg Lehey.Nm defproc . 4541159af41SGreg Lehey.It Cm pcb Ar proc 4551159af41SGreg LeheyShow some pcb contents of process 4561159af41SGreg Lehey.Ar proc . 4571159af41SGreg Lehey.El 4581159af41SGreg Lehey.Ss "Examining data structures" 4591159af41SGreg LeheyYou can use standard 4601159af41SGreg Lehey.Nm gdb 4611159af41SGreg Leheycommands to look at most data structures. The macros in this section are 4621159af41SGreg Leheyconvenience functions which typically display the data in a more readable 4631159af41SGreg Leheyformat, or which omit less interesting parts of the structure. 4641159af41SGreg Lehey.Bl -ohang -offset 3m 4651159af41SGreg Lehey.It Cm bp 4661159af41SGreg LeheyShow information about the buffer header pointed to by the variable 4671159af41SGreg Lehey.Va bp 4681159af41SGreg Leheyin the current frame. 4691159af41SGreg Lehey.It Cm bpd 4701159af41SGreg LeheyShow the contents 4711159af41SGreg Lehey.Vt (char*) 4721159af41SGreg Leheyof 4731159af41SGreg Lehey.Va bp->data 4741159af41SGreg Leheyin the current frame. 4751159af41SGreg Lehey.It Cm bpl 4761159af41SGreg LeheyShow detailed information about the buffer header 4771159af41SGreg Lehey.Vt (struct bp) 4781159af41SGreg Leheypointed at by the local variable 4791159af41SGreg Lehey.Va bp . 4801159af41SGreg Lehey.It Cm bpp bp 4811159af41SGreg LeheyShow summary information about the buffer header 4821159af41SGreg Lehey.Vt (struct bp) 4831159af41SGreg Leheypointed at by the parameter 4841159af41SGreg Lehey.Va bp . 4851159af41SGreg Lehey.It Cm bx 4861159af41SGreg LeheyPrint a number of fields from the buffer header pointed at in by the pointer 4871159af41SGreg Lehey.Va bp 4881159af41SGreg Leheyin the current environment. 4891159af41SGreg Lehey.It Cm vdev 4901159af41SGreg LeheyShow some information of the vnode pointed to by the local variable 4911159af41SGreg Lehey.Va vp . 4921159af41SGreg Lehey.El 4931159af41SGreg Lehey.Ss "Miscellaneous macros" 4941159af41SGreg Lehey.Bl -ohang -offset 3m 4951159af41SGreg Lehey.It Cm checkmem 4961159af41SGreg LeheyCheck unallocated memory for modifications. 4971159af41SGreg LeheyThis assumes that the kernel has been compiled with 4981159af41SGreg Lehey.Cd options DIAGNOSTIC 4991159af41SGreg LeheyThis causes the contents of free memory to be set to 5001159af41SGreg Lehey.Li 0xdeadc0de . 5011159af41SGreg Lehey.It Cm dmesg 5021159af41SGreg LeheyPrint the system message buffer. This corresponds to the 503783a364bSGreg Lehey.Xr dmesg 8 5041159af41SGreg Leheycommand. 5051159af41SGreg LeheyIt can take a very long time over a serial line, and it's even slow via firewire 5061159af41SGreg Leheyor local memory due to inefficiencies in 5071159af41SGreg Lehey.Nm gdb . 5081159af41SGreg LeheyThis macro used to be called 5091159af41SGreg Lehey.Nm msgbuf . 5101159af41SGreg Lehey.It Cm kldstat 5111159af41SGreg LeheyEquivalent of the kldstat(8) command without options 5121159af41SGreg Lehey.It Cm pname 5131159af41SGreg LeheyPrint the command name of the current process. 5141159af41SGreg Lehey.It Cm ps 5151159af41SGreg LeheyShow process status. 5161159af41SGreg LeheyThis corresponds in concept, but not in appearance, to the 5171159af41SGreg Lehey.Nm ps 5181159af41SGreg Leheycommand. 5191159af41SGreg Lehey.It Cm y 5201159af41SGreg LeheyKludge for writing macros. When writing macros, it's convenient to paste them 5211159af41SGreg Leheyback into the 5221159af41SGreg Lehey.Nm gdb 5231159af41SGreg Leheywindow. Unfortunately, if the macro is already defined, 5241159af41SGreg Lehey.Nm gdb 5251159af41SGreg Leheyinsists on asking 5261159af41SGreg Lehey.Bd -literal -offset 5m 5271159af41SGreg LeheyRedefine foo? 5281159af41SGreg Lehey.Ed 5291159af41SGreg Lehey.Pp 5301159af41SGreg LeheyIt won't give up until you answer 5311159af41SGreg Lehey.Li y . 5321159af41SGreg LeheyThis command is that answer. It does nothing else except to print a warning 5331159af41SGreg Leheymessage to remind you to remove it again. 5341159af41SGreg Lehey.El 5351159af41SGreg Lehey.Sh AUTHORS 5361159af41SGreg LeheyThis man page was written by 5371159af41SGreg Lehey.An "Greg Lehey" Aq grog@FreeBSD.org 5381159af41SGreg Lehey.Sh SEE ALSO 539783a364bSGreg Lehey.Xr dconschat 8 , 5401159af41SGreg Lehey.Xr ddb 4 , 5411159af41SGreg Lehey.Xr fwcontrol 8 , 5421159af41SGreg Lehey.Xr gdb 1 , 543783a364bSGreg Lehey.Xr kldload 8 , 5441159af41SGreg Lehey.Xr vinumdebug 4 . 5451159af41SGreg Lehey.\" .Sh HISTORY 5461159af41SGreg Lehey.Sh BUGS 547783a364bSGreg Lehey.Bl -bullet -compact 5481159af41SGreg Lehey.It 5491159af41SGreg Lehey.Nm 5501159af41SGreg Leheywas never designed to debug kernels, and it's not a very good match. 5511159af41SGreg LeheyMany problems exist. 5521159af41SGreg Lehey.It 553783a364bSGreg LeheyThe 554783a364bSGreg Lehey.Nm gdb 555783a364bSGreg Leheyimplementation is very inefficient, and many operations are slow. 556783a364bSGreg Lehey.It 557783a364bSGreg LeheySerial debugging is even slower, and race conditions can make it difficult to 558783a364bSGreg Leheyrun the link at more than 9600 bps. Firewire connections do not have this 559783a364bSGreg Leheyproblem. 560783a364bSGreg Lehey.It 5611159af41SGreg LeheyThe debugging macros ``just growed''. 5621159af41SGreg LeheyIn general, the person who wrote them did so while looking for a specific 5631159af41SGreg Leheyproblem, so they may not be general enough, and they may behave badly when used 5641159af41SGreg Leheyin ways for which they were not intended, even if those ways make sense. 5651159af41SGreg Lehey.It 5661159af41SGreg LeheyMany of these commands only work on the ia32 architecture. 5671159af41SGreg Lehey.El 568