Getting Kernel Symbols/Sources on Ubuntu Linux

This tutorial shows how to prepare your a Debian-based (e.g. Ubuntu, Mint) Linux machine for kernel debugging without rebuilding the kernel.

Note that if you are using VisualKernel, this will be done automatically by the VisualKernel project wizard. This page provides instructions on doing it manually in order to help diagnosing common problems.

As the kernel provided by the distribution does not include sources and symbols, we will need to install the corresponding packages manually. This page provides step-by-step instructions on doing that:

  1. Determine the exact release and version of your kernel by running the following commands:
    uname -r
    uname -v

    In this example the release is 3.8.0-19-generic and the version number is #29.

  2. Determine the Debian release codename by running the “lsb_release -c” command:In this example the release codename is raring.
  3. Add the following line to the /etc/apt/sources.list.d/ddebs.list file (create it if it doesn’t exist):
    deb <codename> main restricted universe multiverse

    This will add a repository containing debugging symbols to your system’s repository list.

  4. Run ‘sudo apt-get update’ to load the package list from the new repository:
  5. Now that the repository has been added, you can install the symbol package by running the following command:
    apt-get install linux-image-<release>-dbgsym=<release>.<version>

    In this example the package name/version are linux-image-3.8.0-19-generic-dbgsym=3.8.0-19.29

  6. Once the package is installed, go to /usr/lib/debug/boot, locate the kernel symbol file matching your current version, open it with gdb and ensure that its version matches the version/release discovered in step 1:
  7. The symbol file you have installed allows setting breakpoints by function names and viewing local variables, however you won’t be able to display source file contents unless you install the source package. The sources can be installed using the following command:
    apt-get install linux-source-<release>-dbgsym=<release>.<version>

  8. Once the package is installed, go to /usr/src/linux-source-<release> and unpack the source tarball:

Now that you have both symbols and sources installed, you can use gdb to successfully debug your kernel.

Note that if you are using VisualKernel, the sources/symbols will be automatically installed by the new project wizard (see this tutorial for an example).