Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2899415
  • 博文数量: 674
  • 博客积分: 17881
  • 博客等级: 上将
  • 技术积分: 4849
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 10:15
文章分类

全部博文(674)

文章存档

2013年(34)

2012年(146)

2011年(197)

2010年(297)

分类: LINUX

2012-06-19 17:40:35

设备驱动调试,在内核中看到内核使用dev_dbg来输出信息,这个函数的实质是调用 prtk(KERN_DE )来输出打印信息。要打开这个开关需要下面两步。 
     1、打开调试开关:你调试的中必然包含了,或者《linux /paltam_device.h》,后者包含了前者,在包含此头文件之前,使用#define DEBUG 1 来打开调试开关:例如 
#include  
#include .h> 
#include  
#include  
#define DEBUG    1 
#include  
     在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>"    /* system is unusable            */ 
#define    KERN_ALERT    "<1>"    /* action must be taken immediately    */ 
#define    KERN_CRIT    "<2>"    /* critical conditions            */ 
#define    KERN_ERR    "<3>"    /* error conditions            */ 
#define    KERN_WARNING    "<4>"    /* warning conditions            */ 
#define    KERN_NOTICE    "<5>"    /* normal but significant condition    */ 
#define    KERN_    "<6>"    /* informational            */ 
#define    KERN_DEBUG    "<7>"    /* debug-level messages            */ 
看到KERN_DEBUG是级别最低的。 
2、文件kernel/printk文件 
/* printk's without a loglevel use this.. */ 
#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */ 
/* We show everything that is MORE important than this.. */ 
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */ 
#define DEFAULT_CONSOLE_LOGLEVEL 8 /* anything MORE serious than KERN_DEBUG */ 
   其中DEFAULT_CONSOLE_LOGLEVEL 为终端console输出的最低级别,比这严重的都将输出。原来该值为7,则调试信息无法输出,修改为8则全部有输出
阅读(958) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~