{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Debugging Fundamentals of an iPhone application explained
Summary
This article looks at debugging Objective-C code of an iPhone application from Xcode. Debugging in Xcode can be performed from these four different places: Code Editor Window, Debugger Window, GDB Console, and Mini Debugger. This article goes through these four different ways.
 
Table of Contents

Debugging from four different locations

Code Editor Window

Figure 1. Debugging from the source code editor window of Xcode. There is a debugger bar at the top of the window. Variable values can be obtained by moving the cursor over to the variable.

Figure 2. The Debugger Datatip menu in Xcode

Debugger Window

Figure 3. The Debugger window from Xcode. In addition to the code window, you have call stack and variable information.

Debugger Console

Figure 4. The Debugger Console. Here you can execute the GDB debugger commands. Here the call stack as a response to the command bt is displayed.

Mini Debugger

Figure 5. The Mini Debugger Window of Xcode

Figure 6. The Mini Debugger when disengaged from the application

 
Article Series
Previous Article:
Test Your Knowledge: The user interface files of First iPhone application explained
This article is part of the Series:
Article Series: Getting started with iPhone development
Next Article:
Test Your Knowledge: Debugging Fundamentals of an iPhone application explained

Debugging from four different locations

In Xcode, debugging can be performed from four different locations:

  • Code Editor Window
  • Debugger Window
  • GDB Console
  • Mini Debugger

Code Editor Window

You can set breakpoints right in the source code editor by clicking in the gutter (the left margin). When the program is run, the execution will stop if any of these breakpoints are hit.

Figure 1. Debugging from the source code editor window of Xcode. There is a debugger bar at the top of the window. Variable values can be obtained by moving the cursor over to the variable.

Figure 1. Debugging from the source code editor window of Xcode. There is a debugger bar at the top of the window. Variable values can be obtained by moving the cursor over to the variable.

As you can see from the figure above, the blue tab in the left margin denotes the breakpoint. The red arrow says that that is the next line to execute. By moving the cursor over a variable, you can see the details of that variable.

In the figure above, the cursor is over the book object, which has members like author, copyright, title, etc. By simply moving the cursor over book variable, you can find out the values of these members. You can further drill down into the objects by clicking on the arrows on the left. These are called Debugger Datatips. By clicking on the up-down arrow in the datatip, you will get datatip menu which provides additional functionality to deal with the variable in question.

Figure 2. The Debugger Datatip menu in Xcode

Figure 2. The Debugger Datatip menu in Xcode

As you can see from the menu, you can jump to the place where the variable is defined or look it up in the documentation. You can obtain the description, open the variable in a separate window or look at the memory it occupies.

There is a debugger tab at the top of the source code window. The buttons on this tab provide the primary debugger functionality: Continue Execution, Step Over Method or Function Call, Step Into Method or Function Call, and Step Out of Current Method or Function. In addition, you can move to a different thread or start the GUI Debugger Window or Console Debugger Window (discussed below).

Debugger Window

The debugger functionality is also available from the GUI Debugger window in Xcode. You can open this window by clicking on the Debugger icon in the source editor toolbar or choosing Run - Debugger menu.

Figure 3. The Debugger window from Xcode. In addition to the code window, you have call stack and variable information.

Figure 3. The Debugger window from Xcode. In addition to the code window, you have call stack and variable information.

This is the most useful window for graphical debugging. In addition to source code (where the current breakpoint is), you will also see the call stack of methods/functions (stack frames) to get to this point. There is also a Variable Window that provides the values of various variables of relevance at that point of execution.

Debugger Console

The Debugger Console provides the most powerful debugging functionality in Xcode. This console is the front-end to the GDB (GNU Debugger). From other places (the editor, GUI Debugger), the information is presented graphically. For most of the regular debugging sessions, that functionality is good enough. Here with GDB Console, the information is presented in text in response to the commands you issue. GDB comes with a whole set of powerful debugging commands.

In the figure below, GDB shows the call stack in response to the command bt (which stands for backtrace).

Figure 4. The Debugger Console. Here you can execute the GDB debugger commands. Here the call stack as a response to the command bt is displayed.

Figure 4. The Debugger Console. Here you can execute the GDB debugger commands. Here the call stack as a response to the command bt is displayed.

Mini Debugger

When you want the least interference from your debugger (useful when trying to reproduces the hard-to-reproduce issues), you would want to use the mini debugger. This mini debugger comes in two modes: when it’s attached to the program (you can see the source at the breakpoint) and when it’s disengaged (i.e. you will see a small list of toolbar buttons to stop or pause the program).

Figure 5. The Mini Debugger Window of Xcode

Figure 5. The Mini Debugger Window of Xcode

Figure 6. The Mini Debugger when disengaged from the application

Figure 6. The Mini Debugger when disengaged from the application
Take a Quick Quiz on this Article

1. What is main purpose of mini debugger?



: Not a lot of footprint
Question 1 of 5
Article Series
Previous Article:
Test Your Knowledge: The user interface files of First iPhone application explained
This article is part of the Series:
Article Series: Getting started with iPhone development
Next Article:
Test Your Knowledge: Debugging Fundamentals of an iPhone application explained
Bookmark and Share This

More Articles With Similar Tags
This is a test on the article that gives a quick overview of the development tools installed with iPhone SDK. These tools include Xcode, Interface Builder, Instruments, and iPhone Simulator. In the article, Dash Code, which is used to build web applications for iPhone is also introduced. GDB, the open source debugger, is discussed there as well.
icon-xcode-groups-files.jpg
This article discusses various parts of the Project window inside an Xcode project. It also gives a quick overview of the Groups and Files navigation window. The Run menu, the default toolbar, and the built-in source editor are also discussed.
This is a test on the article that discusses various parts of the Project window inside an Xcode project. It also gives a quick overview of the Groups and Files navigation window. The Run menu, the default toolbar, and the built-in source editor are also discussed.
icon-xcode-interface-builder-connection-panel.jpg
This article explains the user interface files of an iPhone application. Explains the contents of the .xib files, which store the user interface. Goes through the various windows (Document Window, User Interface Window, Inspector Window, Library Window, Connections Panel) of the Interface Builder. The example used is a simple navigation-based iPhone application.
This is a test on the article that explains the user interface files of an iPhone application. It explains the contents of the .xib files, which store the user interface. Goes through the various windows (Document Window, User Interface Window, Inspector Window, Library Window, Connections Panel) of the Interface Builder. The example used is a simple navigation-based iPhone application.
About  Contact  Privacy Policy  Site Map