驱动中的调试方法

/*模块加载是向内核传递参数 如果不传递就用默认的参数*/
/*用户向内核传递参数的方法 eg insmod param.ko name="wenhui" age=20*/
/*内核调试信息的使用*/

#undef PDEBUG /*取消对PDEBUG的定义 以防重复定义*/
	#ifdef XXX_DEBUG
		#define PDEBUG(fmt) printk("<0>XXX:%d\n",fmt)
	#else
		#define PDEBUG(fmt) /*调试被关闭不做任何事情*/
    #endif


#include<linux/module.h>
#include<linux/init.h>

MODULE_LICENSE("GPL");
static char *name = "WENHUI";
static int age = 30;

module_param(age, int, S_IRUGO); // S_IRUGO 参数读写权限 
module_param(name, charp, S_IRUGO); //

static int __init hello_init(void)
{
	printk("<0>Name:%s\n",name); //
	printk(KERN_INFO "Age:%d\n",age);  //
	PDEBUG(age);
	return 0;
}

static void __exit hello_exit(void)
{
	printk("<0> Module exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);


KERDIR = /home/linux-2.6.32.2
obj-m += debug_example.o
build: kernel_modules

kernel_modules:
	make -C $(KERDIR) M=$(CURDIR) modules
clean:
	make -C $(KERDIR) M=$(CURDIR) clean

#Comment/ucomment the following line to disable/enable debugging
DEBUG = n

#add your debugging flag(or not) to CFLAGS
ifeq ($(DEBUG),y)
	DEBFLAGS = -O -g -DXXX_DEBUG  # "-O"is needed to expand inlines
else
	DEBFLAGS = -O2
endif

                                 #CFLAGS += $(DEBFLAGS)
EXTRA_CFLAGS += $(DEBFLAGS)



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值