1. objdump
objdump 命令是Linux下的反汇编目标文件或者可执行文件的命令.
a. 反汇编test文件中需要执行指令的section
objdump –d test
b. 反汇编test文件中所有section
objdump –D test
c. 显示test文件的section header信息
objdump –h test
d. 反汇编test文件中需要执行指令的section,并且保留c源代码作为参照
objdump –S test
e. 指定反汇编的指令架构i386, i386:x86-64等
objdump –d –m i386 test
2. nm
nm 用来列出一个目标文件中的各种符号
#cat test.c
static int uninit_static_global;
static int init_static_global = 2;
int unit_global;
char *init_global = "hello, world";
const readOnly = 10;
extern int extern_global;
void function()
{
printf("Hello");
}
int get_local()
{
int local;
static int uninit_local_static;
static int init_local_static = 10;
local = 33;
return local;
}
#gcc -c test.c –g
# nm -A -l -n test.o
test.o: U printf /home/cr7/test/test.c:31
test.o:0000000000000000 T function /home/cr7/test/test.c:29
test.o:0000000000000000 d init_static_global /home/cr7/test/test.c:24
test.o:0000000000000000 b uninit_static_global /home/cr7/test/test.c:23
test.o:0000000000000004 C uninit_global
test.o:0000000000000004 b uninit_local_static.4246 /home/cr7/test/test.c:31
test.o:0000000000000008 D init_global /home/cr7/test/test.c:26
test.o:0000000000000010 d init_local_static.4247
test.o:0000000000000010 R readOnly /home/cr7/test/test.c:27
test.o:0000000000000018 T get_local /home/cr7/test/test.c:33
T: text段代表函数
D: 已初始化da
d: 已初始化bss段(static)数据
R: 只读数据
C: 未初始化da
b: 未初始化bss段(static)数据
-A: 显示符号所属文件
-l: 显示符号所属源文件行号
-n: 所有符号从低地址到高地址排序
Others: –u 只列出未定义符号;
--defined-on
3. addr2line
Addr2line 根据一个代码地址,定位到对应的源文件与代码行
#cat test.c
static int global = 2;
void function()
{
printf("Hello");
global = 10;
}
int main()
{
function();
return 0;
}
#gcc -o test test.c –g
#nm test
00000000004004f4 T function
0000000000601020 d global
0000000000400516 T main
U printf@@GLIBC_2.2.5
#addr2line -a 4004f4 -e test
0x00000000004004f4
/home/cr7/test/test.c:26
-a 文件中地址, -e可执行文件
#addr2line -f 4004f4 -e test
function
/home/cr7/test/test.c:26
-f 显示文件中地址所在函数