14.6. Chapter Summary Linux kernel debugging presents many complexities, especially in a cross-development environment. Understanding how to navigate these complexities is the key to successful kernel debugging. KGDB is a very useful kernel-level gdb stub that enables direct symbolic source-level debugging inside the Linux kernel and device drivers. It uses the gdb remote protocol to communicate to your host-based cross-gdb. Understanding (and minimizing) compiler optimizations helps make sense of seemingly strange debugger behavior when stepping through compiler-optimized code. gdb supports user-defined commands, which can be very useful for automating tedious debugging tasks such as iterating kernel linked lists and accessing complex variables. Kernel-loadable modules present their own challenges to source-level debugging. The module's initialization routine can be debugged by placing a breakpoint in module.c at the call to module->init(). printk and the Magic SysReq key provide additional tools to help isolate problems during kernel development and debugging. Hardware-assisted debugging via a JTAG probe enables debugging Flash or ROM resident code where other debugging methods can be cumbersome or otherwise impossible. Enabling CONFIG_SERIAL_TEXT_DEBUG on architectures where this feature is supported is a powerful tool for debugging a new kernel port. Examining the printk log_buf often leads to the cause of a silent kernel crash on boot. KGDB passes control to gdb on a kernel panic, enabling you to examine a backtrace and isolate the cause of the kernel panic. 14.6.1. Suggestions for Additional Reading Linux Kernel Development, 2nd Edition Robert Love Novell Press, 2005 The Linux Kernel Primer Claudia Salzberg Rodriguez et al. Prentice Hall, 2005 "Using the GNU Compiler Collection" Richard M. Stallman and the GCC Developer Community GNU Press, a division of Free Software Foundation http://gcc.gnu.org/onlinedocs/ KGDB Sourceforge home page http://sourceforge.net/projects/KGDB Debugging with GDB Richard Stallman, Roland Pesch, Stan Shebs, et al. Free Software Foundation www.gnu.org/software/gdb/documentation/ Tool Interface Standards DWARF Debugging Information Format Specification Version 2.0 TIS Committee, May 1995 |