一、打印调试
linux设备驱动调试,我们在内核中看到内核使用dev_dbg来控制输出信息,这个函数的实质是调用
printk(KERN_DEBUG )来输出打印信息。要打开这个开关需要下面两步。
1.1、打开调试开关
你调试的文件中必然包含了<linux/device.h>,或者<linux /paltforam_device.h>,后者包含了前者,
在包含此头文件之前,使用#define DEBUG 1 来打开调试开关:例如
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/clk.h>
- #include <linux/module.h>
- #define DEBUG 1
- #include <linux/platform_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是级别最低的。
1.2、修改文件kernel/printk文件
- #define DEFAULT_MESSAGE_LOGLEVEL 4
- #define MINIMUM_CONSOLE_LOGLEVEL 1
- #define DEFAULT_CONSOLE_LOGLEVEL 8
其中DEFAULT_CONSOLE_LOGLEVEL 为终端console输出的最低级别,比这严重的都将输出。
原来该值为7,则调试信息无法输出,修改为8则全部有输出。
1.3、修改Makefile
通过配置内核选项,修改Makefile实现显示打印调试信息。Kconfig内容如下:
- config ADC_DEV_DEBUG
- bool "adc dev debugging messages"
- depends on ADC_INTF_DEV
- help
- Say Y here if you want the adc dev
to produce a bunch of debug
- messages to the system
log. Select this
if you are having a
- problem with adc core and want
to see more of what is going
on.
Makefile内容如下:
- #
- # Makefile for the i2c bus drivers.
- #
- obj-$(CONFIG_GSC_SPI0_ADC_CORE) += adc-core.o
- obj-$(CONFIG_ADC_INTF_DEV) += adc-dev.o
- obj-$(CONFIG_ADC_INTF_PROC) += adc-proc.o
- obj-$(CONFIG_ADC_INTF_SYSFS) +=
adc-sysfs.o
- obj-$(CONFIG_GSC3280_ADC) += gsc3280_adc.o
- ccflags-$(CONFIG_GSC_ADC_DEV_DEBUG)
+=
-DGSC3280_ADC_DEV_DEBUG
红色部分即是。当内核配置选中后,CONFIG_GSC_ADC_DEV_DEBUG即被定义,编译后,源码中使用
GSC3280_ADC_DEV_DEBUG宏定义的调试语句将被打印。
第四章--调试技术,布布扣,bubuko.com
第四章--调试技术
原文:http://blog.csdn.net/apple_guet/article/details/21003877