内核调试选项

来源:互联网 发布:实体店和淘宝买家具 编辑:程序博客网 时间:2024/06/08 08:15

用printk在终端看不到显示是因为printk是在kernel里面执行的啊 终端只是一个加载的过程

******************初稿待验证,本人对调试还不大了解************************

在前面已经建议过:学习编写驱动程序要构建安装自己的内核(标准主线内核)。最重要的原因之一是:内核开发者已经建立了多项用于调试的功能。但是由于这些功能会造成额外的输出,并导致能下降,因此发行版厂商通常会禁止发行版内核中的调试功能。
为了实现内核调试,我在内核配置上增加了几项:
  Kernel hacking  --->     
        [*] Magic SysRq key
        [*] Kernel debugging
        [*]   Debug slab memory allocations  
        [*]   Spinlock and rw-lock debugging: basic checks 
        [*]   Spinlock debugging: sleep-inside-spinlock checking
        [*]   Compile the kernel with debug info  
        [*] Magic SysRq key 
Device Drivers  --->  
        Generic Driver Options  --->
          [*] Driver Core verbose debug messages 
General setup  --->
       [*] Configure standard kernel features (for small systems)  --->
          [*]   Load all symbols for debugging/ksymoops
 为了方便的打开和关闭调试信息  Makefile中要添加的语句:

# Comment/uncomment the following line to disable/enable debugging
DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
else

DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS)    

完整的Makefile文件

# Comment/uncomment the following line to disable/enable debugging
DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS)

# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o #param-objs := file1.o file2.o
obj-m := hello.o         #obj-m := param.o

else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
    $(MAKE) -C $(KDIR) M=$(PWD)
clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean
endif

原创粉丝点击