문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

If this is for quick debugging, just printk() works well.

If this is for debugging in more production situation, maybe use pr_debug(), so messages can be enabled at runtime.

Regardless, ("%s: xxx", func) is usually enough. These filenames and line numbers will become annoying very soon. This is also why you haven't found any "standard" solution -- because there is none.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top