码迷,mamicode.com
首页 > 其他好文 > 详细

binutils工具集之---objdump

时间:2017-06-19 12:53:07      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:ref   man   font   contain   and   data   cti   c/c++   http   

在嵌入式软件开发中,有时需要知道所生成的程序文件中的段信息以分析问题,或者需要查看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.

 

binutils工具集之---objdump

标签:ref   man   font   contain   and   data   cti   c/c++   http   

原文地址:http://www.cnblogs.com/yangguang-it/p/7047621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!