每天学点GDB 5

GDB提供了强大的反汇编能力,本节就围绕于该主题而展开。

继续以Hello.c为例。

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv) {
  printf("hello,world\n");
  return 0;
}

编译生成可执行文件

gcc -o hello -g hello.c

用gdb载入进行调试

gdb hello

反汇编main函数

disassemble main

 以下为输出内容

Dump of assembler code for function main:
   0x080483fc <+0>:     push   %ebp
   0x080483fd <+1>:     mov    %esp,%ebp
   0x080483ff <+3>:     and    $0xfffffff0,%esp
   0x08048402 <+6>:     sub    $0x10,%esp
   0x08048405 <+9>:     movl   $0x80484b0,(%esp)
   0x0804840c <+16>:    call   0x80482d0 <puts@plt>
   0x08048411 <+21>:    mov    $0x0,%eax
   0x08048416 <+26>:    leave
   0x08048417 <+27>:    ret
End of assembler dump.

如果留心的话,可能发现在main函数中调用的printf并没有在反汇编中出现。原因在于printf其实使用的是puts。

如果已经知道了地址,想反过来查看是否对应为某一个函数的话,可以使用info symbol指令

info symbol 0x80482d0

输出为

puts@plt in section .plt

说明地址0x80482d0对应于函数puts

与info symbol相对的指令为info address,可以通过名称获得其地址。继续为Puts为例

info addr puts

输出为

Symbol "puts" is at 0x80482d0 in a file compiled without debugging.

反汇编的另外一种方法就是使用x,当程序执行后(注意一定是程序运行后,停在断点处时),可以使用如下指令

x/3i $pc

 

 

posted @ 2013-04-02 09:44  徽沪一郎  阅读(439)  评论(0编辑  收藏  举报