iphone ios XCode4如何调试程序忽然崩溃而找不到挂的代码

时间:2023-02-20 18:11:57

XCode4设置不太一样: 在Edit–>Scheme里面 找到Arguments(在xcode 4.2中,在菜单 product->edit scheme中)

iphone ios XCode4如何调试程序忽然崩溃而找不到挂的代码

把下面3个值设置成YES

NSAutoreleaseFreedObjectCheckEnabled

NSZombieEnabled

NSDebugEnabled

另外转载2篇调试 EXC_BAD_ACCESS的好文
http://blog.zol.com.cn/2387/article_2386505.html
http://www.cnblogs.com/likwo/archive/2011/02/28/1967066.html

老外也有这么说的:
I had similar issue; turns out I was not retaining a UIButton properly. How I found the cause: - Enable zombies - Run the project with 'Allocations' instrument - Use the app to trigger the bug - Check that Instruments show message 'Zombie Messaged' on the timeline - There should be a link that opens CALayer details: when it was allocated and deallocated - You are interested in the place where is was allocated, should be that aha!!! place in your code


我是用模拟器上 使用zombies,然后运行程序,崩溃的时候会有提示崩溃点,同时有代码。

转另一个人文章:

 方法一:

PAEHoldTranMainControl *control = [[PAEHoldTranMainControl alloc]init];

            [self.navigationController pushViewController:control animated:YES];

            [control release];

alloc了一个control,release,运行就崩溃了。而且没有任何提示,console里只显示exc_bad_access

利用NSZombieEnabled参数,MallocStackLogging参数,显示 -[CALayer release]: message sent to deallocated instance 0x13570810

折腾了半天,最后用如下方法定位问题:

打开instrument-->ios simulator:

选择all--》 zombies运行,断开时,查看stack trace,即可跟踪

 

 方法二:例如console里的输出如下:

TestAPP[1472:207] *** -[NSObject release]: message sent to deallocated instance 0x6019170

在 gdb console 里面, 运行 shell malloc_history <pid> <mem_address>

pid = process ID (e.g. 1472)

mem_address = memory address of instance (e.g. 0x6019170) 

即会出现调用栈