Monday, June 27, 2011

KDB porting on Android device

KDB stands for Kernel DeBugger.
Its used for on target debugging. You don't need another device to debug the kernel on target.
From linux 2.6.35 onwards, mainline kernel includes KDB front end (Backend is GDB). So gone are the days when we used to port kernel patches.
In fact, there used to be 2 patches , one for kernel and another for architecture specific patch.
With 2.6.35 and above, we only need to enable the following configs.
1.CONFIG_KGDB=y
2.CONFIG_KGDB_KDB=y
3.CONFIG_KGDB_SERIAL_CONSOLE=y

 However we need to port a UART patch for console polling on UART. Check out for your UART driver patch for KDB. It should be mostly available 'Open'ly.
With the following changes, build kernel and its ready for debugging.

After booting with modified kernel,we have 2 options to start KDB service.
1.Before boot
Add kgdboc=tty,115200 param in the kernel cmdline.
2.After boot
echo kbd > /sys/module/kgdboc/parameters/kgdboc

To enter KDB mode for debugging,
In tera term (or any other serial port application over PC)
echo g > /proc/sysrq-trigger
KDB command prompt is entered.
Now , we can use various KDB commands for debugging kernel such as backtrace, breakpoint, list registers etc.
Happy Debugging !

No comments: