[How-to] Debug a Preference Pane with XCode

Here is a quick tip to help you debug your Preference Pane with XCode, because debugging with NSLog() is painful and not very productive.

So, open your project with XCode, go to the Project menu and chose News Custom Executable.
Add a custom executable to a Xcode project
In the Executable Path field, chose System Preference application, and for the name of the executable, chose whatever you want.
Add a custom executable to a Xcode project
Now you can put breakpoints in your code and debug it as you normally do.
When you will hit the debug button to launch your project, System Preference will launch, then click on your Preference Pane to load it and you are good to go.
Add a custom executable to a Xcode project

2 thoughts on “[How-to] Debug a Preference Pane with XCode

  1. In XCode 4 you need to do it a bit differently:

    - Choose “Edit Scheme” from the “Product” menu
    - Open up the “Run” scheme and select the “Run” action
    - From the “Executable” popup select “Other…” and choose System Preferences

    You should be able to get the Preference Pane to install by another means, such as using the Run scheme’s pre-action and inserting a shell script to do the install. I haven’t figured out the best supported way to do this, however.

  2. Figured it out!

    Here’s how to get the built product installed with XCode 4. There are three Build Settings that need to be edited to get XCode 4 to do the right thing. You should only set them for the “Debug” configuration of your “PreferencePane” target. Since the “Debug” configuration is used by the “Run” action in the “Product” menu, this will allow you to use Command-R to build, install, and run the Preference Pane all in one step.

    Here are the relevant Build Settings:

    - Deployment Location (DEPLOYMENT_LOCATION): Yes
    - Installation Build Products Location (DSTROOT): /
    - Installation Directory (INSTALL_PATH): $(USER_LIBRARY_DIR)/PreferencePanes

    The “Installation Directory” setting should be applied to both the Debug and Release configurations, for completeness. $(LOCAL_LIBRARY_DIR) is also possible, but you probably need to set permissions to be able to write to that folder.

    Normally the Installation Build Products folder is set to a subfolder of /tmp – which is probably for safety, since you don’t want every new project copying its products into their install locations by default. Setting it to “/” gives you an actual installation instead of a simulated one.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>