我們在使用第三方崩潰統計工具時,經常見到如下圖:
0 CoreFoundation 0x1823c6d8c 0x182281000 + 1334668 __exceptionPreprocess (in CoreFoundation) + 228
1 libobjc.A.dylib 0x1815805ec 0x181578000 + 34284 objc_exception_throw (in libobjc.A.dylib) + 56
2 CoreFoundation 0x1823d4098 0x182281000 + 1388696 __methodDescriptionForSelector (in CoreFoundation) + 0
3 CoreFoundation 0x1823cc5c8 0x182281000 + 1357256 ___forwarding___ (in CoreFoundation) + 1380
4 CoreFoundation 0x1822b241c 0x182281000 + 201756 _CF_forwarding_prep_0 (in CoreFoundation) + 92
5 test 0x10146cc10 0x100d50000 + 7457808 -[ClassB sendAuthModel] (in test) + 396
6 test 0x1014264a0 0x100d50000 + 7169184 -[ClassA onConnect] (in test) + 684
只是這樣只能看到是在sendAuthModel函數內崩潰的,但是并不知道是在具體的哪一行,如何定位是崩潰在哪行呢?
在sendAuthModel的最后加入
NSArray *syms = [NSThread callStackSymbols];
if ([syms count] > 1) {
for (int i = 0; i < 13; i++) {
NSLog(@"<%@ %p> %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:i]);
}
} else {
NSLog(@"<%@ %p> %@", [self class], self, NSStringFromSelector(_cmd));
}
并在函數最后增加個斷點(為了執行image lookup -a address命令)
通過打印可以看到
2018-06-20 15:36:40.965642+0800 jingmai[6392:747560] <ClassB 0x1c00d9de0> sendAuthModel - caller: 0 test 0x0000000101901370 -[ClassB sendAuthModel] + 1692
0x0000000101901370即執行打印時的棧地址
使用0x0000000101901370-0x69c(1692的16進制),得到的地址即sendAuthModel的起始地址,然后加上崩潰統計中的0x18c(396的16進制),既得到崩潰統計中崩潰的位置address。
最后使用image lookup -a address,就可以找到對應的行了。
當然到這還沒有解決問題,只是找到出問題的行,至于是什么原因導致的,還需要繼續去查找啦。
另外2個可能用到的命令:
image list
br set -a 0xaddress