C 内核模块未找到调试符号

C 内核模块未找到调试符号,c,linux,module,gdb,kernel,C,Linux,Module,Gdb,Kernel,在我用 user@c4:$ insmod mmaptest.ko 我可以验证它是否通过 user@c4:$ cat /proc/modules mmaptest 12727 0 - Live 0x0000000000000000 (OF) 但所有段都列出了0x00地址 user@c4$:$ systool -vm mmaptest Module = "mmaptest" Attributes: coresize = "12727" inits

在我用

user@c4:$ insmod mmaptest.ko
我可以验证它是否通过

user@c4:$ cat /proc/modules 
mmaptest 12727 0 - Live 0x0000000000000000 (OF)
但所有段都列出了0x00地址

user@c4$:$ systool -vm mmaptest
  Module = "mmaptest"

  Attributes:
    coresize            = "12727"
    initsize            = "0"
    initstate           = "live"
    refcnt              = "0"
    srcversion          = "EABEF6F90BEAAD0D15B576A"
    taint               = "OF"
    uevent              = <store method only>

  Parameters:
    count               = "0"

  Sections:
    .bss                = "0x0000000000000000"
    .data               = "0x0000000000000000"
    .exit.text          = "0x0000000000000000"
    .gnu.linkonce.this_module= "0x0000000000000000"
    .init.text          = "0x0000000000000000"
    .note.gnu.build-id  = "0x0000000000000000"
    .rodata             = "0x0000000000000000"
    .rodata.str1.1      = "0x0000000000000000"
    .rodata.str1.8      = "0x0000000000000000"
    .smp_locks          = "0x0000000000000000"
    .strtab             = "0x0000000000000000"
    .symtab             = "0x0000000000000000"
    .text               = "0x0000000000000000"
    __mcount_loc        = "0x0000000000000000"
    __param             = "0x0000000000000000"

这是模块本身还是加载到内核代码的情况?为什么所有地址都是0x000000000000?

我的标志不正确。调试符号表是使用此makefile生成的:

obj-m += mmaptest.o
MY_CFLAGS += -g -DDEBUG
ccflags-y += ${MY_CFLAGS}
CC += ${MY_CFLAGS}


all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

debug:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 
        EXTRA_CFLAGS="$(MY_CFLAGS)"
clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 
现在可以通过以下方式进行验证:

peter@c4:$ readelf -S mmaptest.ko | grep debug

  [24] .debug_info       PROGBITS         0000000000000000  00000d40
  [25] .rela.debug_info  RELA             0000000000000000  00018260
  [26] .debug_abbrev     PROGBITS         0000000000000000  0000d577
  [27] .debug_loc        PROGBITS         0000000000000000  0000dd54
  [28] .rela.debug_loc   RELA             0000000000000000  00029510
  [29] .debug_aranges    PROGBITS         0000000000000000  0000e5d5
  [30] .rela.debug_arang RELA             0000000000000000  0002a3e0
  [31] .debug_ranges     PROGBITS         0000000000000000  0000e645
  [32] .rela.debug_range RELA             0000000000000000  0002a458
  [33] .debug_line       PROGBITS         0000000000000000  0000e815
  [34] .rela.debug_line  RELA             0000000000000000  0002a878
  [35] .debug_str        PROGBITS         0000000000000000  0000f4cd
  [38] .debug_frame      PROGBITS         0000000000000000  00016e80
  [39] .rela.debug_frame RELA             0000000000000000  0002a8c0



add symbol table from file "/home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko"
at .text_addr = 0x0
(y or n) y
Reading symbols from /home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko...done.
(gdb) 

但是为什么所有地址仍然是0x000000000000?如果节将出现在进程的内存映像中,那么地址成员将给出节的第一个字节应该驻留的地址。否则,成员将包含0。您可以通过链接获得更多信息@Sridhar当然,它是.o文件(.ko),因此地址是相对的,由偏移量给出。无论如何,感谢您对7f454c46的精彩介绍。但我仍然看不到我的符号。当我执行“whatis mysym_1”时,我得到的类型是int,但当我执行“p mysym_1”时,我得到一个错误-无法访问0x0处的内存。可能有什么问题?为什么在添加了
ccflags-y+=${MY\u CFLAGS}
之后必须添加
CC+=${MY\u CFLAGS}
?顺便说一句,我建议使用
lx符号
加载符号,如所述:
peter@c4:$ readelf -S mmaptest.ko | grep debug

  [24] .debug_info       PROGBITS         0000000000000000  00000d40
  [25] .rela.debug_info  RELA             0000000000000000  00018260
  [26] .debug_abbrev     PROGBITS         0000000000000000  0000d577
  [27] .debug_loc        PROGBITS         0000000000000000  0000dd54
  [28] .rela.debug_loc   RELA             0000000000000000  00029510
  [29] .debug_aranges    PROGBITS         0000000000000000  0000e5d5
  [30] .rela.debug_arang RELA             0000000000000000  0002a3e0
  [31] .debug_ranges     PROGBITS         0000000000000000  0000e645
  [32] .rela.debug_range RELA             0000000000000000  0002a458
  [33] .debug_line       PROGBITS         0000000000000000  0000e815
  [34] .rela.debug_line  RELA             0000000000000000  0002a878
  [35] .debug_str        PROGBITS         0000000000000000  0000f4cd
  [38] .debug_frame      PROGBITS         0000000000000000  00016e80
  [39] .rela.debug_frame RELA             0000000000000000  0002a8c0



add symbol table from file "/home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko"
at .text_addr = 0x0
(y or n) y
Reading symbols from /home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko...done.
(gdb)