Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in XCode - running through code and breakpoints [closed]

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?

like image 337
StuartM Avatar asked Oct 02 '12 20:10

StuartM


People also ask

Why breakpoints are not working in Xcode?

You might be pushing "Run" instead of "Debug" in which case your program is not running with the help of gdb, in which case you cannot expect breakpoints to work! In Xcode 6.4, there is now only a Run button and whether it runs a debug configuration or not depends on the currently selected scheme settings.

What happens when a breakpoint is reached when the debugger is enabled?

If a breakpoint is reached, or a signal not related to stepping occurs before count steps, stepping stops right away. Continue to the next source line in the current (innermost) stack frame. This is similar to step , but function calls that appear within the line of code are executed without stopping.

How do you stop a breakpoint in Xcode?

Specify Where to Pause Your App Xcode displays a breakpoint icon to indicate the location. Drag a breakpoint up or down to move it to another location; drag it away from the gutter to remove it. Click the breakpoint icon in the debug area toolbar to activate or deactivate all breakpoints.


1 Answers

Debug control icons in Xcode

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.

View of call stack

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.

like image 138
Thomson Comer Avatar answered Oct 21 '22 05:10

Thomson Comer