10.8.Â Kernel debugging with Dcons

dcons(4) is a very simple console driver that is
not directly connected with any physical devices. It just reads
and writes characters from and to a buffer in a kernel or
loader. Due to its simple nature, it is very useful for kernel
debugging, especially with a FireWireÂ® device. Currently, FreeBSD
provides two ways to interact with the buffer from outside of
the kernel using dconschat(8).

10.8.1.Â Dcons over FireWireÂ®

Most FireWireÂ® (IEEE1394) host controllers are
based on the OHCI specification that
supports physical access to the host memory. This means that
once the host controller is initialized, we can access the
host memory without the help of software (kernel). We can
exploit this facility for interaction with dcons(4).
dcons(4) provides similar functionality as a serial
console. It emulates two serial ports, one for the console
and DDB, the other for
GDB. Because remote memory access is fully
handled by the hardware, the dcons(4) buffer is
accessible even when the system crashes.

FireWireÂ® devices are not limited to those
integrated into motherboards. PCI cards
exist for desktops, and a cardbus interface can be purchased
for laptops.

10.8.1.1.Â Enabling FireWireÂ® and Dcons support on the target
machine

To enable FireWireÂ® and Dcons support in the kernel of
the target machine:

Make sure your kernel supports
dcons, dcons_crom
and firewire.
Dcons should be statically linked
with the kernel. For dcons_crom and
firewire, modules should be
OK.

Make sure physical DMA is enabled.
You may need to add
hw.firewire.phydma_enable=1 to
/boot/loader.conf.

Add options for debugging.

Add dcons_gdb=1 in
/boot/loader.conf if you use GDB
over FireWireÂ®.

Enable dcons in
/etc/ttys.

Optionally, to force dcons to
be the high-level console, add
hw.firewire.dcons_crom.force_console=1
to loader.conf.

10.8.2.Â Dcons with KVM

We can directly read the dcons(4) buffer via
/dev/mem for live systems, and in the
core dump for crashed systems. These give you similar output
to dmesg -a, but the dcons(4) buffer
includes more information.