zoukankan      html  css  js  c++  java
  • Linux驱动开发调试 -- 打开dev_dbg()【转】

    本文转载自:https://blog.csdn.net/kunkliu/article/details/78048618

    转载地址:http://blog.chinaunix.net/uid-22841689-id-3924244.html

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

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

    点击(此处)折叠或打开

    1. #include <linux/kernel.h>
    2. #include <linux/init.h>
    3. #include <linux/clk.h>
    4. #include <linux/module.h>
    5. #define DEBUG 1
    6. #include <linux/platform_device.h>
         在linux/device.h文件中:

    点击(此处)折叠或打开

    1. #define dev_printk(level, dev, format, arg...)
    2.     printk(level "%s %s: " format , dev_driver_string(dev), (dev)->bus_id, ## arg)
    3. #ifdef DEBUG
    4. #define dev_dbg(dev, format, arg...)
    5.     dev_printk(KERN_DEBUG , dev , format , ## arg)
    6. #else
    7. static inline int __attribute__ ((format (printf, 2, 3)))
    8. dev_dbg(struct device * dev, const char* fmt, ...)
    9. {
    10.     return 0;
    11. }
    12. #endif
            但是这个打开了之后,也不能顺利的输出信息,原因是printk有默认的信息级别。
            linux/kernel文件中

    点击(此处)折叠或打开

    1. #define KERN_EMERG "<0>"
    2. #define KERN_ALERT "<1>" 
    3. #define KERN_CRIT "<2>" 
    4. #define KERN_ERR "<3>" 
    5. #define KERN_WARNING "<4>" 
    6. #define KERN_NOTICE "<5>" 
    7. #define KERN_INFO "<6>" 
    8. #define KERN_DEBUG "<7>"
            可以看到KERN_DEBUG是级别最低的。
    1.2、修改文件kernel/printk文件

    点击(此处)折叠或打开

    1. #define DEFAULT_MESSAGE_LOGLEVEL 4
    2. #define MINIMUM_CONSOLE_LOGLEVEL 1
    3. #define DEFAULT_CONSOLE_LOGLEVEL 8
            其中DEFAULT_CONSOLE_LOGLEVEL 为终端console输出的最低级别,比这严重的都将输出。
    原来该值为7,则调试信息无法输出,修改为8则全部有输出。
    1.3、修改Makefile
            通过配置内核选项,修改Makefile实现显示打印调试信息。Kconfig内容如下:

    点击(此处)折叠或打开

    1. config ADC_DEV_DEBUG
    2.     bool "adc dev debugging messages"
    3.     depends on ADC_INTF_DEV
    4.     help
    5.      Say Y here if you want the adc dev to produce a bunch of debug
    6.      messages to the system log. Select thisif you are having a
    7.      problem with adc core and want to see more of what is going on.
            Makefile内容如下:

    点击(此处)折叠或打开

    1. #
    2. # Makefile for the i2c bus drivers.
    3. #
    4. obj-$(CONFIG_GSC_SPI0_ADC_CORE)        += adc-core.o
    5. obj-$(CONFIG_ADC_INTF_DEV)            += adc-dev.o
    6. obj-$(CONFIG_ADC_INTF_PROC)            += adc-proc.o
    7. obj-$(CONFIG_ADC_INTF_SYSFS)            += adc-sysfs.o
    8. obj-$(CONFIG_GSC3280_ADC)            += gsc3280_adc.o
    9. ccflags-$(CONFIG_GSC_ADC_DEV_DEBUG)+= -DGSC3280_ADC_DEV_DEBUG
            红色部分即是。当内核配置选中后,CONFIG_GSC_ADC_DEV_DEBUG即被定义,编译后,源码中使用
    GSC3280_ADC_DEV_DEBUG宏定义的调试语句将被打印。
     
  • 相关阅读:
    mybatis总结(五)(延迟加载)
    mybatis总结(四)(mybatis的动态sql)
    mybatis总结(三)(resultMap和高级映射-级联)
    mybatis总结(二)(mybatis的基本增删改查实例说明)
    mybatis总结(一)(mybatis的基本定义介绍)
    法门扫地僧简历经验分享
    法门扫地僧面试宝典第五版
    关于https不支持http的解决方案
    浏览器渲染原理
    前端面试宝典第三版
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/10172923.html
Copyright © 2011-2022 走看看