A while ago I successfully used the technique "alinrus" refers to. The part he mentioned is explained in detail at:
http://stackframe.blogspot.com/2007/04/debugging-linux-kernels-with.html
I actually used it directly from a Windows host. So after setting up the VM (mainly enabling remote debugging and downloading the kernel (the vmlinux file, not the vmlinuz file which cannot be interpreted by gdb)), you would need to do the following:
- Install a recent gdb on your Windows machine (I used the one in Cygwin).
- Start gdb with the vmlinux file, and then do "target remote localhost:8832" to connect the VM (when it's running).
That is what you need to debug code which is statically linked into the kernel. You could try statically linking your module and the above would be sufficient. Setting up debugging for a dynamically-linked module requires an additional step to inform to gdb to use your module file as well, and how to interpret the file's sections.
3a. Run the script below on your .ko file, after loading the module (and before crashing it :) ).
3b. Paste the resulting "add-symbol-file mymodule.ko 0xe8884000 ..." lines into gdb. gdb will then load your module, as long as it can find it in the current directory or path you specify.
Script is from http://anomit.com/2009/11/04/kernel-module-debugging-a-simple-technique/
#!/bin/sh
#
# gdbline module image
#
# Outputs an add-symbol-file line suitable for pasting into gdb to examine
# a loaded module.
#
cd /sys/module/$1/sections
PROG=${1}.ko
echo -n add-symbol-file ${PROG} `/bin/cat .text`
#echo -n add-symbol-file $2 `/bin/cat .text` #Take second argument to be gdb name of program/object file
for section in .[a-z]* *; do
if [ $section != ".text" ]; then
echo " \\"
echo -n " -s" $section `/bin/cat $section`
fi
done
echo
There are more things you may want to do. To do actual source-level debugging you'll want to suck down all the kernel and module source code so that gdb can find it. And there are some tricks you can use to compile your module without optimization once you get this far.
You may also want to look at Workstation 7.0's tech note on replay debugging, which contains information on debugging kernel modules. VMware knows their stuff.
http://www.vmware.com/pdf/ws7_replay_linux_technote.pdf