Leveraging the printk for debug purposes
You might imagine that all you have to do to emit a debug message to the kernel log is simply to issue a printk at the log level KERN_DEBUG
. Though there's (a lot) more to it, the pr_debug()
(and dev_dbg()
) macros are actually designed to be more than mere printers when the kernel's dynamic debug option is enabled. We will learn about this powerful aspect in the coming Using the kernel's powerful dynamic debug feature section.
In this section, let's first learn more about issuing a debug print, followed by slightly more advanced ways that help in the issuing of debug messages to the kernel log.
Writing debug messages to the kernel log
In the simple kernel module we covered in the previous section (printk_loglevel
), let's relook at the couple of lines of code that emitted a kernel printk at the debug log levels:
pr_debug("Hello, debug world @ log-level KERN_DEBUG [%d]\n", LOGLEVEL_DEBUG...