Debugging by printing
Note: This article is currently only a draft and is a part of a series of articles I'm going to publish the next few months - if you want to contribute to it, please feel free to. However it would be nice if you could coordinate your efforts with me
debugging by printing is probably the simplest way to get some information from the kernel, especially when using the kernels equivalent of printf, the printk function.
The main advantage of debugging with printk is that no sophisticated setup is needed and printk can be called from almost anywhere at any time. Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.
The only real exception is early in the boot process where no console is available yet, but there is special function named early_printk just for this special case, which is available if CONFIG_EARLY_PRINTK is set.
What this article will be about - ideas
- printk format
- Debug/log levels - dmesg -n /proc/sys/kernel/printk
- dynamic debug, pr_debug and dev_dbg
- pr_warn and family - see printk.h for details
- maybe Early printk via EHCI debug port (if I have the hardware, which I doubt)
- printascii, printch and printhex (on ARM only?)
- /dev/kmsg , /proc/kmsg
- maybe netconsole
- Examples - maybe use example module.
- Linux Kernel Development, Robert Love, 3rd Edition, Chapter 18 Debugging
- Essential Device Drivers