【问题标题】:Debug a linux kernel module using gdb使用 gdb 调试 linux 内核模块
【发布时间】:2016-07-18 07:38:22
【问题描述】:

我想知道 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.

请帮忙。

【问题讨论】:

  • 如果文件没有符号,它就没有符号:即使知道段的地址,也无法调试。你必须得到一个带有符号的文件或一个与你的二进制文件相对应的单独的符号文件。
  • 有没有办法编译模块来合并符号?

标签: c linux linux-kernel gdb


【解决方案1】:

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

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

不确定它是否会起作用。

【讨论】:

  • 谢谢,我会试试的。
  • 是的,这对我有用。我还想知道 API 返回?只给出“gdb vnos-module.ko”然后“运行”是行不通的。我遇到了权限问题。
  • 您的 gdb 似乎需要 root 权限才能调试。 Here 有人有类似的问题。我不太明白您所说的“API 返回”是什么意思(但我住的地方是凌晨,所以可能是这种情况),如果您向我解释,我会尽力提供帮助。
  • 感谢您的链接。但问题完全不同。我想做内核模块的实时调试。这就是我说我想知道 API 返回什么时的意思。并且在模块的makefile中使用-g编译器标志帮助我自动添加符号表,但内核模块大小增加的缺点。
  • “但内核模块大小增加的缺点。”将其视为调试(开发版)和发布(条带版)。从我的经验来看,这似乎是发展的普遍趋势。你设置了刹车点吗?您也可以逐行浏览文件。 gdb 甚至尊重你的刹车点吗? (我有一次没有的情况)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
  • 2012-04-11
  • 2013-12-17
  • 2015-03-25
  • 1970-01-01
  • 2017-07-20
相关资源
最近更新 更多