zoukankan      html  css  js  c++  java
  • 每天学点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
  • 相关阅读:
    我爱java系列之---【微服务间的认证—Feign拦截器】
    我爱java系列之---【设置权限的三种解决方案】
    581. Shortest Unsorted Continuous Subarray
    129. Sum Root to Leaf Numbers
    513. Find Bottom Left Tree Value
    515. Find Largest Value in Each Tree Row
    155. Min Stack max stack Maxpop O(1) 操作
    painting house
    Minimum Adjustment Cost
    k Sum
  • 原文地址:https://www.cnblogs.com/hseagle/p/2994831.html
Copyright © 2011-2022 走看看