< Previous PageNext Page > Hide TOC

Debugging in the Debugger Window

The Xcode Debugger window offers a traditional but rich debugging experience. Figure 4-1 shows the Debugger window.


Figure 4-1  The Debugger window

The debugger window

Here’s what the Debugger window contains:

You can change the layout of the Debugger window by choosing one of the following options:

Troubleshooting debugger display: 

If the debugger does not display source code, try the following:

The Debugger Display menu also lets you specify whether to show source code and/or disassembly code. See “Viewing Disassembly Code and Processor Registers” to learn more about viewing disassembly code.

In this section:

Viewing Stack Frames in the Debugger Window
Viewing Variables in the Debugger window
Viewing Disassembly Code and Processor Registers


Viewing Stack Frames in the Debugger Window

For each function call that your program makes, the debugger stores information about that call in a stack frame. These stack frames are stored in the call stack. When execution of your program is paused in the debugger, Xcode displays the call stack for the currently running process in the Thread list and puts the most recent call at the top.

Selecting any function call in the call stack displays the stack frame for that function. The stack frame includes information on the arguments to the function, variables defined in the function, and the location of the function call. Xcode displays the frame’s variables in the Variable list and displays its currently executing statement in the text editor with the process counter (PC)—a red arrow. If a stack frame is grayed out, no source code is available for it.

To learn about viewing the stack frame in the text editor, see “Debugger Strip.”

Viewing Variables in the Debugger window

The variables view shows information—such as name, type and value—about the variables in your program. Variables are displayed for the stack frame that is currently selected in the Debugger window. The variables view, shown in Figure 4-2, appears in upper-right portion of the Debugger window by default. The variables view can have up to four columns:

  1. The Variable column shows the variable’s name.

  2. The Type column displays the type of the variable. This column is optional. To display it, choose Debug > Variables View > Show Types.

  3. The Value column shows the contents of the variable. If a variable’s value is in red, it changed when the application was last active. You can edit the value of any variable; the changed value is used when you resume execution of your program.

  4. The Summary column gives more information on the contents of a variable. It can be a description of the variable or an English language summary of the variable’s value. For example, if a variable represents a point, its summary could read “(x = x value, y = y value).” You can edit the summary of a variable by double-clicking the Summary column or choosing Debug > Variables View > Edit Summary Format. For a description of how you can format variable summaries, see “Using Data Formatters.”

You can choose which columns the debugger shows in the Variable view; Xcode remembers these columns across debugging sessions.


Figure 4-2  Variable list

The variables view

Variables in the Variable view are grouped by category, as shown in Figure 4-2. To view variables in any of these groups, click the disclosure triangle next to that group. These groups are:

To view the contents of a structured variable, click the disclosure triangle beside the variable’s name. You can also use a data formatter to display a variable’s contents in the Summary column, as described in “Using Data Formatters,” or you can view a variable in its own window. Viewing a variable in its own window is particularly useful for viewing the contents of complex structured variables. To open a variable in its own window, double-click the variable’s name or select it and choose Debug > Variables View > View Variable in Window.

To learn how to view variables in the text editor, see “Debugger Datatips.”

Viewing Global Variables

The Variable list contains a Globals group, which is initially empty. You can choose which global variables to display in the Globals group using the Globals Browser, shown in Figure 4-3. The Globals Browser lets you search for global variables by library.


Figure 4-3  Globals Browser

The Globals Browser

To open the Globals Browser, choose Run > Show > Global Variables.

The debugger must be running and execution of the program being debugged must be paused for this item to be available. If you attempt to open of the Globals group when it’s empty, Xcode automatically opens the Globals Browser.

The Library list, on the left of the Globals Browser, lists the available libraries, including system libraries and your own libraries. To see a library’s global variables, select that library in the list; the global variables defined by that library are shown in the table to the right. In the globals table, you can see:

You can use the search field at the top of the Globals Browser window to filter the contents of the global variables table. To the right of the search field, Xcode displays the number of global variables currently visible, as a fraction of the total number of global variables in the currently selected library.

To add a global variable to the Globals list in the Debugger window variable view, select the checkbox in the “View” column next to the global variable.

When you select a library in the Library list, the full path to that library is displayed below the list.

Viewing Disassembly Code and Processor Registers

When you choose to display disassembly code or when no source code is available for the function or method selected in the Thread list, Xcode displays a pane with disassembled code in the debugger. Figure 4-4 shows disassembled code in the debugger after choosing to view source and disassembly code.


Figure 4-4  Disassembled code in the Debugger window

Viewing disassembled code in the debugger

When the disassembly pane is shown, the Variable list contains a Registers group containing all the processor registers.



< Previous PageNext Page > Hide TOC


© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.