利用dwarfdump分析线上iOS Crash Log
文章目录
线上的CrashLog利用UserTrack的搜集的话一般都无法识别,比如
3 XXX 0x00126adf XXX + 1006303
4 XXX 0x0005ff49 XXX + 192329
5 Foundation 0x33a864a1 <redacted> + 460
6 CoreFoundation 0x331438f7 <redacted> + 14
7 CoreFoundation 0x331431f3 <redacted> + 362
那么怎么去识别这种CrashLog呢?
Mac提供了一个dwarfdump的小工具来解析这种CrashLog,需要dSYM的配合
利用dwarfdump --lookup=ADDRESS DSYMFILE
的方式查找crash出错的地址在DSYM文件中的代码段
我这里提供一个Python的小工具,直接输入address offset(就是上面的堆栈里+号后面的那个数字),生成一个可读的堆栈
#!/usr/bin/python
# wentong@taobao.com
# 13-5-3
#
import optparse
import os
DSYM = ""
def map_hex(x):
return """dwarfdump --lookup=%s %s|grep -E "start_addr:|Line table file:";echo -------------------; """ % (
hex(0x00001000 + int(x)), DSYM)
def add(x, y):
return x + y
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option("-l", "--list", dest="list",
help="addresses of the backtrace")
parser.add_option("-d", "--dsym", dest="dsym",
help="the file of dSYM")
(options, args) = parser.parse_args()
if options.list is not None and options.dsym is not None:
DSYM = options.dsym
alist = map(map_hex, options.list.split(','))
command = reduce(add, alist)
# print command
os.system(command)
pass
else:
parser.print_help()
使用方法就是
iOSCrashAnalyza.py -l1067213,1006303,192329,11307 -d/Users/zephyrleaves/crash/XXX.app.dSYM
其中l后面就是跟 3 XXX 0x00126adf XXX + 1006303
这行中的1006303 这个数字
直接输出
Line table file: 'XXXX.m' line 74, column 56 with start address 0x00000000001058bc
start_addr: 0x0010581c YYYY
-------------------
Line table file: 'AAAA.m' line 182, column 5 with start address 0x00000000000f6aae
start_addr: 0x000f659c -[AAAA BBBB:]
-------------------
Line table file: 'CCCC.m' line 2028, column 2 with start address 0x000000000002ff48
start_addr: 0x0002fef8 -[CCCC DDDD]
-------------------
Line table file: 'main.m' line 16, column 51 with start address 0x0000000000003bf6
start_addr: 0x00003be4 main
-------------------
这样的可读的堆栈了