在XCode中进行调试-通过代码和断点运行 [英] Debugging in XCode - running through code and breakpoints

查看:173
本文介绍了在XCode中进行调试-通过代码和断点运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在xcode中进行最佳调试.我知道如何设置断点,但理想情况下,我希望模拟器停止运行,然后逐步执行代码...

不是单步执行断点,而是逐行单步执行代码,这样我可以看到它的去向,运行的方法是什么...

有可能吗?

解决方案

在Xcode 4的代码窗口的左下方,您可以看到调试步骤控件.每个都有一个简短的替代文字来解释它.我将在这里稍作解释.学会成为专家调试器是许多教科书的主题.

播放按钮的替代文本:继续执行程序.您可能已经找到了.按下它会前进到下一个断点.

跳转箭头的替代文本:跳过.重复按此按钮将使您能够像程序一样在当前作用域级别上浏览程序.它使您可以逐步观察当前方法中程序的行为.当前方法完成后,Step over将带您进入程序堆栈中的上一步调用方法.

向下箭头替代文字:进入.按下此按钮将使新方法进入其范围,并允许您查看被调用方法中的代码(如果已将其编译用于调试).例如,在上面的调试窗口中的当前代码行上单击此按钮,将带您到_generateSources方法,然后可以逐步执行.

向上箭头的替代文本:退出.将您带出当前上下文,并进入程序堆栈中的上一步的调用方法.这与使用Step over完成方法,正常执行程序以及在没有使用Step over调试的原始范围内执行所有代码行的行为相同.

单击带有蓝色背景的轮廓以查看当前调用堆栈.从当前作用域一直到调用程序启动的第一个方法,调用堆栈将一直进行.为了达到-[HelloWorldLayer init],将依次调用您在此处看到的每个方法.当您按退出时,当前正在执行的代码行将返回至-[CCNode节点],如果您拥有源代码,则可以对其进行浏览.

左侧是当前正在执行的代码行(此图中的第76行)的范围内可见的当前Local变量.这些变量是您如何真正使用上述命令(如 Step over )的方法. background winSize 是在此范围内定义且当前正在使用的局部变量.退出示波器后,它们将消失. _cmd 是指向当前正在Objective-C中调用的选择器的指针:-[HelloWorldLayer init].在成为高级调试器之前,您将不需要此功能. self 是指向对象的指针,该对象包含属于当前正在执行的类HelloWorldLayer的所有ivars,而 objc_super 是指向HelloWorldLayer父类的指针.

I would like to know how to debug best in xcode. I know how to set a break point but ideally i would like the simulator to stop and then step through the code...

Not step through breakpoints but step through the code line by line so I can see where it goes, what methods are run etc...

Is this possible, if so how?

解决方案

At the bottom left of your code window in Xcode 4 you can see the debug step controls. Each has a short alt text to explain it. I'll explain in slightly more detail here. Learning to become an expert debugger is the subject of many textbooks.

The play button alt text: Continue program execution. You've probably found this already. Pressing it advances to the next breakpoint.

The jumping arrow alt text: Step over. Pressing this button repeatedly will allow you to advance through your program at the current level of scope just as your program would. It will allow you to observe the behavior of your program step by step through the current method. When the current method finishes, Step over will take you to the calling method one step up in the program stack.

The down arrow alt text: Step into. Pressing this button will follow the new method into its scope and allow you to view code in the called-method if it has been compiled for debugging. For example, clicking this on the current line of code in the above debug window will take you to the _generateSources method, which you can then progress through with Step over.

The up arrow alt text: Step out. Takes you out of the current context and into the calling method one step up in the program stack. This behaves identically to finishing a method using Step over, executing the program as normal and executing all of the lines of code in the original scope that you did not debug using Step over.

Click on the silhouette with the blue background to see the current call stack. The call stack will always progress all the way from your current scope to the first method that was called to launch your program. Each method you see here was called in sequence in order to reach -[HelloWorldLayer init]. When you press Step out then the current line of executing code will return to -[CCNode node], and if you have the source for it you can browse it.

To the left are the current Local variables visible from the scope of the line of code currently being executed (line 76 in this image). These variables are how you can really use the above commands like Step over. background and winSize are local variables that were defined in this scope and are currently being used. When the scope is exited they will be gone. _cmd is a pointer to the selector that is currently being invoked in Objective-C: -[HelloWorldLayer init]. You won't need this until you are an advanced debugger. self is the pointer to an object containing all of the ivars that belong to the currently executing class, HelloWorldLayer, and objc_super is a pointer to the parent class of HelloWorldLayer.

这篇关于在XCode中进行调试-通过代码和断点运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆