Linux内核调试打印输出?

use*_*128 10 c debugging kernel linux-kernel printk

有没有更好的方法来调试Linux内核中的打印输出?

现在乱丢代码:

printk(KERN_DBG "%s:%d - %s() <message>", __FILE__, __LINE__, __FUNCTION__ ); 
Run Code Online (Sandbox Code Playgroud)

哪个不是很干净.

整个行应该有一种方式#ifdef:以一种不错的方式编辑.

use*_*775 16

使用

/* 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");
Run Code Online (Sandbox Code Playgroud)

作为基础(标准做法).然后,您可以添加__FILE____LINE__pr_fmt定义,如果你需要.