linux下发布的执行文件崩溃的问题定位 心得一则

时间:2023-12-28 17:36:14

C++ Release版本发布到客户处执行时,如果程序崩溃,有什么办法能够快速的确认程序的问题呢?

  • 如果能gdb调试的话,比较简单了,可以使用gdb命令,类似如下:

gdb ##
set args ****
b main
r
#eip
x/10i 0xb7362040

  • 如果开发不在现场等情况,此时可以使用记录崩溃日志的方法进行分析

此时首先要求的是项目使用类似google breakpad这个工具库,对崩溃进行记录

默认breakpad生成的是dmp文件,可以使用breakpad带的工具转换成文字进行查看,如下:

./minidump-2-core -m 7ee5c76f-afe2-f9bd-564dedb7-57d73e0c.dmp >core

./minidump_stackwalk 7ee5c76f-afe2-f9bd-564dedb7-57d73e0c.dmp > dbg.txt

此时根据如上的信息可以确定哪个模块的地址出错了

由于一般的情况,发布的库的源代码对应版本提取,编译比较麻烦,可以直接拿对应出错的库或执行文件进行分析,使用objdump生成出汇编文件,通过对应地址可以初步找到哪个函数出问题,至于猜测出来的代码,那需要根据分析情况构建单元测试或者重新上线进行检验

具体的一些过程实例如下:
objectdump -d ##.so > ##.o
vim ##.o
6 libTaps2.so + 0xa452d

./minidump_stackwalk 7ee5c76f-afe2-f9bd-564dedb7-57d73e0c.dmp

Thread 7 (crashed)
0 linux-gate.so + 0x430
eip = 0xb78b4430 esp = 0xb2952e18 ebp = 0xb2952e30 ebx = 0x00000fff
esi = 0xb5b98864 edi = 0xb5b97ff4 eax = 0x00000000 ecx = 0x00001008
edx = 0x00000006 efl = 0x00000206
Found by: given as instruction pointer in context
1 libc-2.11.1.so + 0x2da81
eip = 0xb5a6fa82 esp = 0xb2952e38 ebp = 0xb2952f58
Found by: previous frame's frame pointer
2 libstdc++.so.6.0.13 + 0xbf52e
eip = 0xb5cba52f esp = 0xb2952f60 ebp = 0xb2952fa8
Found by: previous frame's frame pointer
3 libstdc++.so.6.0.13 + 0xbd464
eip = 0xb5cb8465 esp = 0xb2952fb0 ebp = 0xb2952fc8
Found by: previous frame's frame pointer
4 libstdc++.so.6.0.13 + 0xbd4a1
eip = 0xb5cb84a2 esp = 0xb2952fd0 ebp = 0xb2952fe8
Found by: previous frame's frame pointer
5 libstdc++.so.6.0.13 + 0xbd5e0
eip = 0xb5cb85e1 esp = 0xb2952ff0 ebp = 0xb2953008
Found by: previous frame's frame pointer
6 libTaps2.so + 0xa452d
eip = 0xb738c52e esp = 0xb2953010 ebp = 0xb2953048
Found by: previous frame's frame pointer
7 libTaps2.so + 0x7a03f
eip = 0xb7362040 esp = 0xb2953050 ebp = 0xb2953068
Found by: previous frame's frame pointer
8 libTaps2.so + 0x6aa9d
eip = 0xb7352a9e esp = 0xb2953070 ebp = 0xb29530b8
Found by: previous frame's frame pointer
9 libTaps2.so + 0x68e69
eip = 0xb7350e6a esp = 0xb29530c0 ebp = 0xb2953108
Found by: previous frame's frame pointer
10 libTaps2.so + 0x691a2
eip = 0xb73511a3 esp = 0xb2953110 ebp = 0xb2953158
Found by: previous frame's frame pointer
11 libTaps2.so + 0x71b9c
eip = 0xb7359b9d esp = 0xb2953160 ebp = 0xb29531a8
Found by: previous frame's frame pointer
12 libTaps2.so + 0x71db1
eip = 0xb7359db2 esp = 0xb29531b0 ebp = 0xb29531b8
Found by: previous frame's frame pointer
13 libTaps2.so + 0xa8ac9
eip = 0xb7390aca esp = 0xb29531c0 ebp = 0xb2953208
Found by: previous frame's frame pointer
14 libTaps2.so + 0xa98d8
eip = 0xb73918d9 esp = 0xb2953210 ebp = 0xb2953288
Found by: previous frame's frame pointer
15 libTaps2.so + 0xa78b0
eip = 0xb738f8b1 esp = 0xb2953290 ebp = 0xb29532b8
Found by: previous frame's frame pointer
16 libTaps2.so + 0xa7960
eip = 0xb738f961 esp = 0xb29532c0 ebp = 0xb29532e8
Found by: previous frame's frame pointer
17 libTaps2.so + 0xa88a5
eip = 0xb73908a6 esp = 0xb29532f0 ebp = 0xb2953338
Found by: previous frame's frame pointer
18 libTaps2.so + 0x7207a
eip = 0xb735a07b esp = 0xb2953340 ebp = 0xb2953358
Found by: previous frame's frame pointer
19 tapsdaemon + 0x2e168
eip = 0x08076169 esp = 0xb2953360 ebp = 0xb2953388
Found by: previous frame's frame pointer
20 libpthread-2.11.1.so + 0x596d
eip = 0xb5ba196e esp = 0xb2953390 ebp = 0xb2953488
Found by: previous frame's frame pointer
21 libc-2.11.1.so + 0xcda4d
eip = 0xb5b0fa4e esp = 0xb2953490 ebp = 0x00000000
Found by: previous frame's frame pointer