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开发板上会用到的。

  • 相关阅读:
    dataframe字段过长被截断
    sublime text 3安装Anaconda插件之后写python出现白框
    在tkinter中使用matplotlib
    RemoteDisconnected: Remote end closed connection without response
    object of type 'Response' has no len()
    matploylib之热力图
    pycharm格式化python代码快捷键Ctrl+Alt+L失效
    Windows下Redis集群配置
    七牛云--对象存储
    Spring发送邮件
  • 原文地址:https://www.cnblogs.com/yangguang-it/p/7047621.html
Copyright © 2011-2022 走看看