Specifications

Driver Testing and Debugging
15-19
matically under various conditions, such as panics and breakpoint traps. Any time the
kdb>> prompt displays, you are in the debugger. I/O is performed through the console or
a serial terminal.
To exit the debugger, press CTRL-d or q.
When you exit and re-enter the debugger, its state is preserved, including the contents of
the value stack.
kdb is an extremely powerful tool, and should be used carefully to avoid accidental cor-
ruption of kernel data structures, which could lead to a system crash. kdb has few provi-
sions for preventing programmer error.
NOTE
The kernel debugger is not meant for debugging user programs.
Use an appropriate user-level debugger, such as adb(1), for
that purpose.
kdb must exist in your kernel before you can use it (just like any device driver).
kdb prints and accepts address inputs symbolically, using kernel procedure and variable
names instead of hexadecimal numbers, but you must load the debugger with the kernel's
symbols after the debugger itself has been installed into the kernel. You can do this by
using the unixsyms command, which loads the symbols into the kernel executable file
after building it and before booting it. Normally, this is done automatically for you by
idbuild(1M).
Entering kdb from a Driver 15
If you are debugging a device driver or another part of the kernel, you can directly invoke
the kernel debugger by including the following code in your driver:
#include <sys/systm.h>
(*call_demon) (DR_OTHER, NO_FRAME);
This mechanism cannot be used for debugging early kernel startup code or driver init
routines, since the debugger cannot be used until its init routine, kdb_init, has been
called.
System Panics 15
If you expect that the driver could enter a state that is invalid, the driver can halt the system
using the cmn_err(D3) function with a panic flag set. For example, if the driver expects
one of three specific cases in a switch statement, the driver can add a fourth default case
that calls the cmn_err() function. The system dumps an image of memory for later