linux 驱动调试添加调试宏方法

来源:互联网 发布:广州有机云计算 编辑:程序博客网 时间:2024/05/29 19:06
 

linux 驱动调试添加调试宏

1.修改Makefile 添加是否开启debug宏

#Comment / uncomment the following line to disable / enable debugging
DEBUG = y

#Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
 DEBFLAGS = -0 -g -DSCULL_DEBUG # "-0" is needed to expand inlines
else
 DEBFLAGS = -02
endif

CFLAGS += $(DEBFLAGS)


2.在debug打印函数使用的文件处添加该头文件scull_debug.h

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#undef PDEBUG  /* undef it, just in case */

#ifdef SCULL_DEBUG

#ifdef __KERNEL__

/* This on if debugging is on ,and in kernel space */
#define PDEBUG(fmt, args...) printk(KERN_ALERT "[scull]: " fmt, ##args)

#else

/* This one for user space */
#define PDEBUG(fmt, args...) fprintf(stderr, fmt, ##args)

#endif

#else

/* not debugging : nothing */
#define PDEBUG(fmt, args...)

#endif

原创粉丝点击