Debugging in Xcode - Running Code and Breakpoints

I would like to know how to debug best in xcode. I know how to set a breakpoint, but ideally I would like the simulator to stop and then execute the code ...

Don't go through breakpoints, but skip the code line by line so I can see where it goes, what methods are running, etc.

Is this possible, if so, how?

+7
source share
2 answers

Debug control icons in Xcode

In the lower left corner of the code window in Xcode 4, you can see the debugging controls. Each of them has a short text for explanation. I will explain here in more detail. Learning to become an expert debugger is the subject of many textbooks.

Play button Alt: Continue the program . You probably already found it. Pressing the button moves to the next breakpoint.

Arrow arrow alt: Step over . Pressing this button again will allow you to advance through your program at the current level of visibility, just like your program. This will allow you to observe the behavior of your program step by step according to the current method. When the current method completes, Step over will take you to the calling method one step up in the program stack.

Down arrow text: Step c . Pressing this button will follow the new method in its area and allow you to view the code in the called method if it was compiled for debugging. For example, clicking on the current line of code in the above debugging window will take you to the _generateSources method, which you can then follow through with a step.

Upper arrow alt text: Exit . Brings you out of the current context and into the calling method one step up in the program stack. This behaves identically to the completion of the method using Step over, executing the program as usual and executing all lines of code in the source area that you did not debug with Step over.

View of call stack

Click on the silhouette with a blue background to see the current call stack. The call stack will always go all the way from the current area to the first method that was called to run your program. Each method that you see here has been called sequentially to achieve - [HelloWorldLayer init]. When you click Run , then the current line of executable code will return to [CCNode node], and if you have a source for it, you can view it.

On the left are the current Local variables visible from the scope of the current line of code (line 76 in this image). These variables are how you can really use the commands above, like Step over . background and winSize are local variables that have been defined in this area and are currently in use. When the scope comes out, they disappear. _cmd is a pointer to a selector that is currently being called in Objective-C: - [HelloWorldLayer init]. You will not need this until you are an advanced debugger. self is a pointer to an object containing all ivars belonging to the executable class, HelloWorldLayer and objc_super is a pointer to the parent class HelloWorldLayer.

+23
source

I would add keyboard shortcuts to @Thomson Corner's answer.

  • Use 'c' to continue. 's' for step, 'n' for next, 'f' for finish. I don't like working with the debugger with the mouse. These icons are too tiny, and getting a pointer to them is a pain (from time to time). I have always been a person with a keyboard, and it is REALLY comfortable with the keyboard.

  • You should also try using po - it displays the values ​​of variables with sentences of type forward. Like po_varName . Easily checks if a variable is null, etc.,

  • You can also change your command aliases by changing ~/.lldbinit .

Here is the official tutorial: http://lldb.llvm.org/tutorial.html . And another tutorial: http://www.informit.com/articles/article.aspx?p=1829415&seqNum=6 . What I have indicated above are the most basic debugging functions that are mainly performed by programmers. There are more options, such as checkpoints for program exclusions and downloads, but I'm sure they are the next day if you are just starting out.

+8
source

All Articles