Running Programs

After you build a product, you can test it from Xcode. To run a product, perform these steps:

  1. Choose the appropriate build configuration. Depending on how you want to test the product, you run a release or debug configuration of it. See Build Configurations for details.

  2. Build the product. In the build process you may find problems that prevent Xcode from creating a binary to run. Xcode must successfully build the product before you can run it. See Building with Xcode for more information.

  3. Run the product. To run the product, do one of the following:

    • Choose Run > Run – Breakpoints Off.

    • Choose Run > Debug – Breakpoints On.

    • Choose Run > Run with Performance Tool.

    If none of these commands are available, try associating an executable with the selected target. See Defining Executable Environments.

In addition, after halting a program, you can restart it using the last run configuration by choosing Run > Go.

Viewing Console Output

Many programs print messages to stdout, as well as logging debugging messages to the console or stderr. When you run your program in Xcode, you can see this output in the console window. In addition, if you are creating a command-line program that takes input from stdin, you can use the console to interact with your program. To open console, choose Run > Console.

Halting a Program

In some unique cases, you may want to unconditionally stop your program’s execution with a trap. Such an operation in programs launched from Xcode would cause the debugger to appear, pointing to the code line that caused the trap. In programs launched directly, the CrashReporter application would log a crash with stack traces for the program’s threads.

Listing 11-1 shows the assembly-language instructions that stop a program.

Listing 11-1  Halting a program with a trap instruction

asm {trap}            ; Stops a program running on PPC32 or PPC64.
__asm {int 3}         ; Stops a program running on IA-32.