哪里有关于如何正确使用 Xcode 调试器的好教程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1365267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is there a good tutorial on how to use Xcode's debugger properly?
提问by Philip Regan
Subject says it all really...Is there anywhere a good tutorial for Xcode's Debugger out there? I'm finding dribs and drabs of stuff but nothing comprehensive or that goes deep enough. My problem right now is that this...
主题说这一切真的......那里有没有关于 Xcode 调试器的好教程?我正在寻找点点滴滴的东西,但没有什么全面的或足够深入的。我现在的问题是这...
#0 0x90d9c688 in objc_msgSend
#1 0x30506515 in NSPopAutoreleasePool
#2 0x30901697 in _UIApplicationHandleEvent
#3 0x32046375 in PurpleEventCallback
#4 0x30245560 in CFRunLoopRunSpecific
#5 0x30244628 in CFRunLoopRunInMode
#6 0x308f930d in -[UIApplication _run]
#7 0x309021ee in UIApplicationMain
#8 0x00001ff8 in main at main.m:14
...combined with this...
……结合这个……
0x90d9c688 <+0024> mov 0x20(%edx),%edi
...and this...
...和这个...
EXC_BAD_ACCESS
...isn't helping much. Or at all, really. I'm resorting to commenting out lines of code and there has to be a better way.
......没有多大帮助。或者根本没有,真的。我正在求助于注释掉代码行,并且必须有更好的方法。
Thanks
谢谢
UPDATE:I guess perhaps my venting was a bit of a distraction from the real question, though the tips have helped explain things a bit. What I'm really getting at is not only an explanation of the above, but just use of the Debugger in general. The questions that I usually have are:
更新:我想也许我的发泄有点分散了对真正问题的注意力,尽管这些提示有助于解释一些事情。我真正要了解的不仅是对上述内容的解释,而且只是总体上对调试器的使用。我通常会遇到的问题是:
- Why does the Debugger sometimes go from the source code view to (what I'm assuming) assembly code when I step over or in? Is there a way for me to see both at the same time all the time?
- Is there anything specific I should be looking for in the assembly code, or anything that could help in a given situation?
- It looks as though breakpoints allow for actions, so I'm curious how that might be utilized rather than peppering my code with NSLog statements.
- 为什么调试器有时会在我跳过或进入时从源代码视图转到(我假设的)汇编代码?有没有办法让我一直同时看到两者?
- 我应该在汇编代码中寻找什么特定的东西,或者在给定情况下有什么帮助?
- 看起来好像断点允许操作,所以我很好奇如何利用它而不是用 NSLog 语句填充我的代码。
I know these are broad, and probably should be asked individually, but I didn't want to clutter the SO space with these topics that might already be documented elsewhere.
我知道这些很宽泛,可能应该单独询问,但我不想用这些可能已经在别处记录的主题使 SO 空间混乱。
I also noticed there is a nearly duplicate question asked here: What are some Objective-c debugging tips?
我还注意到这里提出了一个几乎重复的问题:什么是一些 Objective-c 调试技巧?
采纳答案by Kornel
The crash is inside Apple's code (that's why debugger doesn't show you the source) and cause of it is actually somewhere else – you've released a temporary object that was supposed to be released by autorelease pool. This caused autorelease pool to crash.
崩溃是在 Apple 的代码中(这就是为什么调试器没有向您显示源代码)并且它的原因实际上在其他地方 - 您已经释放了一个应该由自动释放池释放的临时对象。这导致自动释放池崩溃。
You're supposed to release only objects which:
你应该只释放以下对象:
- you've retained yourself using
retain
- were returned by
init
,copy
andnew
methods only (and their variants containing these words)
- 你保留了自己使用
retain
- 仅由
init
,copy
和new
方法返回(及其包含这些词的变体)
Unfortunately you can't learn that one from the debugger, only from documentation and experience…
不幸的是,您无法从调试器中学到这一点,只能从文档和经验中学习……
You can use Clang Analyzerto find such errors (sometimes).
您可以使用Clang Analyzer来查找此类错误(有时)。
回答by Rob Keniger
You should turn on NSZombieEnabled to debug over-release issues like this:
你应该打开 NSZombieEnabled 来调试像这样的过度发布问题:
http://cocoadev.com/index.pl?NSZombieEnabled
http://cocoadev.com/index.pl?NSZombieEnabled
http://www.fromconcentratesoftware.com/2007/08/09/nszombieenabled-for-the-debugger-adverse/
http://www.fromconcentratesoftware.com/2007/08/09/nszombieenabled-for-the-debugger-adverse/
http://www.tomwhitson.co.uk/blog/2009/04/debugging-with-nszombiesenabled/
http://www.tomwhitson.co.uk/blog/2009/04/debugging-with-nszombiesenabled/
回答by milesmeow
Here's a great tutorialon the features of the debugger for XCode 4.
这是有关 XCode 4 调试器功能的精彩教程。
Regarding your question for why the debugger goes from source code view to assembly view... It goes to assembly view when the execution of code goes into classes that are not part of your source code files...e.g. when your stepping into code that are part of Frameworks that you use such as UIKit.
关于为什么调试器从源代码视图转到汇编视图的问题......当代码执行进入不属于源代码文件的类时,它会转到汇编视图......例如,当你进入代码时是您使用的框架的一部分,例如 UIKit。