Saturday, October 24, 2009

tips for baby steps in kernel debugging

Even if you have been a programming in C for a while, getting into kernel debugging can be intimidating. If you are used to c-tags or using an IDE for your development, the task is even more challenging. However, a few tools listed below help you get started very quickly:

Obviously the first step is getting the kernel, and depending on what kernel you are running and/or what Linux distribution you have, this can be tricky. For Fedora systems, there are simple ways to get the kernel source.

LXR - Linux Cross Reference
This is a very useful resource if you want to get a quick idea about the flow of code, structures. LXR is a toolset that has the entire kernel source indexed. It's an Ajax interface and makes it very easy to browse source code.

printk()
This is the printf of the kernel. The syntax is similar to printf. The useful argument is the loglevels that can attach a level of importance to your messages. The definition of the loglevels are in include/linux/kernel.h

dump_stack()
Sometimes, tracking the code flow is easier if you can show the program stack. Most architectures have dump_stack() implemented. This can be a very useful weapon in a newbie kernel debugger's arsenal.

There are some good tutorials that do some hand-holding for writing kernel modules, but if you have to track an issue in the core kernel or just want to get a better understanding, the tools described above are very useful.

Go on, get your feet wet in kernel debugging.

No comments: