Wednesday, August 25, 2010

Adding a Drizzle Executable in Xcode

In my last post, I explained how to setup Drizzle under an Xcode project. This allows you to take advantage of Xcode's features while developing on Drizzle (or any other project of your own choosing). The one thing we weren't able to do was debug the Drizzle executable. This post remedies that.

So it turns out that this is an easy fix. But for Drizzle, there are a few extra hoops you have to jump through in order to get it to work.

The basic steps we need to do for Drizzle are:
  1. Add a custom executable in Xcode
  2. Setup any arguments you want to pass to the executable
  3. Setup any environment variables needed for the executable to run properly
For most other projects, you can probably just get away with #1 and possibly #2. For Drizzle, though, we need to do #3 so that it can find its libraries.

Step #1 is easy. In the Groups & Files window, right click on Executables and then Add -> New Custom Executable...



This will pop up a window where you define where the executable resides. Once that is done, you can define what arguments to pass it, and what environment variables should be set when it runs, among other things. These should be self explanatory, and you should be able to set this up for your particular project. For Drizzle, though, it isn't so intuitive.

In Drizzle, after you run configure and make, the executable lives in a hidden directory within your xcode-branch repo directory. It will actually be in:

$drizzle-repo/xcode-branch/drizzled/.libs/drizzled

The executable you see in the xcode-branch/drizzled subdirectory is actually a shell script that runs the real executable for you. Don't ask me why. So enter the path to the executable in the .libs subdirectory:

Once you enter in the path and click Finish, you are given the chance to edit executable working directory, arguments, environment variables etc.  The important part here is the information under the Arguments tab. We need to set the arguments to the executable as well as set the DYLD_LIBRARY_PATH environment variable so that the executable can find its dynamic libraries (otherwise, it looks for them in the installation directory, which if doesn't exist yet, will cause the executable to not start). Here is an example:

Once you have this setup, you should now be able to run your executable (after you've built it, of course), and use the Xcode debugger to merrily do some bug hunting. Make sure that you have unselected the Load symbols lazily option in Xcode Debugging preferences so that your breakpoints will be recognized!

Happy debugging.

No comments:

Post a Comment