iOS SDK : Debugging (part 2) - Watchpoints

8/17/2011 11:34:21 AM


Sometimes you might be interested in having the program pause when a value changes. A watchpoint pauses the program when the watched item’s value changes. Setting a watchpoint is tricky the first time, but then it becomes easy. To set a watchpoint, start the application in the debugger, and when the application pauses at a breakpoint, select the variable in the debugger window’s variable list. Right-click it and select “Watch address of” from the shortcut menu (Figure 4). After you click Continue, if the value changes, the debugger notifies you and pauses (Figure 5). It’s worth noting that watchpoints are not persisted across debugging sessions. Every application launch requires that you reestablish your watchpoints.

Figure 4. Setting a watchpoint

Figure 5. The debugger notifies you when a watchpoint’s value changes.

Try This: Debugging an Application

  1. Create a new Utility Application named Debug.

  2. Select FlipsideView.xib to edit it in the Interface Builder. Select View | Utilities | Show Utilities if necessary and then click the Connections button (tiny arrow in a circle). Remove the connection between the view and the File’s Owner by clicking the tiny X next to Files’s Owner (Figure 6).

    Figure 6. Remove the view from the view controller.
  3. Click the Run button to run the application. Click the Info button in the lower right of the simulator screen, and the application crashes.

  4. Quit the iPhone Simulator and return to Xcode.

  5. Open MainViewController.m and add a breakpoint at the second line in showInfo (Figure 7).

    Figure 7. Debugger window stopped at breakpoint in showInfo
  6. Click the Run button again to run the application. If the Debug Area is not visible, select View | Show Debugger Area.

  7. Try stepping over the next few lines and the application crashes. You now know exactly which line in your code causes the application to crash. Something about presenting the FlipsideViewController caused the crash.


    Forgetting to set a File’s Owner view outlet is a common mistake.

  8. Stop the iPhone Simulator and return to Xcode. Remove the breakpoint.

  9. From the main menu, select View | Navigators | Breakpoint.

  10. Click the + in the lower-left corner to create a new breakpoint and select Add Symbolic Breakpoint from the pop-up menu. Type objc_exception_throw for the symbol and click Done (Figure 8). You’ve now set a breakpoint in the code that’s called at the moment the error occurs.

    Figure 8. Adding objc_exception_throw as a breakpoint
  11. Click the Run button to launch the application in the debugger.

  12. Click the Info button, and the application halts at the newly set breakpoint. Open the debugger area, if it is not already open (Figure 9). You may want to drag the slider in the lower left of the window to increase the detail in the stack trace.

    Figure 9. Debugger window paused at objc_exception_throw breakpoint
  13. Notice the upper-left window. This contains the stack listing. Follow the stack down several items, and you see the last thing to occur prior to an NSException is loading the view from the nib. Follow the stack to row 12, click it, and you see the line of code in the view controller that was executed in the right pane (Figure 10). So you know trying to load the view from the nib caused the crash.

    Figure 10. Following the stack trace takes you to an error’s source.
Other -----------------
- iOS SDK : Debugging (part1 )
- iOS SDK : Installing Applications on an iPhone
- Software Testing with Visual Studio Team System 2008 : Web Testing - Recording a test
- Software Testing with Visual Studio Team System 2008 : Unit testing web services & Code coverage unit test
- .NET Debugging : Introduction to the Tools - SOS & SOSEX
- .NET Debugging : CLR 4.0 - Synchronization & Interoperability
- iPhone Programming : Connecting to the Network - Getting Data from the Internet
- iPhone Programming : Connecting to the Network - Sending Email
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Check Results
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Read and Write Files
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Get Dates and Times
- Programming Excel with VBA and .NET : Tasks in Visual Basic - Work with Text
- A Technical Overview of the Mobile Web : THE TECHNICAL CHALLENGES OF MOBILE DEVICES (part 2)
- A Technical Overview of the Mobile Web : THE TECHNICAL CHALLENGES OF MOBILE DEVICES (part 1) - Physical Constraints
- Parallel Programming with Microsoft Visual Studio 2010 : Task Parallelism - Unhandled Exceptions in Tasks
- Parallel Programming with Microsoft Visual Studio 2010 : Introduction to Parallel Tasks
- jQuery 1.3 : DOM Manipulation - Moving elements
- .NET Debugging : Introduction to the Tools - .NET 2.0—Redistributable & .NET 2.0—SDK
- .NET Debugging : Managed Heap and Garbage Collection
- Context and Interception : Custom Component Services (part 3) - The Transaction Management Service
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Most View
- Windows 7 : Preventing Users from Logging On at Certain Times
- Windows Home Server 2011 : Setting Up a Fax Server (part 3) - Receiving Faxes
- Using Non-Windows Systems to Access Exchange Server 2007 : Configuring and Implementing Entourage for the Mac
- Exchange Server 2007 : Modify Recipient Configuration Modify
- Windows Phone 7 : Controlling Music Playback
- SQL Server 2008 : Indexing for Performance - Putting It All Together (part 2) - Clustered Index Seeks
- SharePoint 2010 : Discard the Check-out of a Page
- Using Cloud Services : Exploring Online Scheduling Applications
- Windows Home Server 2011 : Controlling Services (part 1) - Controlling Services with the Services Snap-In
- DirectX 10 Game Programming : The 2D Resurgence - Sprites