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
Figure 4. Setting a watchpoint
Figure 5. The debugger notifies you when a watchpoint’s value changes.
Create a new Utility Application named Debug.
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.
the Run button to run the application. Click the Info button in the
lower right of the simulator screen, and the application crashes.
Quit the iPhone Simulator and return to Xcode.
Open MainViewController.m and add a breakpoint at the second line in showInfo (Figure 7).
Figure 7. Debugger window stopped at breakpoint in showInfo
Click the Run button again to run the application. If the Debug Area is not visible, select View | Show Debugger Area.
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.
Stop the iPhone Simulator and return to Xcode. Remove the breakpoint.
From the main menu, select View | Navigators | Breakpoint.
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
Click the Run button to launch the application in the debugger.
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
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.