09m-debugging-with-xcode

09m-debugging-with-xcode - Eric Roberts CS 106B Handout #9M...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Eric Roberts Handout #9M CS 106B April 6, 2009 Debugging with Xcode This handout has many authors including Eric Roberts, Julie Zelenski, Stacey Doerr, Justin Manis, Justin Santamaria, and Jason Auerbach. Because debugging is a difficult but nonetheless critical task, it is important to learn the tricks of the trade. The most important of these tricks is to get the computer to show you what it’s doing, which is the key to debugging. The computer, after all, is there in front of you. You can watch it work. You can’t ask the computer why it isn’t working, but you can have it show you its work as it goes. Modern programming environments usually come equipped with a debugger, which is a special facility for monitoring a program as it runs. By using the Xcode debugger, for example, you can step through the operation of your program and watch it work. Using the debugger helps you build up a good sense of what your program is doing, and often points the way to the mistake. Using the Xcode debugger The Xcode debugger is a complicated environment, but with a little patience, you should be able to learn it to the point where you code more efficiently and productively. Under the Build menu, there are two menu items for executing your code: the Run ( R ) option and the Debug ( Y ) option. So far you’ve probably been using Run , which sets up and runs your program on its own until it completes successfully or halts abnormally because of a fatal error. The Debug option, on the other hand, will set up and run your program in the context of the debugger. The debugger gives you the ability to stop your program mid-stream, poke around and examine the values of variables, and investigate the aftermath after a fatal error to understand what happened. When you choose the Debug menu item, it sets up your program and then brings up the debugger window without starting program execution. At this point, you control the execution of the program manually using the buttons on the debugger window. You can choose to step through the code line-by-line, run until you get to certain points, and so on. The toolbar icons you should become familiar with are Build and Debug , Terminate , Restart , Pause , Continue , Step Over , Step Into , and Step Out . These icons and their corresponding commands are detailed in Figure 1. Whenever the program has not yet been started, the Build and Debug command will start it. If it has started but has stopped, Continue will start it again from where it left off. The Pause button is useful if the program is in an infinite loop or if you want to stop the program manually to use the debugger. The Terminate command is useful if you want to want to quit the debugger and return to editing before the program has finished running. When a program starts with debugging enabled, the debugger window opens.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

09m-debugging-with-xcode - Eric Roberts CS 106B Handout #9M...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online