驱动中的调试方法

来源:互联网 发布:h3c1024交换机端口镜像 编辑:程序博客网 时间:2024/05/17 20:30
/*模块加载是向内核传递参数 如果不传递就用默认的参数*//*用户向内核传递参数的方法 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.2obj-m += debug_example.obuild: kernel_moduleskernel_modules:make -C $(KERDIR) M=$(CURDIR) modulesclean:make -C $(KERDIR) M=$(CURDIR) clean#Comment/ucomment the following line to disable/enable debuggingDEBUG = n#add your debugging flag(or not) to CFLAGSifeq ($(DEBUG),y)DEBFLAGS = -O -g -DXXX_DEBUG  # "-O"is needed to expand inlineselseDEBFLAGS = -O2endif                                 #CFLAGS += $(DEBFLAGS)EXTRA_CFLAGS += $(DEBFLAGS)



原创粉丝点击