Linux驱动开发 -- 打开dev_dbg()
发布日期:2021-06-29 02:35:24 浏览次数:2 分类:技术文章

本文共 1153 字,大约阅读时间需要 3 分钟。

linux设备驱动调试,我们在内核中看到内核使用dev_dbg来控制输出信息,这个函数的实质是调用printk(KERN_DEBUG )来输出打印信息。要打开这个开关需要下面两步。

     1、打开调试开关:你调试的文件中必然包含了 linux/device.h,或者linux/paltforam_device.h,后者包含了前者,在包含此头文件之前,使用#define DEBUG 1 来打开调试开关:例如
#include 
#include 
#include 
#include 
#define DEBUG    1
#include <linux/device.h>


     在linux/device.h文件中:
#define dev_printk(level, dev, format, arg...)    \
    printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)

#ifdef DEBUG
#define dev_dbg(dev, format, arg...)        \
    dev_printk(KERN_DEBUG , dev , format , ## arg)
#else
static inline int __attribute__ ((format (printf, 2, 3)))
dev_dbg(struct device * dev, const char * fmt, ...)
{


    return 0;
}
#endif
    但是这个打开了之后,也不能顺利的输出信息,原因是printk有默认的信息级别。
    linux/kernel文件中
#define    KERN_EMERG    "<0>"    
#define    KERN_ALERT    "<1>"    
#define    KERN_CRIT    "<2>"    
#define    KERN_ERR    "<3>"    
#define    KERN_WARNING    "<4>"    
#define    KERN_NOTICE    "<5>"    
#define    KERN_INFO    "<6>"    
#define    KERN_DEBUG    "<7>"   
 
可以看到KERN_DEBUG是级别最低的。


2、修改文件kernel/printk文件

#define DEFAULT_MESSAGE_LOGLEVEL 4

#define MINIMUM_CONSOLE_LOGLEVEL 1
#define DEFAULT_CONSOLE_LOGLEVEL 8

      其中DEFAULT_CONSOLE_LOGLEVEL 为终端console输出的最低级别,比这严重的都将输出。原来该值为7,则调试信息无法输出,修改为8则全部有输出。

转载地址:https://blog.csdn.net/yyyyyyyyyywwwwwwwwww/article/details/52130241 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Kernel Symbols and CONFIG_MODVERSIONS
下一篇:linux debug开关 dev_dbg

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月02日 03时30分19秒