pr_xx( )封裝
在使用printk的時候需要手動添加輸出等級KERN_INFO、KERN_WARNING等,這樣還是有些麻煩。因此,Linux內核也對printk進行了進一步的封裝。
Linux內核將每一個輸出等級封裝為pr_xx()函數(shù),例如,輸出等級KERN_INFO
封裝為pr_info(),輸出等級KERN_WARNING
封裝為pr_warn()。具體如下:
#define pr_emerg(fmt, ...)
printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
#define pr_alert(fmt, ...)
printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_crit(fmt, ...)
printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...)
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
#define pr_warn(fmt, ...)
printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
#define pr_notice(fmt, ...)
printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
#define pr_info(fmt, ...)
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...)
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
這里對輸出等級為KERN_DEBUG
的封裝是比較特殊的,因為debug等級比較常用,內核對pr_debug()分為了三種情況:
如果設置了 CONFIG_DYNAMIC_DEBUG
,則此pr_debug()擴展為 dynamic_pr_debug(),主要用于 動態(tài)輸出 。否則,如果定義了 DEBUG
宏,則它等同于具有 KERN_DEBUG
日志級別的 printk。 如果未定義 DEBUG,則它什么都不做 。
pr_debug()的定義如下:
/* If you are writing a driver, please use dev_dbg instead */
#if defined(CONFIG_DYNAMIC_DEBUG) ||
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#include < linux/dynamic_debug.h >
/**
* pr_debug - Print a debug-level message conditionally
* @fmt: format string
* @...: arguments for the format string
*
* This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
* set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
* KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
*
* It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
* pr_fmt() internally).
*/
#define pr_debug(fmt, ...)
dynamic_pr_debug(fmt, ##__VA_ARGS__)
#elif defined(DEBUG)
#define pr_debug(fmt, ...)
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_debug(fmt, ...)
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif
-
內核
+關注
關注
3文章
1416瀏覽量
41441 -
Linux
+關注
關注
87文章
11511瀏覽量
213823 -
函數(shù)
+關注
關注
3文章
4381瀏覽量
64889
發(fā)布評論請先 登錄
Linux內核中斷設計與實現(xiàn)
Linux內核學習筆記:printk調試
Linux的內核教程
Linux內核源代碼
linux內核kernel-api
基于Android的Linux內核的電源管理

linux內核是什么_linux內核學習路線
Linux內核熱補丁安全隱患的探索

評論