zoukankan      html  css  js  c++  java
  • binutils工具集之---objdump

    在嵌入式软件开发中,有时需要知道所生成的程序文件中的段信息以分析问题,或者需要查看c语言对应的汇编代码,此时,objdump工具就可以帮大忙了。obj——object  dump:转储。

    #include<stdio.h>
    #include<time.h>
    
    int global1;
    int global2=3;
    
    static int static_global1;
    static int static_global2=3;
    
    void foo()
    {
            static int internal1;
            static int internal2=3;
             time(0);
    }
    
    static void bar()
    {
    
    }
      int main(void)
    {
            int local1;
            int local2=3;
            foo();
            return 0;
    }

    采用 -d选项,可以查看程序文件的汇编代码:

    在使用-d进行反汇编时,另一个很有用的选项就是-S(大写),它的作用是告诉objdump在反汇编时同时显示汇编代码对应的c/c++源程序。

    想查看对应反汇编,一定要在编译的时候加上-g选项生成debug信息,否则不会成功:

    -f选项可以显示程序文件的头信息。

    objdump另一个非常有用的选项是-s(小写),将它与-j参数配合使用,能查看某一个段中的具体内容。

     更多指令参考man或者info介绍:

    -s
    --full-contents
    Display the full contents of any sections requested. By default
    all non-empty sections are displayed.

    -S
    --source
    Display source code intermixed with disassembly, if possible.//这下知道为什么刚才说的要加上-g生成调试信息了把,-S并不是强制显示程序文件,而是
    Implies -d.                                                                                //在可能的情况下,进行显示,所以要想可能,就加上-g生成调试信息。

    -d
    --disassemble
    Display the assembler mnemonics for the machine instructions from
    objfile. This option only disassembles those sections which are
    expected to contain instructions.

    -D
    --disassemble-all
    Like -d, but disassemble the contents of all sections, not just
    those expected to contain instructions.

    This option also has a subtle effect on the disassembly of
    instructions in code sections. When option -d is in effect objdump
    will assume that any symbols present in a code section occur on the
    boundary between instructions and it will refuse to disassemble
    across such a boundary. When option -D is in effect however this
    assumption is supressed. This means that it is possible for the
    output of -d and -D to differ if, for example, data is stored in
    code sections.

    If the target is an ARM architecture this switch also has the
    effect of forcing the disassembler to decode pieces of data found
    in code sections as if they were instructions.

    -h
    --section-headers
    --headers
    Display summary information from the section headers of the object
    file.

    File segments may be relocated to nonstandard addresses, for
    example by using the -Ttext, -Tdata, or -Tbss options to ld.
    However, some object file formats, such as a.out, do not store the
    starting address of the file segments. In those situations,
    although ld relocates the sections correctly, using objdump -h to
    list the file section headers cannot show the correct addresses.
    Instead, it shows the usual addresses, which are implicit for the
    target.

    -m machine
    --architecture=machine
    Specify the architecture to use when disassembling object files.
    This can be useful when disassembling object files which do not
    describe architecture information, such as S-records. You can list
    the available architectures with the -i option.

    If the target is an ARM architecture then this switch has an
    additional effect. It restricts the disassembly to only those
    instructions supported by the architecture specified by machine.
    If it is necessary to use this switch because the input file does
    not contain any architecture information, but it is also desired to
    disassemble all the instructions use -marm.

    以上列出的,都是在之后arm开发板上会用到的。

  • 相关阅读:
    leetcode778
    2020年的一些总结
    go笔记 NSQ (6) ( nsqd如何创建消费者以及消费消息)
    go笔记 NSQ (5) ( nsqd如何监听生产者的消息,select关键字使用)
    go笔记 NSQ (4) ( nsqd启动监听来了解go如何编写tcp与http服务端,以及sync.WaitGroup线程同步工具使用 )
    go笔记 NSQ (3) ( 从启动nsqd了解flag包使用,解析配置文件以及json有关,反射使用 )
    Sitecore去除地址中带语言,例:localhost:8080/zh-cn/index
    js给URL追加参数
    SQL Server服务启动时错误:1069(由于登陆失败而无法启动服务)
    C# windows服务定时处理/例每天凌晨1点处理数据
  • 原文地址:https://www.cnblogs.com/yangguang-it/p/7047621.html
Copyright © 2011-2022 走看看