Debugging kernels under qemu

This is a quick explanation of how to provide gdb with enough information to be able to show source when connected to a qemu which is running a stock Linaro kernel image.

Assuming you're running a nightly snapshot or a release, you'll need to check the hwpack to find the version of the linux-image package that was used:

  • tar tvzf hwpack_linaro-omap3_20110126-0_armel_supported.tar.gz | grep pkgs/linux-image-2

In this example it is 'linux-image-2.6.37-1002-linaro-omap_2.6.37-1002.5_armel.deb'.

Setting up using setup-kndbg script

setup-kndbg

This is the easy approach: cd into a suitable directory and run

  • setup-kndbg [platform] 2.6.37-1002.5

where [platform] is the platform name (eg vexpress, omap; default is omap), and it will wget all the necessary files, unpack them and write a gdb script you can pass to an ARM gdb to tell it where the sources are.

Manual explanation

You don't need to read this unless you distrust the script and like doing things by hand...

gdb needs two things: the source tree, and an uncompressed vmlinux file. The former is in the linux-linaro-omap source package, and the latter is in the linux-image-*-dbgsym .ddeb file, so we must download both of these and extract them:

  • wget http://ddebs.ubuntu.com/pool/universe/l/linux-linaro-omap/linux-image-2.6.37-1002-linaro-omap-dbgsym_2.6.37-1002.5_armel.ddeb
    wget http://ports.ubuntu.com/pool/universe/l/linux-linaro-omap/linux-linaro-omap_2.6.37-1002.5.dsc
    wget http://ports.ubuntu.com/pool/universe/l/linux-linaro-omap/linux-linaro-omap_2.6.37-1002.5.tar.gz
    dpkg-source -x linux-linaro-omap_2.6.37-1002.5.dsc
    dpkg -x linux-image-2.6.37-1002-linaro-omap-dbgsym_2.6.37-1002.5_armel.ddeb kndbg

This will give you the sources in linux-linaro-omap-2.6.37/ and a vmlinux file in kndbg/usr/lib/debug/boot/vmlinux-2.6.37-1002-linaro-omap.

For the Ubuntu 10.10 netbook image you want these files instead:

  • wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35-22.33.dsc
    wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35-22.33.diff.gz
    wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35.orig.tar.gz
    wget http://ddebs.ubuntu.com/pool/main/l/linux/linux-image-2.6.35-22-omap-dbgsym_2.6.35-22.33_armel.ddeb
    dpkg-source -x linux_2.6.35-22.33.dsc
    dpkg -x linux-image-2.6.35-22-omap-dbgsym_2.6.35-22.33_armel.ddeb kndbg

We need to install a symlink so gdb can find the source code despite the odd source path that results from the kernel having been built on a buildd:

  • mkdir -p build/buildd
    ln -s "$(pwd)/linux-linaro-omap-2.6.37 build/buildd

Now we're ready to debug. Start qemu with all the usual arguments and also the options "-s -S". This will make it set up a gdb server listening on port 1234 and wait for a gdb connection. Run gdb:

  • arm-linux-gnueabi-gdb kndbg/usr/lib/debug/boot/vmlinux-2.6.37-1002-linaro-omap

and at the gdb prompt:

  • target remote localhost:1234
    directory .
    break my_kernel_function_name
    continue

Note that you can happily break on kernel function names even though the kernel has not yet been loaded into memory, relocated and so on. When the kernel hits the breakpoint you should find that you have full source level debugging information. (Since the kernel was compiled with optimisation you'll still find that some variables aren't accessible in the debugger because they've been optimised out, of course.)

Debugging Ubuntu 10.10 netbook image

For the Ubuntu 10.10 netbook image you want these files instead:

  • wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35-22.33.dsc
    wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35-22.33.diff.gz
    wget http://ports.ubuntu.com/pool/main/l/linux/linux_2.6.35.orig.tar.gz
    wget http://ddebs.ubuntu.com/pool/main/l/linux/linux-image-2.6.35-22-omap-dbgsym_2.6.35-22.33_armel.ddeb
    dpkg-source -x linux_2.6.35-22.33.dsc
    dpkg -x linux-image-2.6.35-22-omap-dbgsym_2.6.35-22.33_armel.ddeb kndbg
    mkdir -p build/buildd
    ln -s linux-2.6.35 build/buildd

and your gdb command line is

  • arm-linux-gnueabi-gdb kndbg/usr/lib/debug/boot/vmlinux-2.6.35-22-omap


CategoryHowTo

PeterMaydell/QemuKernelDebugging (last modified 2011-03-03 15:45:19)