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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值