当 NSZombieEnabled == YES 时,断点在 Xcode 中停用:EXC_BAD_ACCESS
这个问题已经过时了,因为它是针对 XCode 3 提出的。请不要认为它对 XCode 4+ 有用。 =)
我的应用程序在(看似)随机事件中崩溃。因此,我想添加 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/
为什么我的断点被停用?
This question is far outdated, as it was asked for XCode 3. Please don't consider it useful for XCode 4+. =)
My app crashes at (seemingly) random events. So, I wanted to add NSZombieEnabled to debug my iPhone application. I cloned my target and set its Info.plist to the same as the original target and set NSZombieEnabled to YES.
Once i run the app, it crashes with a stack trace of...
#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
This only happens when NSZombieEnabled is set to YES. If it is not set, the app just runs ( and crashes at different times )
I wanted to add breakpoints like "-[_NSZombie methodSignatureForSelector:]" and others, but they get deactivated during Debugging. I tried it both ways with "Load symbols lazily" turned on and off.
I also tried to set my ~/.gdbinit file to
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
which yield this result in the console:
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/
Why do my breakpoints get deactivated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也一直在尝试这种方法,得到了相同的结果。我的理解是 NSZombie 断点在 Leopard 和 Snow Leopard 中不再有效。
一些替代方案:
1) 将 eax 寄存器转储到 obj_msg_send 上。我个人没有尝试过这个,但我发现了很多关于这个主题的帖子:
如何调试仅在 iPhone 应用程序的发布目标上发生的 EXC_BAD_ACCESS?
2) 使用 info malloc-history。在模拟器中工作得很好,但我没能从设备上获取日志。查找已释放的已释放对象实例
3) 最好的办法可能是在 Instruments 中运行您的应用程序。请注意,NSZombie 模式在该设备上不可用。这可能会有所帮助:
iPhone 内存调试 NSZombie
I've been trying this approach as well with the same results. My understanding is that NSZombie breakpoints are no longer valid in Leopard and Snow Leopard.
Some alternatives:
1) Dump the eax register on obj_msg_send. I haven't personally tried this one but I found many posts on the subject:
How to debug EXC_BAD_ACCESS that occurs only on release target for an iPhone app?
2) Use info malloc-history. Works nicely in the simulator but I've had little luck getting the logs off of the device.Finding freed deallocated instances of objects
3) Probably the best thing to do is run your app in Instruments. Note that NSZombie mode isn't available on the device. This may be of help:
iPhone memory debug NSZombie