You may want to actually debug the kernel or a kernel module, however, debugging is not enabled by default.
The steps are identical to the steps contained in the How to build and install a custom kernel on FreeBSD? article, with the exception of the kernel configuration file.
Step 1 – Create a new kernel config
- Determine your architecture by running this command:
# uname -a FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 email@example.com:/usr/obj/usr/src/sys/GENERIC amd64
- Look at the last text item in the output string. I have amd64 so that is my architecture: amd64
- Change to the directory of the kernel configuration files for your architecture. Remember if you are on a different architecture to replace amd64 in the following command lien with your architecture.
# cd /usr/src/sys/amd64/conf
- Copy GENERIC to a new file.
# cp GENERIC KRNLDBG
- Edit KRNLDBG with your favorite text editor.
- First, change the ident value near the top from GENERIC to KRNLDBG.
- Add debugging settings to your KRNLDBG configuraiton file.
options KDB options KDB_TRACE options DDB options GDB
- Save and close your new KRNLDBG configuration file.
For the remaining steps, follow the How to build and install a custom kernel on FreeBSD? article, only replace any references to KRNL1 kernel config file with the KRNLDBG config file created in the previous step.
Once you are done building and installing the kernel, you should have debugging enabled.
I happen to be working with a kernel module that is crashing and when it crashes, it automatically places me in a debugging session with the following prompt.