When a userland application encounters a bug the operating system provides services for investigating the bug. For example, a kernel may save a copy of the a process' memory image on disk as a core dump. An operating system may also provide APIs for one process to analyze the state of another process. Using these services, debugging tools such as gdb  can be written.
Operating system kernels have bugs just like userland applications. A key difference, however, is that operating system kernels are not always able to rely on a separate piece of software to provide debugging services. As a result, kernels generally must provide their own specialized support for debugging services. The FreeBSD kernel provides several services such as crash messages, crash dumps, the /dev/kmem device, a remote GDB interface, and a self-contained in-kernel debugger called DDB . These services can then be used either directly by the user or indirectly via other tools such as kgdb .
The Kernel Debugging chapter of the FreeBSD Developer's Handbook  covers several details already such as entering DDB, configuring a system to save kernel crash dumps, and invoking kgdb on a crash dump. This paper will not cover these topics. Instead, it will demonstrate some ways to use FreeBSD's kernel debugging tools to investigate bugs.