正在运行的内核反汇编

5

我尝试使用gdb来反汇编内核,并尝试运行:

root@debian:/home/jestinjoy# gdb /usr/src/linux-2.6.38.8/vmlinux
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/src/linux-2.6.38.8/vmlinux...done.
(gdb) disass sys_read
Dump of assembler code for function sys_read:
0xc10cacb9 <sys_read+0>:    push   %ebp
0xc10cacba <sys_read+1>:    mov    %esp,%ebp
0xc10cacbc <sys_read+3>:    push   %esi
0xc10cacbd <sys_read+4>:    mov    $0xfffffff7,%esi
0xc10cacc2 <sys_read+9>:    push   %ebx
0xc10cacc3 <sys_read+10>:   sub    $0xc,%esp
0xc10cacc6 <sys_read+13>:   mov    0x8(%ebp),%eax
0xc10cacc9 <sys_read+16>:   lea    -0xc(%ebp),%edx
0xc10caccc <sys_read+19>:   call   0xc10cb346 <fget_light>
0xc10cacd1 <sys_read+24>:   test   %eax,%eax
0xc10cacd3 <sys_read+26>:   mov    %eax,%ebx
0xc10cacd5 <sys_read+28>:   je     0xc10cad10 <sys_read+87>
0xc10cacd7 <sys_read+30>:   mov    0x2c(%ebx),%edx
0xc10cacda <sys_read+33>:   mov    0x28(%eax),%eax
0xc10cacdd <sys_read+36>:   mov    0x10(%ebp),%ecx
0xc10cace0 <sys_read+39>:   mov    %edx,-0x10(%ebp)
0xc10cace3 <sys_read+42>:   mov    0xc(%ebp),%edx
0xc10cace6 <sys_read+45>:   mov    %eax,-0x14(%ebp)
0xc10cace9 <sys_read+48>:   lea    -0x14(%ebp),%eax
0xc10cacec <sys_read+51>:   push   %eax
0xc10caced <sys_read+52>:   mov    %ebx,%eax
0xc10cacef <sys_read+54>:   call   0xc10cab82 <vfs_read>
0xc10cacf4 <sys_read+59>:   mov    -0x10(%ebp),%edx
0xc10cacf7 <sys_read+62>:   mov    %eax,%esi

它运行得很好。但是当我尝试运行时

root@debian:/home/jestinjoy# gdb /usr/src/linux-2.6.38.8/vmlinux /proc/kcore 
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/src/linux-2.6.38.8/vmlinux...done.
Core was generated by `BOOT_IMAGE=/boot/vmlinuz-2.6.38.8 root=UUID=b61e8ee2-949a-4810-ac56-42564ee005d7'.
#0  0x00000000 in ?? ()
(gdb) disass sys_read
Dump of assembler code for function sys_read:
0xc10cacb9 <sys_read+0>:    add    %al,(%eax)
0xc10cacbb <sys_read+2>:    add    %al,(%eax)
0xc10cacbd <sys_read+4>:    add    %al,(%eax)
0xc10cacbf <sys_read+6>:    add    %al,(%eax)
0xc10cacc1 <sys_read+8>:    add    %al,(%eax)
0xc10cacc3 <sys_read+10>:   add    %al,(%eax)
0xc10cacc5 <sys_read+12>:   add    %al,(%eax)
0xc10cacc7 <sys_read+14>:   add    %al,(%eax)
0xc10cacc9 <sys_read+16>:   add    %al,(%eax)
0xc10caccb <sys_read+18>:   add    %al,(%eax)
0xc10caccd <sys_read+20>:   add    %al,(%eax)
0xc10caccf <sys_read+22>:   add    %al,(%eax)
0xc10cacd1 <sys_read+24>:   add    %al,(%eax)
0xc10cacd3 <sys_read+26>:   add    %al,(%eax)
0xc10cacd5 <sys_read+28>:   add    %al,(%eax)
0xc10cacd7 <sys_read+30>:   add    %al,(%eax)

它给出了奇怪的结果。我正在运行 CONFIG_DEBUG_INFO=y 和内核版本为2.6.38。

看起来你正在加载一个与你启动的内核不同的内核 - 如果你已经安装了内核,这可能是或可能不是情况。/proc/kcore 报告内核是 /boot/vmlinuz-2.6.38.8。另外,如果你能发布你的 .config,那可能有助于得到更好的答案。 - synthesizerpatel
我的 config 可以在 http://pastebin.com/BiNpDmvY 找到。我是否错过了一些配置? - user567879
如果你只想反汇编内核,为什么不直接反汇编镜像呢? - Samuel Edwin Ward
3个回答

2

禁用CONFIG_RELOCATABLE

不能简单地使用gdb调试正在运行的内核!

Linux内核提供了两种不同的调试前端(kdbKGDB),它们有些不同,但幸运的是可以在运行时切换它们。

kdb不是源级别的调试器(因此不是您要寻找的那个),可以在本地机器上的系统控制台或通过另一台机器的串行连接上使用。

KGDB是一个源级别的调试器,但需要两台机器来操作-其中一台是被调试的主体(也就是运行被调试代码的目标机器),另一台是开发机器,在该机器上运行gdb针对vmlinux文件(与目标机器运行的相同文件)。并且目标机器和开发机器之间的连接是通过串行端口完成的...

现在,在内核的Documentation目录下有大量关于如何设置所有内容的文档。只需搜索任何一个: kdbkgdboc,...


实际上,您可以使用gdb调试运行中的内核(前提是您有带有调试符号的内核映像)- 您只是无法在断点处停止它等。 - gby
@gby 我不认为那是调试。 - plaes
由于您可以从任何内存位置提取值,因此它非常有用来调试许多现象。 - gby

1

在您的机器上执行 "grep sys_read /proc/kallsyms" 命令会输出什么?如果不是 0xc10cacb9,那么您的运行内核源代码或配置与原始代码不同,因此地址不匹配。


cat /boot/System.map-2.6.38.8 | grep sys_read 表示 0xc10cacb9 - user567879
抱歉,我的问题有些被截断了。我想问的是,“grep sys_read /proc/kallsyms”在你的机器上读取了什么?原因是/proc/kallsyms来自实际运行的内核,而/boot/Systems.map-2.6.38.8是安装在之前的某个内核中的。由于我怀疑正在运行的内核可能不同,我想验证实际运行内核的地址。 - gby

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接