c – 内核模块没有找到调试符号

用我加载 linux内核模块后
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"

因此,当我尝试从不正确的(?)地址从模块文本段加载符号时,我得到:

(gdb) add-symbol-file /home/mmaptest/mmaptest.ko 0x00
add symbol table from file "/home/mmaptest/mmaptest.ko" at
    .text_addr = 0x0
(y or n) y
Reading symbols from /home/mmaptest/mmaptest.ko...(**no debugging symbols found**)...done.

这是关于模块本身还是加载到内核代码中的情况?为什么所有地址都是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)

相关文章

/** C+⬑ * 默认成员函数 原来C++类中,有6个默认成员函数: 构造函数 析构函数 拷贝...
#pragma once // 1. 设计一个不能被拷贝的类/* 解析:拷贝只会放生在两个场景中:拷贝构造函数以及赋值运...
C类型转换 C语言:显式和隐式类型转换 隐式类型转化:编译器在编译阶段自动进行,能转就转,不能转就编译...
//异常的概念/*抛出异常后必须要捕获,否则终止程序(到最外层后会交给main管理,main的行为就是终止) try...
#pragma once /*Smart pointer 智能指针;灵巧指针 智能指针三大件//1.RAII//2.像指针一样使用//3.拷贝问...
目录&lt;future&gt;future模板类成员函数:promise类promise的使用例程:packaged_task模板类例程...