Programming4us
         
 
 
Programming

iOS SDK : Debugging (part 2) - Watchpoints

8/17/2011 11:34:21 AM

Watchpoints

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.

    Tip

    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
 
 
Most View
- Windows Server 2008 : Using wbadmin (part 1)
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 3) - The Line Tool
- Windows 7 : Customizing Startups Using the Boot Configuration Data
- Exchange Server 2003 : SMTP Protocol Configuration and Management - Managing SMTP Message Transfer Support
- Windows Server 2008 : Configuring FTP (part 7)
- Active Directory Domain Services 2008 : Identify Operations Master Role Holders
- Windows Server 2008 : Adding an Account to the Event Log Readers Group
- Managing Websites with IIS Manager (part 6) - The Machine Key and Windows Authentication
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 4) - Serving Images More Effectively
- Windows Server 2008 : Licensing and Activation - Forcing Registration of KMS Server SRV Records, Manually Creating an SRV Record for KMS
Top 10
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 3) - Configuring Recipient Filtering
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 2)
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 1)
- Implementing Edge Services for an Exchange Server 2007 Environment : Installing and Configuring the Edge Transport Server Components
- What's New in SharePoint 2013 (part 7) - BCS
- What's New in SharePoint 2013 (part 6) - SEARCH
- What's New in SharePoint 2013 (part 6) - WEB CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 5) - ENTERPRISE CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 4) - WORKFLOWS
- What's New in SharePoint 2013 (part 3) - REMOTE EVENTS