0a. Check if your kernel is debug-enabled. In the file /usr/src/sys/i386/conf/GENERIC (replace GENERIC with your kernel name if you are using a custom kernel), look for the following line:
makeoptions DEBUG=-gIf it's not there, add it.
0b. Check if the config file has the following line:
options DDBIf it's not there, add it.
If you make these changes, recompile the kernel and install it on the system to be debugged ("live system").
1. Connect the serial cable between live system and development system.
2. Edit /etc/ttys in the live system to enable serial cable communication.
ttyd0 "/usr/libexec/getty std.9600" dialup off secure
To:
ttyd0 "/usr/libexec/getty std.9600" vt100 on secure
(The above assumes the cable is connected to COM1 port.)
3. Restart the live system, or just say "kill -HUP 1".
4. Go to the kernel compile directory in the development system (in the /usr/obj/... hierarchy).
5. In the development system and in the compile directory, issue:
gdb -k kernel.debugor:
kgdb kernel.debug
(assuming kernel.debug is the unstripped kernel: if kernel is itself unstripped, use that)
6. Log in to the live system (through telnet or console) and issue:
sysctl debug.enter_debugger=gdbor in FreeBSD 6.x,
sysctl debug.kdb.enter=1
7. In the developer system, within the gdb prompt, say:
(kgdb) target remote /dev/cuaa0
After this, you should be able to debug the kernel like any other program in GDB.