Linux内核调试打印输出? [英] Linux-kernel debug printouts?

查看:30
本文介绍了Linux内核调试打印输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更好的方法在 Linux 内核中调试打印输出?

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

现在乱丢代码:

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

这不是很干净.

应该有一种方法可以使整行 #ifdef: 以某种不错的方式进行编辑.

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

推荐答案

使用

/* 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
");

作为基础(标准做法).然后,如果需要,您可以将 __FILE____LINE__ 添加到 pr_fmt 定义中.

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

这篇关于Linux内核调试打印输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆