您的位置:首页 > 移动开发 > IOS开发

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

2014-10-02 00:58 288 查看
XCode4设置不太一样: 在Edit–>Scheme里面 找到Arguments(在xcode 4.2中,在菜单 product->edit scheme中)

把下面3个值设置成YES

NSAutoreleaseFreedObjectCheckEnabled

NSZombieEnabled

NSDebugEnabled

MallocStackLogging

LLDB->GDB (才能使用shell命令)

另外转载2篇调试EXC_BAD_ACCESS的好文

http://blog.zol.com.cn/2387/article_2386505.html

/article/4690738.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:(xcode4.6 profile选项)

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

方法二:例如console里的输出如下:(需要打开MallocStackLogging:YES, LLDB->GDB选项)
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)

即会出现调用栈
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: