pr_xx( )封裝
在使用printk的時候需要手動添加輸出等級KERN_INFO、KERN_WARNING等,這樣還是有些麻煩。因此,Linux內(nèi)核也對printk進行了進一步的封裝。
Linux內(nèi)核將每一個輸出等級封裝為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等級比較常用,內(nèi)核對pr_debug()分為了三種情況:
如果設(shè)置了 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
-
內(nèi)核
+關(guān)注
關(guān)注
3文章
1383瀏覽量
40434 -
Linux
+關(guān)注
關(guān)注
87文章
11350瀏覽量
210458 -
函數(shù)
+關(guān)注
關(guān)注
3文章
4346瀏覽量
62989
發(fā)布評論請先 登錄
相關(guān)推薦
Linux內(nèi)核中斷設(shè)計與實現(xiàn)
Linux內(nèi)核學(xué)習(xí)筆記:printk調(diào)試
Linux的內(nèi)核教程
Linux內(nèi)核源代碼
linux內(nèi)核kernel-api
基于Android的Linux內(nèi)核的電源管理
![基于Android的<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>的電源管理](https://file.elecfans.com/web1/M00/8F/57/o4YBAFy_9-GAVKfXAABcGcVf2iQ807.png)
linux內(nèi)核是什么_linux內(nèi)核學(xué)習(xí)路線
linux內(nèi)核參數(shù)設(shè)置_linux內(nèi)核的功能有哪些
![<b class='flag-5'>linux</b><b class='flag-5'>內(nèi)核</b>參數(shù)設(shè)置_<b class='flag-5'>linux</b><b class='flag-5'>內(nèi)核</b>的功能有哪些](https://file.elecfans.com/web1/M00/C6/BD/o4YBAF9jBBiAf9uUAAAtvlTBiIE373.jpg)
快速理解什么是Linux內(nèi)核以及Linux內(nèi)核的內(nèi)容
![快速理解什么是<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>以及<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>的內(nèi)容](https://file.elecfans.com/web1/M00/CB/AB/pIYBAF-PsbaASbG3AABoasH5eFg888.png)
Linux內(nèi)核GPIO操作函數(shù)的詳解分析
Linux內(nèi)核熱補丁安全隱患的探索
![<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>熱補丁安全隱患的探索](https://file.elecfans.com/web2/M00/17/48/poYBAGFjtbaAJ-M0AAAms77bcW4911.png)
linux內(nèi)核中do_initcalls函數(shù)的執(zhí)行邏輯分析
Linux內(nèi)核模塊參數(shù)傳遞與sysfs文件系統(tǒng)
萬千設(shè)備,linux內(nèi)核如何知道?
![萬千設(shè)備,<b class='flag-5'>linux</b><b class='flag-5'>內(nèi)核</b>如何知道?](https://file1.elecfans.com/web2/M00/8C/85/wKgaomSt-cSAVYdnAAAI6NkztOU769.png)
Linux內(nèi)核如何使用結(jié)構(gòu)體和函數(shù)指針?
![<b class='flag-5'>Linux</b><b class='flag-5'>內(nèi)核</b>如何使用結(jié)構(gòu)體和<b class='flag-5'>函數(shù)</b>指針?](https://file1.elecfans.com/web2/M00/A1/C9/wKgZomT38MGANWMgAABk_lYUJ0w67.jpeg)
評論