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.

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

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.

Wednesday, October 14, 2009

handling the cross-compiling nightmare

If you have ever faced the challenge of running your code on different platforms with need to support different system libs (glibc/uClibc), you probably know it's not a simple task building the toolchains. Very simplistically, a toolchain is what makes up the tools that compile, assemble and link the code being developed.

For this case, crosstool-NG comes to your rescue. It's a versatile toolchain generator that is very simple to configure. You simply fill in the appropriate values with the adequate options in a configuration file. Then point your compiler option in the Makefiles to the right compiler.

There is a decent tutorial on how to use crosstool-NG here, but it has not been updated for the newer releases. The current release is version 1.5.2.