Friday, January 23, 2009

The Linux Kernel Debugger, kdb

A few people need to debug the Linux kernel as it is opensource. But still debugging isn't a wasteful exercise.

Outlined here are the steps to configure and use the Linux Kernel Debugger, kdb.

Download the kernel source (linux-2.6.xx) from kernel.org.

Copy the file to /usr/src/kernels and extract it.

# tar -xvf linux-2.6.xx

Download the kdb patch for the kernel. Depending on the kernel and the platform two files, kdb-v4.4-2.6.xx-common.bz2 and kdb-v4.4-2.6.xx-ARCH.bz2 should be downloaded.

For a kernel 2.6.25.3 and intel based machine, download kdb-v4.4-2.6.25-rc3-common-1.bz2 and kdb-v4.4-2.6.25-rc3-x86-1.bz2.

Copy the files into the /usr/src/kernels/linux-2.6.xx directory and extract the patch files from the bzipped files:

# bzip2 -d kdb-v4.4-2.6.xx-common-1.bz2
# bzip2 -d kdb-v4.4-2.6.xx-x86-1.bz2

You will get the kdb-v4.4-2.6.xx-common-1 and kdb-v4.4-2.6-ARCH-1 files.

Now, apply the patches:
# patch -p1 kdb-v4.4-2.6.xx-common-1
# patch -p1 kdb-v4.4-2.6.xx-x86-1

Now, traverse to /usr/src/kernels/linux-2.6.xx build and install the kernel

# make
# make dep modules modules_install install clean

Boot to the new kernel.

Now to invoke kdb first switch to session at F10 by pressing ctrl+F10. Now press PAUSE key twice. The kdb shell should come up.

Various commands can be used to view the kernel memory space and to perform a lot of other debugging tasks.

To end the session issue g at the prompt and press ENTER. Switch back to the previous session.