Linux-kernel debug printouts?

放肆的年华 提交于 2019-12-03 02:50:50

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!