Wednesday, March 11, 2015

Xcode tuneup and notes

Changing the Build Location

Although most developers don’t need to change the default location of build products, you can specify a different location.

  1. Choose Xcode > Preferences, and click Locations.
  2. Click the Advanced button for the Derived Data setting.


    ../art/derived_data_advanced_button_2x.png
  3. Select a build location from the available options, and click Done.


    ../art/derived_data_pane_2x.png
The derived data settings in the Locations preferences give you control over the location of build products and other derived data. Most developers don’t need to change the default settings. If you’re sure that you need to store your build products in a location different from the one for other derived data, click Advanced.
You have several choices for the location of build products:
  • unique subfolder inside the derived data folder. The subfolder name is based on your project or workspace name and location. This is the recommended choice and the default setting.
  • shared folder inside the derived data folder. You specify the name of this subfolder, which is shared by all projects. This choice assumes that the derived data location is not workspace-relative.
    This option can be used to let separate projects build into the same location so that they can share their build products. Build products are automatically shared among all projects in a workspace, so this setting is unnecessary if you can place your projects in the same workspace.
  • custom path. From the pop-up menu, choose whether the path should be relative to the derived data, relative to your workspace, or absolute. In the text fields, specify the custom path to the build products and intermediate build files.
    ../art/custom_build_location_2x.png
  • The legacy location specified in each target’s build settings.
    This option is intended to support older projects that won’t work correctly unless they’re in custom per-target or per-project build locations (SYMROOT and OBJROOT build settings).

Opening a File in an Editor Pane, Window, or Tab

Opening a file in an Editor Pane, Window, or Tab

Open a file in a specific editor pane, window, or tab using the navigation chooser. You can select a file to open in the project navigator or a jump bar.
  1. In the project navigator, Shift-Option-click the file you want to open.
  2. In the navigation chooser, choose the pane, window, or tab in which you want to open the file.
The navigation chooser shows the layout of the workspace window. If the selected file is already open in one of the editor panes, the navigation chooser displays a star to indicate the pane containing the file.
../art/navigation_chooser.png
With the navigation chooser you can open the file in the primary editor, an existing assistant editor or tab by choosing the items without a plus sign. To open the file in a new assistant editor, tab, or window, chose an item with a plus sign. When making your choice from the navigation chooser:
  • To choose an editor pane or window, double-click it.
  • To choose a new tab, click it.
To dismiss the navigator without making a choice, press the Esc (Escape) key.
See the related article on General preferences to learn how to specify outcomes for these navigation gestures:
  • Click
  • Option-click
  • Double-click

 The DEBUG preprocessor macro in XCode

The preprocessor "DEBUG" macro is defined in all Xcode project templates for debug builds. Preprocessor macros are interpreted at compile time and the DEBUG preprocessor macro can be used to allow debug code to be run in debug builds of your project. If you aren't sure that your project has it defined, you can verify that this it is by selecting the project in Xcode and clicking on the build settings tab. Search for Preprocessing and make sure that DEBUG=1 is being defined for your debug builds (as shown bellow). If it isn't already defined in your project, you can add it. Preprocessor macros are case sensitive.

Figure 1  The DEBUG preprocessor macro setting in an Xcode project.

How do you specify command line arguments in XCode

Command line arguments and environment variables can be set up in the Run section of the scheme editor.
Product -> Edit Scheme... -> Run -> Arguments

Starting a debugging session

Attaching to an existing process

You can attach to Firefox with following command:
(lldb) process attach --name firefox
Some versions of lldb causes crashes after attaching to Firefox.

Running a new process

To start Firefox under the debugger, run lldb followed by "--", followed by the command line you'd like to run, like this:
$ lldb -- obj-ff-dbg/dist/Nightly.app/Contents/MacOS/firefox-bin -no-remote -profile /path/to/profile
Then set breakpoints you need and start the process:
(lldb) breakpoint set --name nsInProcessTabChildGlobal::InitTabChildGlobal
Breakpoint created: 1: name = 'nsInProcessTabChildGlobal::InitTabChildGlobal', locations = 0 (pending)
WARNING:  Unable to resolve breakpoint to any actual locations.

(lldb) r
Process 7602 launched: '/.../obj-ff-opt/dist/Nightly.app/Contents/MacOS/firefox-bin' (x86_64)
1 location  added to breakpoint 1