Linux supports various configuration options for debugging Linux Kernel. Some of these options are not supported on all the platforms. Some of the available configuration options are

  • CONFIG_DEBUG_KERNEL : It makes other debugging options available, but does not enable any features.
  • CONFIG_DEBUG_SLAB : This option turns on several types of checks in the kernel memory allocation functions. It allow to detect a number of memory overrun and missing initialization errors. Each byte of allocated memory is set to 0xa5 before being handed to the caller and then set to 0x6b when it is freed. When debugging is enabled, the kernel also places special guard values before and after every allocated memory object; if those values ever get changed, the kernel knows that somebody has overrun a memory allocation, and it complains loudly.
  • CONFIG_DEBUG_PAGEALLOC : Full pages are removed from the kernel address space when freed. This option can slow things down significantly, but it can also quickly point out certain kinds of memory corruption errors.
  • CONFIG_DEBUG_SPINLOCK : This options allows kernel to catch operations on uninitialized spinlocks and various other errors (such as unlocking a lock twice).
  • CONFIG_DEBUG_SPINLOCK_SLEEP : It enables a check for attempts to sleep while holding a spinlock.
  • CONFIG_INIT_DEBUG : Items marked with _ init (or _initdata) are discarded after system initialization or module load time. This option enables checks for code that attempts to access initialization-time memory after initialization is complete.
  • CONFIG_DEBUG_INFO : This option causes the kernel to be built with full debugging information included. This information is helpful to debug the kernel with gdb. You may also want to enable CONFIG_FRAME_POINTER if you plan to use gdb.
  • CONFIG_DEBUG_STACKOVERFLOW : These options can help track down kernel stack overflows.
  • CONFIG_DEBUG_STACK_USAGE : These options can help the kernel to monitor stack usage and make some statistics.
  • CONFIG_PROFILING : Profiling is normally used for system performance tuning, but it can also be useful for tracking down some kernel hangs and related problems.
  • ¬†CONFIG_DEBUG_INFO : Compile the kernel with debug information.

Example

Kernel has infrastructure for detecting all sorts of atomicity violations. Below configuration will help debug potential bugs including calling schedule() while holding a lock, issuing a blocking memory allocation while holding a lock, or sleeping while holding a reference to per-CPU data.

CONFIG_PREEMPT=y
CONFIG_DEBUG_KERNEL=y
CONFIG_KALLSYMS=y
CONFIG_SPINLOCK_SLEEP=y