Running
Now you have something runnable. Run it (Run button, first in the toolbar; or R).
There is a transformation: The Debug area appears at the bottom of the window; and the View control in the toolbar highlights its middle button to match the appearance of the Debug area (Figure 3.3).
Figure 3.3 Running an app in Xcode opens the Debug area (at the bottom of the project window).
The right half of the Debug area is a console that you’ll be using to communicate with the passer-rating tool. If all has gone well, it should be showing something like this:
comps, atts, yards, TDs, INTs:
. . . which is just what the printf() was supposed to do. passer-rating is waiting for input, so click in the console pane and type:
10 20 85 1 0 <return>
Something went wrong. passer-rating crashed. lldb, the debugging engine, takes control, and the debugging displays fill up.
In the Navigator area, the Debug navigator appears, showing the status of the program when it crashed. The upper part of the navigator contains performance bar charts that will be useful when you get to more complex projects. Ignore them for the moment.
What’s left is a stack trace, showing the chain of function calls that led to the crash. The top line, labeled 0, is the name of the function, _svfscanf-l, where the crash occurred; if you click it, you can see the assembly code (the source isn’t available) focused on the very instruction that went wrong. The next line is scanf, which you recognize as the function you called from main, the function on the next line. Xcode identifies main as your work by flagging it with a blue head-and-shoulders icon. Click that line to see what your code was doing when the crash occurred.
- In the Debug area at the bottom of the window, the left-hand pane fills with the names of variables and their values. You see, for instance, “ atts = (int) 20,” which is just what you entered. Chapter 4, “Active Debugging,” discusses this more.
- The Editor area has the most interesting change: A green flag at the left margin and a green banner at the right of the call to scanf. The banner says, “Thread 1: EXC BAD ACCESS (code=1, address=0x0).” The message may be truncated; you can see the full text in a tooltip that appears if you hover the mouse cursor over the banner.