XcodeDebug---闪退调试

参考:http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1

        http://blog.csdn.net/kesalin/article/details/7222153

        http://blog.csdn.net/totogo2010/article/details/8233565


闪退分为两种,

一种是未被捕获的Objective-C异常(NSException),导致程序向自身发送了SIGABRT信号而崩溃。其实对于未捕获的Objective-C异常。

一种是由EXC_BAD_ACCESS引起的,原因是访问了不属于本进程的内存地址,有可能是访问已被释放的内存;

1.对于第一种情况:SIGABRT(比较好处理)

可能情况1:输出日志内会直接提示你错误信息

Problems[14465:f803] -[UINavigationController setList:]: unrecognized selector sent to
instance 0x6a33840
Problems[14465:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UINavigationController setList:]: unrecognized selector 0x6a33840'
*** First throw call stack:
(0x13ba052 0x154bd0a 0x13bbced 0x1320f00 0x1320ce2 0x29ef 0xf9d6 0x108a6 0x1f743
0x201f8 0x13aa9 0x12a4fa9 0x138e1c5 0x12f3022 0x12f190a 0x12f0db4 0x12f0ccb 0x102a7
0x11a9b 0x2792 0x2705)
terminate called throwing an exception
本例中错误是unrecognized selector UINavigationController 找不到 setList 方法 
说明UINavigationController里面没有这个方法;这样就找到错误了。

可能情况2

错误信息显示在左侧面板上,点击左侧面板可以直接定位到错误。

可能情况3

运行后crash继续运行输出日记会告诉你到底错在哪里

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x13ba052 0x154bd0a 0x1362a78 0x99a2db 0xaaee3 0xab589 0x96dfd 0xa5851 0x50301 
0x13bbe72 0x1d6492d 0x1d6e827 0x1cf4fa7 0x1cf6ea6 0x1cf6580 0x138e9ce 0x1325670
0x12f14f6 0x12f0db4 0x12f0ccb 0x12a3879 0x12a393e 0x11a9b 0x2722 0x2695)
terminate called throwing an exception

可能情况4

程序运行后crash,点没反应,这是就需要(异常断点)Exception Breakpoint:To set the Exception Breakpoint, we have to switch to the Breakpoint Navigator:

The Breakpoint Navigator

At the bottom is a small + button. Click this and select Add Exception Breakpoint:

Adding the Exception Breakpoint

A new breakpoint will be added to the list:

After the Exception Breakpoint has been added

加了异常断点之后,不出意料的话程序会在错误的地方停下来。


第二种情况:EXC_BAD_ACCESS

90%的错误来源在于对一个已经释放的对象进行release操作,或者message sent to deallocated instance

建议:先进行内存检查product-profile把内存泄露尽量消除掉

很多情况下无法直接获取错误信息,需要一些工具来帮助我们

(1)开启僵尸模式Zombies

Open the scheme editor for the project:

The Edit Scheme menu option.

Select the Run action, and then the Diagnostics tab. Check the Enable Zombie Objects box:

Enabling the Zombie Objects diagnostic option.

Now, run the app again. The app still crashes, but now you’ll get the following error message:

Problems[18702:f803] *** -[__NSArrayM objectAtIndex:]: message sent to deallocated instance 0x6d84980
提示信息
 message sent to deallocated instance

However, it’s possible that you still have pointers that point at that now-defunct chunk of memory, under the assumption there’s still a valid object there. If some part of your program tries to use that stale pointer, the app will crash with an EXC_BAD_ACCESS error.

已经释放了,有可能产生了野指针,如果你的程序要使用野指针,就会引起crash

开启了zombie模式之后当object被release后,内存被标记为“Undead”。这时候就会提醒你“message sent to deallocated instance” error.


根据list.count和 *** -[__NSArrayM respondsToSelector:]: message sent to deallocated instance 0x71ca0e0 可以知道list有问题,可以跟踪list输出来看一下list什么时候的值没了,来解决问题

注意一般不用Zombies的时候要记得关掉


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值