Kernel Debugging

From OLPC

Jump to: navigation, search

This page offers a short HOWTO on the care and feeding of the kdb in-kernel debugger. This concentrates on using a serial port, if somebody has success using the keyboard and panel, please add it.

Setup

The KDB home page is here: [1], and the latest patches are located here: [2]. Note that they do a very good job of keeping up to date with the kernel - so you should be reasonably sure that the patches will work with the latest unstable OLPC kernel. We are currently using 2.6.21-rc3, so thats what we'll use for the rest of this tutorial.

To setup the kernel - make sure you have a recent pull from the OLPC unstable GIT tree. Download the following patches from the KDB site:

ftp://oss.sgi.com/www/projects/kdb/download/v4.4/kdb-v4.4-2.6.21-rc3-common-1.bz2

ftp://oss.sgi.com/www/projects/kdb/download/v4.4/kdb-v4.4-2.6.21-rc3-i386-1.bz2

Apply the patches to your kernel:

 bzcat kdb-v4.4-2.6.21-rc3-common-1.bz2 | patch -p1
 bzcat kdb-v4.4-2.6.21-rc3-i386-1 | patch -p1

Make sure you enable the configuration (this is what I use):

CONFIG_KDB=y
CONFIG_KDB_MODULES=m
# CONFIG_KDB_OFF is not set
CONFIG_KDB_CONTINUE_CATASTROPHIC=0
CONFIG_KDB_USB=y

Read the help for the configuration options to learn more about them. After configuring, rebuild your kernel, and install it into your image. In order to debug with serial, you need to add a serial console to the system, do that by adding

 console=ttyS0,115200

to the setenv boot-file line in /boot/olpc.fth, or /boot/olpc-boot.fth (whichever one appears in your image). You will also need to make sure that a serial console is enabled by default in your inittab (it should be).

Debugging the kernel (with serial)

Boot the system - you should see a login on the serial port. To enter the debugger, enter <ESC>KDB - the debugger prompt should appear. (Note: Its very important that this happen on a serial line with a serial console enabled - not just any serial port connection will do).

Once in the debugger, you can perform a number of commands. This article [3] is a great tutorial, and somewhat more detailed man pages can be found in Documentation/kdb in your kernel.

In general, the basic commands you may be interested in are:

  • ss - single step - this lets you move to the next instruction
  • bp - breakpoint - lets you set a break point on a symbol name or address
  • id - disassemble a symbol name or address
  • go - Start execution
  • rd - read registers
Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
Projects
OLPC wiki
Toolbox