【2018-01-11】Linux下使用addr2line来定位进程崩溃

发布时间:2026/7/17 6:25:28
【2018-01-11】Linux下使用addr2line来定位进程崩溃 [历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2018-01-11 标题Linux下使用addr2line来定位进程崩溃分类编程 标签linux·addr2linelinux addr2line 的简单笔记测试代码整体编译静态库动态库废话不讲。测试代码main_entry.c#includestdio.h#includemylib.hintmain(void){test_funcA();return0;}mylib.h#ifndefMY_LIB_H#defineMY_LIB_Hvoidtest_funcA(void);#endif// MY_LIB_Hmylib.c#includestdio.h#includemylib.hvoidtest_funcA(void){printf(Init test_funcA called );int*pX0;*pX100;printf(test_funcA called );}整体编译cstriker1407cstriker1407:~/workspace/libtest$ gcc-gmain_entry.c mylib.c-odirect.bin cstriker1407cstriker1407:~/workspace/libtest$ cstriker1407cstriker1407:~/workspace/libtest$ cstriker1407cstriker1407:~/workspace/libtest$ ./direct.bin Init test_funcA called 段错误(核心已转储)cstriker1407cstriker1407:~/workspace/libtest$dmesg|tail........[21840.270979]direct.bin[14218]: segfault at0ip0000559b33b3c6d0 sp 00007ffe9c674dc0 error6indirect.bin[559b33b3c0001000]6D00000559b33b3c6d0 - 559b33b3c000 cstriker1407cstriker1407:~/workspace/libtest$ addr2line-edirect.bin 6D0-f-ptest_funcA 于 /home/cstriker1407/workspace/libtest/mylib.c:10静态库cstriker1407cstriker1407:~/workspace/libtest$ gcc-g-cmylib.c-omylib.o cstriker1407cstriker1407:~/workspace/libtest$ ar-rcslibmylib.a mylib.o cstriker1407cstriker1407:~/workspace/libtest$ gcc-gmain_entry.c -L.-lmylib-ostatic.bin cstriker1407cstriker1407:~/workspace/libtest$ ./static.bin Init test_funcA called 段错误(核心已转储)cstriker1407cstriker1407:~/workspace/libtest$dmesg|tail........[22252.413286]static.bin[14519]: segfault at0ip0000563d3fee26d0 sp 00007ffc7a0a95d0 error6instatic.bin[563d3fee20001000]6D00000563d3fee26d0 - 563d3fee2000 cstriker1407cstriker1407:~/workspace/libtest$ addr2line-estatic.bin 6D0-f-ptest_funcA 于 /home/cstriker1407/workspace/libtest/mylib.c:10动态库cstriker1407cstriker1407:~/workspace/libtest$ gcc-g-DPIC-fPIC-cmylib.c-omylib.o cstriker1407cstriker1407:~/workspace/libtest$ gcc-g-shared-DPIC-fPIC-olibmylib.so mylib.o cstriker1407cstriker1407:~/workspace/libtest$ gcc-gmain_entry.c -L.-lmylib-odynamic.bin cstriker1407cstriker1407:~/workspace/libtest$exportLD_LIBRARY_PATH${LD_LIBRARY_PATH}:./ cstriker1407cstriker1407:~/workspace/libtest$ldddynamic.bin linux-vdso.so.1(0x00007ffcdd78a000)libmylib.so(0x00007f8ef5fe3000)libc.so.6/lib/x86_64-linux-gnu/libc.so.6(0x00007f8ef5bf7000)/lib64/ld-linux-x86-64.so.2(0x000055f746964000)cstriker1407cstriker1407:~/workspace/libtest$ ./dynamic.bin Init test_funcA called 段错误(核心已转储)cstriker1407cstriker1407:~/workspace/libtest$dmesg|tail.........[22598.662423]dynamic.bin[14722]: segfault at0ip00007f91f48bb6a0 sp 00007ffc18dd83b0 error6inlibmylib.so[7f91f48bb0001000]cstriker1407cstriker1407:~/workspace/libtest$ addr2line-elibmylib.so 6a0-f-ptest_funcA 于 /home/cstriker1407/workspace/libtest/mylib.c:10