文章参考书籍自:
<<汇编语言程序设计第二章>>:
第二章简单介绍了控制单元、执行单元、寄存器和标志
ubuntu下开启core文件:
ulimit -u limit
echo "/home/saneri/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
参考文章:
addr2line_markvz的博客-CSDN博客_addr2line
ar 创建修改和展开文件存档
c++filt
#include <stdio.h>
class A
{
public:
int a_func(int a, int b)
{
return a+b;
}
int a_func(int a)
{
return a;
}
};
int main()
{
int aaa = 20;
printf("aaa is :%d\n", aaa);
A bbb;
int ccc = bbb.a_func(30, 40);
printf("ccc is : %d\n", ccc);
int ddd = bbb.a_func(100);
printf("ddd is : %d\n", ddd);
}
如果我们用nm显示:
zhanglei@ubuntu:~$ nm main2
0000000000004010 B __bss_start
0000000000004010 b completed.8061
w __cxa_finalize@@GLIBC_2.2.5
0000000000004000 D __data_start
0000000000004000 W data_start
00000000000010b0 t deregister_tm_clones
0000000000001120 t __do_global_dtors_aux
0000000000003db8 d __do_global_dtors_aux_fini_array_entry
0000000000004008 D __dso_handle
0000000000003dc0 d _DYNAMIC
0000000000004010 D _edata
0000000000004018 B _end
00000000000012c8 T _fini
0000000000001160 t frame_dummy
0000000000003db0 d __frame_dummy_init_array_entry
00000000000021c4 r __FRAME_END__
0000000000003fb0 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
000000000000202c r __GNU_EH_FRAME_HDR
0000000000001000 t _init
0000000000003db8 d __init_array_end
0000000000003db0 d __init_array_start
0000000000002000 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
00000000000012c0 T __libc_csu_fini
0000000000001250 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000001169 T main
U printf@@GLIBC_2.2.5
00000000000010e0 t register_tm_clones
U __stack_chk_fail@@GLIBC_2.4
0000000000001080 T _start
0000000000004010 D __TMC_END__
0000000000001232 W _ZN1A6a_funcEi
0000000000001216 W _ZN1A6a_funcEii
zhanglei@ubuntu:~$
如果用c++filt 显示的就更详细
zhanglei@ubuntu:~$ nm main2 |c++filt
0000000000004010 B __bss_start
0000000000004010 b completed.8061
w __cxa_finalize@@GLIBC_2.2.5
0000000000004000 D __data_start
0000000000004000 W data_start
00000000000010b0 t deregister_tm_clones
0000000000001120 t __do_global_dtors_aux
0000000000003db8 d __do_global_dtors_aux_fini_array_entry
0000000000004008 D __dso_handle
0000000000003dc0 d _DYNAMIC
0000000000004010 D _edata
0000000000004018 B _end
00000000000012c8 T _fini
0000000000001160 t frame_dummy
0000000000003db0 d __frame_dummy_init_array_entry
00000000000021c4 r __FRAME_END__
0000000000003fb0 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
000000000000202c r __GNU_EH_FRAME_HDR
0000000000001000 t _init
0000000000003db8 d __init_array_end
0000000000003db0 d __init_array_start
0000000000002000 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
00000000000012c0 T __libc_csu_fini
0000000000001250 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000001169 T main
U printf@@GLIBC_2.2.5
00000000000010e0 t register_tm_clones
U __stack_chk_fail@@GLIBC_2.4
0000000000001080 T _start
0000000000004010 D __TMC_END__
0000000000001232 W A::a_func(int)
0000000000001216 W A::a_func(int, int)
objdump 查看目标字节信息:
objdump 选项 文件
readelf 显示目标文件信息
win+R 然后 cmd、powershell(更强大)
gcc是GUN C和C++编译器,我们通常使用GCC时,编译器会依次做如下工作:preprocess(预处理),compilation(编译),assembly(汇编),link(链接)。
我们可以使用gcc来生成会变文件
gcc -S main.c 可以生成汇编文件