Linux-kernel debug printouts?

user616128 picture user616128 · Feb 14, 2011 · Viewed 7.7k times · Source

Is there a better way to debug printouts in the Linux kernel?

Right now littering the code with:

printk(KERN_DBG "%s:%d - %s() <message>", __FILE__, __LINE__, __FUNCTION__ ); 

Which isn't very clean.

There ought to be a way for the whole row to be #ifdef:ed in some nice way.

Answer

user611775 picture user611775 · Feb 14, 2011

Use

/* At the top of the file, before any includes */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/printk.h>

/* in code... */
pr_devel("foobar happened\n");

as a basis (the standard practice). You can then add __FILE__ or __LINE__ to the pr_fmt definition if you need.