c - 使用 gdb 调试 Linux 内核模块

标签 c linux linux-kernel gdb

我想知道 API 在内核模块 中返回什么。

从几个表格来看,事情并不是那么简单,我们需要加载符号表来调试内核模块。

所以我所做的就是, 1.试图找到内核模块的.text、.bss和.data段地址。 2. 在gdb中使用add-symbol-file命令添加符号表文件。

但我收到错误消息“从/fabos/modules/vnos-module.ko 读取符号...(未找到调试符号)...完成。”

我这里有什么遗漏的吗?

root@sw0:/sys/module/vnos_module/sections# cat .text .data .bss 
0xf7f7f000
0xf7fb7a30
0xf7fc3da4

root@sw0:/sys/module/vnos_module/sections# gdb /fabos/modules/vnos-module.ko
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /fabos/modules/vnos-module.ko...(no debugging symbols found)...done.
 add-symbol-file /fabos/modules/vnos-module.ko 0xf7f7f000 -s .data 0xf7fb7a -s .bss 0xf7fc3da4
add symbol table from file "/fabos/modules/vnos-module.ko" at
        .text_addr = 0xf7f7f000
        .data_addr = 0xf7fb7a30
(y or n) y

Reading symbols from /fabos/modules/vnos-module.ko...(no debugging symbols found)...done.

请帮忙。

最佳答案

由于我无法发表评论,所以我会写一个答案。 (但我知道这更像是评论部分的帖子,因为我对此不是 100% 确定)

您必须使用调试符号来编译模块。为此,模块应该在不剥离的情况下进行编译。您可能还想尝试 -g 选项并在内核 CONFIG_DEBUG_INFO=y 中启用调试。

不确定是否有效。

关于c - 使用 gdb 调试 Linux 内核模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38431060/

相关文章:

Linux I2C 内核驱动绑定(bind)

android - 内核开发新手 : "Virtual" input driver in kernel?

c - 未初始化字符数组的 %d 说明符

c - uint64_t 的计算结果错误

linux - 在 Linux 中使用符号链接(symbolic link)将文件从一个位置 move 到另一个位置

linux - 如何从在 centos 中作为服务运行的进程访问环境变量?

html - ubuntu 中的 css @font-face 不起作用

c - 使用 procfs 的内核用户输出在哪里?

c - if 语句中使用的 C 函数中对数组类型表达式进行赋值错误

python - 编写通用脚本将数据从文件上传到数据库表