A common debugging technique is to instrument your code; that is, insert prints at appropriate points such that you can follow the path the code takes. Within a kernel module, of course, we would use the versatile printk function for this purpose. So, let's say we do something like the following (pseudo-code):
#define pr_fmt(fmt) "%s:%s():%d: " fmt, KBUILD_MODNAME, __func__, __LINE__
[ ... ]
func_x() {
pr_debug("At 1\n");
[...]
while (<cond>) {
pr_debug("At 2: j=0x%x\n", j);
[...]
}
[...]
}
Okay, great. But we don't want the debug prints to appear in a production (or release) version. That's precisely why we're using the pr_debug() : it emits a printk only when the symbol DEBUG is defined! Indeed, but what if, interestingly, our customer is an engineering customer and wants to dynamically turn on or turn off these debug prints? There are...