Debugging NetBSD kernel with qemu
Alexander Shishkin has written some
posted
instructions on how to debug a NetBSD kernel running
in qemu with gdb. He reminds how to build NetBSD,
provides a shell script for making a bootable disk,
and explains the magic on how to run qemu and connect
gdb to it. An example session shows how to load the
kernel, set a breakpoint, and examine registers and
variables when the breakpoint is reached.

Post mortem debugging, or: what happened before it crashed? (Updated)
So your machine paniced, and as you were running X you have no
clue what went on? Here's a nice way to find out, assuming you have
a kernel crash dump. To ensure the latter, set
kern.dump_on_panic=1 in /etc/sysctl.conf.
Now, what to do with those crashdumps?

In /var/crash, "bounds" contains an increasing counter for the
crashdump number (it would be "27" in the above example),
and "minfree" contains the minimum amount of free space
in kilobytes that should keep free - both files are read by
savecore(8) when /etc/rc.conf has "savecore=yes", which is
the default.

The actual crashdump consists of two gzipped files - the
actual memory dump "netbsd.XX.core.gz" and a copy of the
running kernel "netbsd.xx.gz". After uncompressing the
files can be used for looking at the system at the point
of it's panic:

# gunzip netbsd.26*.gz
#

Note that the crashdump may contain sensitive data and is such
only readable by root!

The crashdump can be read by programs that use libkvm to
read through the crashdump's kernel memory, e.g.
gdb(1), dmesg(8), ps(1), fstat(8), ipcs(1), netstat(8), nfsstat(8),
pmap(1), w(1), pstat(8), vmstat(8) etc.,
using the -M and -N switches.

Enabling separate debug symbol support for gdb6
NetBSD-current got an update to the latest GNU debugger,
gdb6, recently. That version allows keeping the debug
information for a binary in a seperate file, thus not
bloating every client's filesystem while still being able
to keep debugging symbols around in some place.

Luke Mewburn has sent a
proposal
to enable this in NetBSD, and he has
committed
code now that allows setting "MKDEBUG=yes" to put seperate debugging
symbols into /usr/libdata/debug.

This is currently not enabled by default, but maybe someone
finds this useful, wants to test it and give some feedback.