05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

470<br />

CHAPTER 25 MAC <strong>OS</strong> X DEVELOPMENT: THE TOOLS<br />

Breakpoints<br />

Debuggers, like vampires, cannot enter uninvited. To invite GDB into your program, mark your<br />

code with breakpoints. Setting a breakpoint is simple—just click the gutter that runs along the<br />

left side of the editor. This will add a blue pointer, representing the breakpoint. To toggle the<br />

breakpoint on and off, click it. To remove it, drag it from the gutter and it will vanish in a puff<br />

of smoke.<br />

Normally, breakpoints are inactive and the program runs without paying any attention to<br />

them. To activate breakpoints, select Activate Breakpoints from the Run menu, or click the<br />

appropriate icon in the toolbar.<br />

The normal reaction to a breakpoint is for the program to suspend execution before the line<br />

of code that contains the breakpoint. However, this is not the only option. Breakpoints can be set<br />

to only break on certain conditions, or to immediately continue after logging something to the<br />

console, running other GDB commands, making a sound, or even reading something aloud via<br />

text-to-speech. Unlike hard-coded logging, breakpoints can be set, removed, deactivated, moved,<br />

and edited on the fly.<br />

Ctrl+clicking or right-clicking the gutter will bring up the breakpoint contextual menu,<br />

which has several additional options, including a list of predefined breakpoint behaviors. There<br />

is also a Breakpoints window where breakpoints can be set, removed, and edited. To launch the<br />

Breakpoints window, select Breakpoints from the Show submenu of the Run menu.<br />

You can also set breakpoints outside your own code. A common trick among programmers<br />

is to create a breakpoint named objc_exception_throw. This will cause the program to automatically<br />

stop whenever it is about to throw an error. Since unexpected errors lead to crashes, this<br />

allows the programmer to examine the state of the program right before everything falls apart.<br />

Xcode’s Debugger Interface<br />

When a program stops at a breakpoint, Xcode launches its graphical interface to GDB, as shown<br />

in Figure 25-18. From the GDB interface, the program’s state and execution can be examined<br />

and controlled.<br />

Figure 25-18. Xcode’s traditional debugging environment

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!