objdump命令.docx

上传人:b****3 文档编号:27053490 上传时间:2023-06-26 格式:DOCX 页数:14 大小:18.87KB
下载 相关 举报
objdump命令.docx_第1页
第1页 / 共14页
objdump命令.docx_第2页
第2页 / 共14页
objdump命令.docx_第3页
第3页 / 共14页
objdump命令.docx_第4页
第4页 / 共14页
objdump命令.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

objdump命令.docx

《objdump命令.docx》由会员分享,可在线阅读,更多相关《objdump命令.docx(14页珍藏版)》请在冰豆网上搜索。

objdump命令.docx

objdump命令

objdump命令

objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具。

选项

--archive-headers

-a

显示档案库的成员信息,类似ls-l将lib*.a的信息列出。

-bbfdname

--target=bfdname

指定目标码格式。

这不是必须的,objdump能自动识别许多格式,比如:

objdump-boasys-mvax-hfu.o

显示fu.o的头部摘要信息,明确指出该文件是Vax系统下用Oasys编译器生成的目标文件。

objdump-i将给出这里可以指定的目标码格式列表。

-C

--demangle

将底层的符号名解码成用户级名字,除了去掉所开头的下划线之外,还使得C++函数名以可理解的方式显示出来。

--debugging

-g

显示调试信息。

企图解析保存在文件中的调试信息并以C语言的语法显示出来。

仅仅支持某些类型的调试信息。

有些其他的格式被readelf-w支持。

-e

--debugging-tags

类似-g选项,但是生成的信息是和ctags工具相兼容的格式。

--disassemble

-d

从objfile中反汇编那些特定指令机器码的section。

-D

--disassemble-all

与-d类似,但反汇编所有section.

--prefix-addresses

反汇编的时候,显示每一行的完整地址。

这是一种比较老的反汇编格式。

-EB

-EL

--endian={big|little}

指定目标文件的小端。

这个项将影响反汇编出来的指令。

在反汇编的文件没描述小端信息的时候用。

例如S-records.

-f

--file-headers

显示objfile中每个文件的整体头部摘要信息。

-h

--section-headers

--headers

显示目标文件各个section的头部摘要信息。

-H

--help

简短的帮助信息。

-i

--info

显示对于-b或者-m选项可用的架构和目标格式列表。

-jname

--section=name

仅仅显示指定名称为name的section的信息

-l

--line-numbers

用文件名和行号标注相应的目标代码,仅仅和-d、-D或者-r一起使用使用-ld和使用-d的区别不是很大,在源码级调试的时候有用,要求编译时使用了-g之类的调试编译选项。

-mmachine

--architecture=machine

指定反汇编目标文件时使用的架构,当待反汇编文件本身没描述架构信息的时候(比如S-records),这个选项很有用。

可以用-i选项列出这里能够指定的架构.

--reloc

-r

显示文件的重定位入口。

如果和-d或者-D一起使用,重定位部分以反汇编后的格式显示出来。

--dynamic-reloc

-R

显示文件的动态重定位入口,仅仅对于动态目标文件意义,比如某些共享库。

-s

--full-contents

显示指定section的完整内容。

默认所有的非空section都会被显示。

-S

--source

尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,效果比较明显。

隐含了-d参数。

--show-raw-insn

反汇编的时候,显示每条汇编指令对应的机器码,如不指定--prefix-addresses,这将是缺省选项。

--no-show-raw-insn

反汇编时,不显示汇编指令的机器码,如不指定--prefix-addresses,这将是缺省选项。

--start-address=address

从指定地址开始显示数据,该选项影响-d、-r和-s选项的输出。

--stop-address=address

显示数据直到指定地址为止,该项影响-d、-r和-s选项的输出。

-t

--syms

显示文件的符号表入口。

类似于nm-s提供的信息

-T

--dynamic-syms

显示文件的动态符号表入口,仅仅对动态目标文件意义,比如某些共享库。

它显示的信息类似于nm-D|--dynamic显示的信息。

-V

--version

版本信息

--all-headers

-x

显示所可用的头信息,包括符号表、重定位入口。

-x等价于-a-f-h-r-t同时指定。

-z

--disassemble-zeroes

一般反汇编输出将省略大块的零,该选项使得这些零块也被反汇编。

@file可以将选项集中到一个文件中,然后使用这个@file选项载入。

实例

首先,在给出后面大部分测试所基于的源代码以及编译指令。

源代码如下:

[root@localhosttest]#nlmytest.cppvoidprintTest(){

chara;

a='a';

}

voidprintTest2(){

inta=2;

a+=2;

}对以上源代码进行编译,如下:

[root@localhosttest]#g++-c-gmytest.cpp这里,生成的文件是mytest.o,为了方便测试包含了调试的信息,对可执行文件的测试,显示的结果类似。

查看当前使用的objdump的版本号:

[root@localhosttest]#objdump-V

GNUobjdump2.17.50.0.6-14.el520061020

Copyright2005freeSoftwareFoundation,Inc.

Thisprogramisfreesoftware;youmayredistributeitunderthetermsof

theGNUGeneralPublicLicense.Thisprogramhasabsolutelynowarranty.查看档案库文件中的信息:

[root@localhosttest]#objdump-alibmy2.a

Inarchivelibmy2.a:

myfile.o:

fileformatelf32-i386

rwxrwxrwx0/02724Nov1616:

062009myfile.o

mytest.o:

fileformatelf32-i386

rw-r--r--0/0727Jul1315:

322011mytest.o这里,libmy2.a是一个使用ar命令将多个*.o目标文件打包而生成的静态库。

命令的输出类似ar-tv,相比较ar-tv输出如下:

[root@localhosttest]#ar-tvlibmy2.a

rwxrwxrwx0/02724Nov1616:

062009myfile.o

rw-r--r--0/0727Jul1315:

322011mytest.o显示可用的架构和目标结构列表:

[root@localhosttest]#objdump-i

BFDheaderfileversion2.17.50.0.6-14.el520061020

elf32-i386

(headerlittleendian,datalittleendian)

i386

a.out-i386-linux

(headerlittleendian,datalittleendian)

i386

efi-app-ia32

(headerlittleendian,datalittleendian)

i386

elf64-x86-64

(headerlittleendian,datalittleendian)

i386

elf64-little

(headerlittleendian,datalittleendian)

i386

elf64-big

(headerbigendian,databigendian)

i386

elf32-little

(headerlittleendian,datalittleendian)

i386

elf32-big

(headerbigendian,databigendian)

i386

srec

(headerendiannessunknown,dataendiannessunknown)

i386

symbolsrec

(headerendiannessunknown,dataendiannessunknown)

i386

tekhex

(headerendiannessunknown,dataendiannessunknown)

i386

binary

(headerendiannessunknown,dataendiannessunknown)

i386

ihex

(headerendiannessunknown,dataendiannessunknown)

i386

trad-core

(headerendiannessunknown,dataendiannessunknown)

elf32-i386a.out-i386-linuxefi-app-ia32elf64-x86-64

i386elf32-i386a.out-i386-linuxefi-app-ia32elf64-x86-64

elf64-littleelf64-bigelf32-littleelf32-bigsrecsymbolsrec

i386elf64-littleelf64-bigelf32-littleelf32-bigsrecsymbolsrec

tekhexbinaryihextrad-core

i386tekhexbinaryihex---------这里,显示的信息是相对于-b或者-m选项可用的架构和目标格式列表。

显示mytest.o文件中的text段的内容:

[root@localhosttest]#objdump--section=.text-smytest.o

mytest.o:

fileformatelf32-i386

Contentsofsection.text:

00005589e583ec10c645ff61c9c35589e583U......E.a..U...

0010ec10c745fc020000008345fc02c9c3...E......E....这里注意,不能单独使用-j或者--section,例如objdump--section=.textmytest.o是不会运行成功的。

反汇编mytest.o中的text段内容,并尽可能用源代码形式表示:

[root@localhosttest]#objdump-j.text-Smytest.o

mytest.o:

fileformatelf32-i386

Disassemblyofsection.text:

00000000<_Z9printTestv>:

voidprintTest()

0:

55push%ebp

1:

89e5mov%esp,%ebp

3:

83ec10sub$0x10,%esp

{

chara;

a='a';

6:

c645ff61movb$0x61,0xffffffff(%ebp)

}

a:

c9leave

b:

c3ret

000000c<_Z10printTest2v>:

voidprintTest2()

c:

55push%ebp

d:

89e5mov%esp,%ebp

f:

83ec10sub$0x10,%esp

{

inta=2;

12:

c745fc02000000movl$0x2,0xfffffffc(%ebp)

a+=2;

19:

8345fc02addl$0x2,0xfffffffc(%ebp)

}

1d:

c9leave

1e:

c3ret这里注意,不能单独使用-j或者--section,例如objdump-j.textmytest.o是不会运行成功的。

另外-S命令对于包含调试信息的目标文件,显示的效果比较好,如果编译时没有指定g++的-g选项,那么目标文件就不包含调试信息,那么显示效果就差多了。

反汇编出mytest.o的源代码:

[root@localhosttest]#objdump-Smytest.o

mytest.o:

fileformatelf32-i386

Disassemblyofsection.text:

00000000<_Z9printTestv>:

voidprintTest()

0:

55push%ebp

1:

89e5mov%esp,%ebp

3:

83ec10sub$0x10,%esp

{

chara;

a='a';

6:

c645ff61movb$0x61,0xffffffff(%ebp)

}

a:

c9leave

b:

c3ret

0000000c<_Z10printTest2v>:

voidprintTest2()

c:

55push%ebp

d:

89e5mov%esp,%ebp

f:

83ec10sub$0x10,%esp

{

inta=2;

12:

c745fc02000000movl$0x2,0xfffffffc(%ebp)

a+=2;

19:

8345fc02addl$0x2,0xfffffffc(%ebp)

}

1d:

c9leave

1e:

c3ret这里,尤其当编译的时候指定了-g这种调试参数时,反汇编的效果比较明显。

隐含了-d参数。

显示文件的符号表入口:

[root@localhosttest]#objdump-tmytest.o

mytest.o:

fileformatelf32-i386

SYMBOLTABLE:

00000000ldf*ABS*00000000mytest.cpp

00000000ld.text00000000.text

00000000ld.data00000000.data

00000000ld.bss00000000.bss

00000000ld.debug_abbrev00000000.debug_abbrev

00000000ld.debug_info00000000.debug_info

00000000ld.debug_line00000000.debug_line

00000000ld.debug_frame00000000.debug_frame

00000000ld.debug_loc00000000.debug_loc

00000000ld.debug_pubnames00000000.debug_pubnames

00000000ld.debug_aranges00000000.debug_aranges

00000000ld.note.GNU-stack00000000.note.GNU-stack

00000000ld.comment00000000.comment

00000000gF.text0000000c_Z9printTestv

00000000*UND*00000000__gxx_personality_v0

0000000cgF.text00000013_Z10printTest2v这里,输出的信息类似nm-s命令的输出,相比较之下,nm命令的输出如下:

[root@localhosttest]#nm-smytest.o

0000000cT_Z10printTest2v

00000000T_Z9printTestv

U__gxx_personality_v0显示文件的符号表入口,将底层符号解码并表示成用户级别:

[root@localhosttest]#objdump-t-Cmytest.o

mytest.o:

fileformatelf32-i386

SYMBOLTABLE:

00000000ldf*ABS*00000000mytest.cpp

00000000ld.text00000000.text

00000000ld.data00000000.data

00000000ld.bss00000000.bss

00000000ld.debug_abbrev00000000.debug_abbrev

00000000ld.debug_info00000000.debug_info

00000000ld.debug_line00000000.debug_line

00000000ld.debug_frame00000000.debug_frame

00000000ld.debug_loc00000000.debug_loc

00000000ld.debug_pubnames00000000.debug_pubnames

00000000ld.debug_aranges00000000.debug_aranges

00000000ld.note.GNU-stack00000000.note.GNU-stack

00000000ld.comment00000000.comment

00000000gF.text0000000cprintTest()

00000000*UND*00000000__gxx_personality_v0

0000000cgF.text00000013printTest2()这里,和没-C相比,printTest2函数可读性增加了。

反汇编目标文件的特定机器码段:

[root@localhosttest]#objdump-dmytest.o

mytest.o:

fileformatelf32-i386

Disassemblyofsection.text:

00000000<_Z9printTestv>:

0:

55push%ebp

1:

89e5mov%esp,%ebp

3:

83ec10sub$0x10,%esp

6:

c645ff61movb$0x61,0xffffffff(%ebp)

a:

c9leave

b:

c3ret

0000000c<_Z10printTest2v>:

c:

55push%ebp

d:

89e5mov%esp,%ebp

f:

83ec10sub$0x10,%esp

12:

c745fc02000000movl$0x2,0xfffffffc(%ebp)

19:

8345fc02addl$0x2,0xfffffffc(%ebp)

1d:

c9leave

1e:

c3ret这里,对text段的内容进行了反汇编。

反汇编特定段,并将汇编代码对应的文件名称和行号对应上:

[root@localhosttest]#objdump-d-lmytest.o

mytest.o:

fileformatelf32-i386

Disassemblyofsection.text:

00000000<_Z9printTestv>:

_Z9printTestv():

/root/test/04_libraryTest/mytest.cpp:

1

0:

55push%ebp

1:

89e5mov%esp,%ebp

3:

83ec10sub$0x10,%esp

/root/test/04_libraryTest/mytest.cpp:

4

6:

c645ff61movb$0x61,0xffffffff(%ebp)

/root/test/04_libraryTest/mytest.cpp:

5

a:

c9leave

b:

c3ret

0000000c<_Z10printTest2v>:

_Z10printTest2v():

/root/test/04_libraryTest/mytest.cpp:

6

c:

55push%ebp

d:

89e5mov%esp,%ebp

f:

83ec10sub$0x10,%esp

/root/test/04_libraryTest/mytest.cpp:

8

12:

c745fc02000000movl$0x2,0xfffffffc(%ebp)

/root/test/04_libraryTest/mytest.cpp:

9

19:

8345fc02addl$0x2,0xfffffffc(%ebp)

/root/test/04_libraryTest/mytest.cpp:

10

1d:

c9leave

1e:

c3ret这里,项"-d"从objfile中反汇编那些特定指令机器码的section,而使用"-l"指定用文件名和行号标注相应的目标代码,仅仅和-d、-D或者-r一起使用,使用-ld和使用-d的区别不是很大,在源码级调试的时候有用,要求编译时使用了-g之类的调试编译选项。

显示目标文件各个段的头部摘要信息:

[root@localhosttest]#objdump-hmytest.o

mytest.o:

fileformatelf32-i386

Sections:

IdxNameSizeVMALMAFileoffAlgn

0.te

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 外语学习 > 法语学习

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1