While it is possible to gdb into the kernel, setting it up can be more hassle than it's worth (at the least, you need to patch and recompile your kernel). See the various kernel programming guides on http://www.tldp.org/
for where to find further information.
My advice is to work through your code by hand and look for a race condition or an infinite loop. This approach takes a little more work than using a debugger, but tends to find more bugs and mistakes.
Alternatively, comment out sections of the code systematically that are likely to be causing errors to find out where the bug is.