Debugging application code helps you gain insight into the way code works and what is happening when it misbehaves and you can do the same with the kernel, with some limitations.
You can use
kgdb for source level debugging, in a manner similar to remote debugging with
gdbserver. There is also a self-hosted kernel debugger,
kdb, that is handy for lighter weight tasks such as seeing if an instruction is executed and getting the backtrace to find out how it got there. Finally, there are kernel oops messages and panics, which tell you a lot about the cause of a kernel exception.
When looking at kernel code using a source debugger, you must remember that the kernel is a complex system, with real-time ...