objdump是显示object文件的详细信息的工具
-a, --archive-headers 显示档案库的成员信息,类似 ls -l 将文件的信息列出
-f, --file-headers 显示档案文件的整体头部摘要信息
-p, --private-headers Display object format specific file header contents
-P, --private=OPT,OPT... Display object format specific contents
-h, --[section-]headers 显示目标文件各个section的头部摘要信息
-x, --all-headers 显示所可用的头信息,包括符号表、重定位入口。-x 等价于-a -f -h -r -t 同时指定
-d, --disassemble 从objfile中反汇编那些特定指令机器码的section
-D, --disassemble-all 反汇编所有section
--disassemble=<sym> Display assembler contents from <sym>
-S, --source 尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,效果比较明显。隐含了-d参数。
--source-comment[=<txt>] Prefix lines of source code with <txt>
-s, --full-contents 显示指定section的完整内容。默认所有的非空section都会被显示
-g, --debugging 显示调试信息。企图解析保存在文件中的调试信息并以C语言的语法显示出来。仅仅支持某些类型的调试信息。有些其他的格式被readelf -w支持
-e, --debugging-tags 类似-g选项,但是生成的信息是和ctags工具相兼容的格式
-G, --stabs Display (in raw form) any STABS info in the file
-W, --dwarf[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,
f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,
m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,
s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,
U/=trace_info]
Display the contents of DWARF debug sections
-Wk,--dwarf=links Display the contents of sections that link to
separate debuginfo files
-WK,--dwarf=follow-links
Follow links to separate debug info files (default)
-WN,--dwarf=no-follow-links
Do not follow links to separate debug info files
-L, --process-links Display the contents of non-debug sections in
separate debuginfo files. (Implies -WK)
--ctf=SECTION Display CTF info from SECTION
-t, --syms 显示文件的符号表入口。类似于nm -s提供的信息
-T, --dynamic-syms 显示文件的动态符号表入口,仅仅对动态目标文件意义,比如某些共享库。它显示的信息类似于 nm -D|--dynamic 显示的信息
-r, --reloc 显示文件的重定位入口。如果和-d或者-D一起使用,重定位部分以反汇编后的格式显示出来
-R, --dynamic-reloc 显示文件的动态重定位入口,仅仅对于动态目标文件意义,比如某些共享库。
@<file> Read options from <file>
-v, --version Display this program's version number
-i, --info 显示对于 -b 或者 -m 选项可用的架构和目标格式列表。
-H, --help Display this information
简单使用方法
#显示mytest.o文件中的text段的内容
[root@localhost test]# objdump --section=.text -s mytest.o
mytest.o: file format elf32-i386
Contents of section .text:
0000 5589e583 ec10c645 ff61c9c3 5589e583 U......E.a..U...
0010 ec10c745 fc020000 008345fc 02c9c3 ...E......E....
#反汇编出mytest.o的源代码
[root@localhost test]# objdump -S mytest.o
mytest.o: file format elf32-i386
Disassembly of section .text:
00000000 <_Z9printTestv>:
void printTest()
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 10 sub $0x10,%esp
{
char a;
a = 'a';
6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp)
}
a: c9 leave
b: c3 ret
0000000c <_Z10printTest2v>:
void printTest2()
c: 55 push %ebp
d: 89 e5 mov %esp,%ebp
f: 83 ec 10 sub $0x10,%esp
{
int a = 2;
12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp)
a+=2;
19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp)
}
1d: c9 leave
1e: c3 ret
#显示文件的符号表入口
[root@localhost test]# objdump -t mytest.o
mytest.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 mytest.cpp
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .debug_abbrev 00000000 .debug_abbrev
00000000 l d .debug_info 00000000 .debug_info
00000000 l d .debug_line 00000000 .debug_line
00000000 l d .debug_frame 00000000 .debug_frame
00000000 l d .debug_loc 00000000 .debug_loc
00000000 l d .debug_pubnames 00000000 .debug_pubnames
00000000 l d .debug_aranges 00000000 .debug_aranges
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .comment 00000000 .comment
00000000 g F .text 0000000c _Z9printTestv
00000000 *UND* 00000000 __gxx_personality_v0
0000000c g F .text 00000013 _Z10printTest2v
#反汇编特定段,并将汇编代码对应的文件名称和行号对应上
[root@localhost test]# objdump -d -l mytest.o
mytest.o: file format elf32-i386
Disassembly of section .text:
00000000 <_Z9printTestv>:
_Z9printTestv():
/root/test/04_libraryTest/mytest.cpp:1
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 10 sub $0x10,%esp
/root/test/04_libraryTest/mytest.cpp:4
6: c6 45 ff 61 movb $0x61,0xffffffff(%ebp)
/root/test/04_libraryTest/mytest.cpp:5
a: c9 leave
b: c3 ret
0000000c <_Z10printTest2v>:
_Z10printTest2v():
/root/test/04_libraryTest/mytest.cpp:6
c: 55 push %ebp
d: 89 e5 mov %esp,%ebp
f: 83 ec 10 sub $0x10,%esp
/root/test/04_libraryTest/mytest.cpp:8
12: c7 45 fc 02 00 00 00 movl $0x2,0xfffffffc(%ebp)
/root/test/04_libraryTest/mytest.cpp:9
19: 83 45 fc 02 addl $0x2,0xfffffffc(%ebp)
/root/test/04_libraryTest/mytest.cpp:10
1d: c9 leave
1e: c3 ret
#显示目标文件各个段的头部摘要信息
[root@localhost test]# objdump -h mytest.o
mytest.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000001f 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, readonly, CODE
1 .data 00000000 00000000 00000000 00000054 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000054 2**2
ALLOC
3 .debug_abbrev 00000046 00000000 00000000 00000054 2**0
CONTENTS, READONLY, DEBUGGING
4 .debug_info 000000ed 00000000 00000000 0000009a 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
5 .debug_line 0000003e 00000000 00000000 00000187 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
6 .debug_frame 00000044 00000000 00000000 000001c8 2**2
CONTENTS, RELOC, READONLY, DEBUGGING
7 .debug_loc 00000058 00000000 00000000 0000020c 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_pubnames 0000002f 00000000 00000000 00000264 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
9 .debug_aranges 00000020 00000000 00000000 00000293 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
10 .comment 0000002e 00000000 00000000 000002b3 2**0
CONTENTS, READONLY
11 .note.GNU-stack 00000000 00000000 00000000 000002e1 2**0
CONTENTS, READONLY