Kernel debugging primer

Debug boot problem

debug ignore_loglevel earlyprintk=ttyS0,115200,keep keep_bootcon initcall_debug dyndbg=+plmf

Dynamic debug

Precondition: CONFIG_DYNAMIC_DEBUG
How to use it during kernel booting?
Use boot option:
dyndbg=“file drivers/usb/host/ehci-hcd.c +p; file
drivers/usb/host/ehci-ppc-of.c +p” loglevel=8
loglevel=8 dyndbg=“module ehci_pci +p;
module ehci_hcd +p; module usbcore +p”
After booting:
/sys/kernel/debug/dynamic_debug/control

Dev print functions

drivers/base/core.c
define_dev_printk_level
THese functions are like pr_func

oops

Kernel oops relates to invalid memory access, including sigev and sigbus.
kernel oops tracing
Debugging a kernel crash found by syzkaller

lockup

phenomenon: LOCKUP_DETECTOR
kernle doc - Softlockup detector and hardlockup detector
Debugging Linux Kernel Lockup / Panic / Oops
Causes: deadlock, hardware, irqoff and loop

hung task

phenomenon: DETECT_HUNG_TASK
Includes the interruptable task.
Causes: deadlock, race condition

kprobes

deadlock

Lockdep
The kernel lock validator
Runtime locking correctness validator
https://lkml.org/lkml/2013/2/4/4
http://bbs.chinaunix.net/thread-4183696-1-1.html

kasan

setup_arch->kasan_init
KernelAddressSanitizer a fast memory error detector for the Linux kernel
kasan found stack out of bounds
lwn The kernel address sanitizer
out of bounds

CONFIG_DEBUG_PAGEALLOC

check_poison_mem in alloc_pages
free_pages_prepare posion