我收到了客户的崩溃日志,以了解我的应用程序崩溃iPhone的原因 .
这里来自崩溃日志的一些信息:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
线程0的堆栈跟踪
Thread 0 Crashed:
0 libSystem.B.dylib 0x3293f98c 0x328c1000 + 518540
1 libSystem.B.dylib 0x3293f97c 0x328c1000 + 518524
2 libSystem.B.dylib 0x3293f96e 0x328c1000 + 518510
3 libSystem.B.dylib 0x3295461a 0x328c1000 + 603674
4 libstdc++.6.dylib 0x30a143b0 0x309cf000 + 283568
5 libobjc.A.dylib 0x3347a858 0x33475000 + 22616
6 libstdc++.6.dylib 0x30a12776 0x309cf000 + 276342
7 libstdc++.6.dylib 0x30a127ca 0x309cf000 + 276426
8 libstdc++.6.dylib 0x30a12896 0x309cf000 + 276630
9 libobjc.A.dylib 0x33479714 0x33475000 + 18196
10 CoreFoundation 0x335c8210 0x33534000 + 606736
11 CoreFoundation 0x3354ea8e 0x33534000 + 109198
12 CoreFoundation 0x33545ab8 0x33534000 + 72376
13 Journaler Lite 0x0001699e -[AccountManager unsignedIntegerValueForPath:] (AccountManager.m:151)
...
这是 AccountManager.m
的代码:
NSNumber *number = ...;
if (number) {
return [number unsignedIntegerValue]; // line 151
} else {
return 0;
}
主要问题是如何阅读此类崩溃日志?该应用程序崩溃在系统库内的某个地方,没有更多的额外信息 . 如何找到崩溃的原因?
update: 我搜索过很多论坛帖子,其中异常类型是 EXC_CRASH (SIGABRT)
,来自崩溃线程堆栈的第一行是:
Thread 0 Crashed:
0 libSystem.B.dylib 0x3293f98c 0x328c1000 + 518540
1 libSystem.B.dylib 0x3293f97c 0x328c1000 + 518524
2 libSystem.B.dylib 0x3293f96e 0x328c1000 + 518510
3 libSystem.B.dylib 0x3295461a 0x328c1000 + 603674
4 libstdc++.6.dylib 0x30a143b0 0x309cf000 + 283568
5 libobjc.A.dylib 0x3347a858 0x33475000 + 22616
6 libstdc++.6.dylib 0x30a12776 0x309cf000 + 276342
7 libstdc++.6.dylib 0x30a127ca 0x309cf000 + 276426
8 libstdc++.6.dylib 0x30a12896 0x309cf000 + 276630
9 libobjc.A.dylib 0x33479714 0x33475000 + 18196
10 CoreFoundation 0x335c8210 0x33534000 + 606736
11 CoreFoundation 0x3354ea8e 0x33534000 + 109198
这种异常类型( EXC_CRASH (SIGABRT)
)是什么意思?
1 回答
首先,您需要使用DSYM来表示崩溃日志,以了解发生了什么 . 从构建应用程序时起,您需要拥有DSYM文件 . DSYM文件允许您将这些内存地址的映射反向回可读的代码行 .
SIGABRT是当您有未处理的异常时获得的信号,例如如果数组只有1个项目则调用
[someArray objectAtIndex:2]
. 或者,更常见的是,无法识别的选择器:[NSArray unsignedIntValue]
.在this question中查看此崩溃日志 . 请注意,Foundation中的调用堆栈库与您的代码相同 - 而且它是一个无法识别的选择器 .
你的代码是:
你没有告诉我们 - 但是非常重要 - 是什么在“foo” . 你如何分配NSNumber?如果它是除NSNumber之外的任何其他对象,那么您的崩溃日志将与您的一样 .
如果你想在编程中真正防守,你可以说:
但实际上,无论你的“foo”是什么,都应该总是返回一个NSNumber .