2009-09-08 54 views
1

這個問題遠沒有過時,因爲它要求的XCode 3,請不要考慮它的XCode有用4+。 =)斷點得到停用在Xcode中:EXC_BAD_ACCESS時NSZombieEnabled = = YES


我的應用程序崩潰的(貌似)隨機事件。所以,我想添加NSZombieEnabled來調試我的iPhone應用程序。我克隆了我的目標,並將其Info.plist設置爲與原始目標相同,並將NSZombieEnabled設置爲YES。

一旦我運行應用程序時,它的堆棧跟蹤崩潰......

#0 0x3025db0c in ___forwarding___() 
#1 0x30239db2 in __forwarding_prep_0___() 
#2 0x304f5105 in NSPopAutoreleasePool() 
#3 0x308ee452 in _UIApplicationHandleEvent() 
#4 0x32031425 in PurpleEventCallback() 
#5 0x30235253 in CFRunLoopRunSpecific() 
#6 0x302343c8 in CFRunLoopRunInMode() 
#7 0x308e6209 in -[UIApplication _run]() 
#8 0x308eef81 in UIApplicationMain() 
#9 0x000023ef in main (argc=1, argv=0xbffff0bc) at /Users/tomen/Documents/MIB-Sprint4/main.m:26 

時NSZombieEnabled設置爲YES這只是發生。如果沒有設置,應用程序只運行(並在不同時間崩潰)

我想添加諸如「 - [_ NSZombie methodSignatureForSelector:]」等斷點,但它們在調試期間取消激活。我試着用「加載符號懶惰」打開和關閉兩種方式。

我也試過了我的〜/ .gdbinit中設置爲

fb -[NSException raise] 
fb -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] 
fb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 

#define NSZombies 
# this will give you help messages. Set to NO to turn them off. 
set env MallocHelp=YES 
# might also be set in launch arguments. 
set env NSZombieEnabled=YES 
set env NSDeallocateZombies=NO 
set env MallocCheckHeapEach=100000 
set env MallocCheckHeapStart=100000 
set env MallocScribble=YES 
set env MallocGuardEdges=YES 
set env MallocCheckHeapAbort=1 

set env CFZombie 5 

fb -[_NSZombie init] 
fb -[_NSZombie retainCount] 
fb -[_NSZombie retain] 
fb -[_NSZombie release] 
fb -[_NSZombie autorelease] 
fb -[_NSZombie methodSignatureForSelector:] 
fb -[_NSZombie respondsToSelector:] 
fb -[_NSZombie forwardInvocation:] 
fb -[_NSZombie class] 
fb -[_NSZombie dealloc] 

fb szone_error 

其產生這樣的結果在控制檯:

The Debugger has exited with status 0. 
[Session started at 2009-09-08 13:48:40 +0200.] 
Loading program into debugger… 
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found). 
warning: Unable to read symbols from "UIKit" (not yet mapped into memory). 
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found). 
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory). 
Pending breakpoint 1 - "-[NSException raise]" resolved 
Pending breakpoint 2 - "-[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:]" resolved 
Pending breakpoint 3 - "-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]" resolved 
Pending breakpoint 14 - "szone_error" resolved 
Program loaded. 
sharedlibrary apply-load-rules all 
Attaching to program: `/Users/tomen/Library/Application Support/iPhone Simulator/User/Applications/F77D9D82-0B34-4B8D-9076-AE883A2714F4/MIB.app/MIB', process 279. 
Re-enabling shared library breakpoint 1 
Re-enabling shared library breakpoint 2 
Re-enabling shared library breakpoint 3 
Re-enabling shared library breakpoint 14 
Re-enabling shared library breakpoint 16 
Re-enabling shared library breakpoint 17 
Re-enabling shared library breakpoint 18 
warning: Couldn't raise load state for requested objfile: "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" for breakpoint 1/ 

warning: Couldn't raise load state for requested objfile: "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation" for breakpoint 2/ 

warning: Couldn't raise load state for requested objfile: "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation" for breakpoint 3/ 

爲什麼我的斷點得到解除?

回答

2

我一直在嘗試這種方法以及相同的結果。我的理解是NSZombie斷點在Leopard和Snow Leopard中不再有效。

一些替代方案:

1)轉儲obj_msg_send EAX寄存器。我沒有親自嘗試過這個,但是我發現了很多關於這個主題的帖子: How to debug EXC_BAD_ACCESS that occurs only on release target for an iPhone app?

2)使用信息malloc-history。在模擬器中很好地工作,但我很少運氣從設備上獲取日誌。 Finding freed deallocated instances of objects

3)可能最好的做法是在樂器中運行您的應用程序。請注意,NSZombie模式在設備上不可用。這可能有幫助: iPhone memory debug NSZombie