Debugging Drupal with MacGDBp

Oct
10
By Dan Kurtz | Filed Under: code, php, technology, Tools, workflow

Confession time. I don't use an IDE (Integrated Development Enviroment) for Drupal development. Sometimes, I kind of wish I did because having all of the development tools in one place is great; but all of the IDEs I've tried for my platform (I'm a OS X user) try to change the way I work, lack key PHP features, or are incredibly slow. And I really like TextMate. Thankfully I've found a great PHP debugger for OS X called MacGDBp and, at least for me, the chances of switching to an IDE continue to dwindle.

MacGDBp requires the xdebug PHP extension, which is useful to have even if you don't use a debugger, since it provides pretty stack traces and other tools. If you use Macports, you can install xdebug by typing sudo port install xdebug at the terminal. Otherwise, Komodo has a packaged version of the extension, and the MacGDBp site gives full setup details. One xdebug is installed, you can install MacGBBp just like a normal OS X application.

Now onto debugging, finally! Fire up MacGDBp and you'll be presented with two windows: a debugger and a list of breakpoints. The first thing to do is set breakpoints. Hit the "+" button at the bottom of the breakpoint window to choose the file you want to add the breakpoint to. The file will open up at the top of the window, and you can click on a line to add a breakpoint to that line, and all the breakpoints are saved when you close MacGDBp. While you can add a breakpoints by calling xdebug_break(); in your code, it is frighteningly easy to forget to remove those lines before shipping, so I wouldn't recommend it. The MacGDBp breakpoint window:

To run the debugger, click the power button in the main debugger window. The debugger will attempt to make a connection to xdebug, but unless you happen to be in the middle of a page load, nothing spectacular will happen. Try loading a URL that will call your breakpointed code. You won't get a response from the browser, because PHP will be waiting for a response from the debugger. At this point, the "play" button in MacGDBp should work and allow you to step through the code as you would for a normal debugger. Press it once to start running through the code. It'll stop when it hits the first breakpoint, and give you a stack trace and variable list at that point in the code. Like most debuggers, you can then choose to step over the breakpoint line to the next line of code, step into the breakpointed line, or continue executing until the next breakpoint. You can add or remove breakpoints at any time, from either window. Here's a screen shot of the main debugger window with variables, stack trace, and code context:

While it would be convenient to connect MacGDBp to a development server, I haven't yet figured out whether it's possible to get xdebug to make the connection through the security. On the whole I'm pretty happy with the light-weight graphical interface, the uncomplicated window into my code, and standard methods of debugging. I've found that MacGDBp does exactly what I need it too, and despite not working with the development server (and the terrible name!) it means I can stick with the tools I'm comfortable with for other aspects of development, and that's a good thing for my sanity and my code.

3 Comments

I see that I have to do: sudo

I see that I have to do:
sudo port install php5-xdebug

When it comes to PHP and

When it comes to PHP and Drupal development, I'm a huge fan of the build-your-own-workbench approach. TextMate and MacGDBp are two major components I use (I've got several custom TextMate bundles for everything from Drupal to Phing).

A few months ago, I wrote up detailed instructions for getting MAMP, TextMate, and MacGDBp all working together:

http://technosophos.com/content/debugging-your-php-code-xdebug-mamp-text...

That's the configuration I use when working on Drupal and QueryPath.

I pretty much had really

I pretty much had really benefited from useful information, thank you.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options