Most proficient web coders I know don’t need a debugger for simpler tasks. Having grown up in web development (where there were very few real debuggers for years anyway) most web coders I know got used to juggling variables, flow, and several programming languages in their heads.

When you start getting into complex systems or code you did not write, however, a debugger can save you tons of time (not including the terrible startup time some debuggers have – I am looking at you Eclipse Java).

I’ve come to such a wall in some of the projects I’ve been working on.

Most of the projects I am working on are in PHP, so I looked around and found a PHP debugger (dbg) at http://sourceforge.net/projects/dbg2. I tried to install it on my Mac (PPC 10.4.9) and it did not work. Everything seemed to be going fine, but in the end it actually broke php. It resulted in the error:

PowerMacG4:/usr/lib/php/extensions robrohan$ php
dyld: NSLinkModule() error
dyld: Symbol not found: _zend_ini_boolean_displayer_cb
  Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20020429/dbg.so
  Expected in: flat namespace

Trace/BPT trap

Which according to the forums is because the Mac default version of php has the symbols striped out. Supposedly, if I download, compile, and install php myself it should work (so sayth the forums), but I don’t have time for that right now.

To document: the following are the steps I took to get it installed. It seemed to install into the default Apache and looked like it was working until I actually tried to use it – when it blew up. Again, these steps will install the debugger properly, but it doesn’t seem to work on a default Mac install. (This post is mostly to document and for reference later). Also note, if you do this php from the command line will be broken until you remove the extension (dbg.so).

PHP Extension

You’ll need the Apple developer tools installed (should be on a CD that came with your copy of OS X). During the whole process you’ll need to start and stop Apache (probably a couple times). You can do that on the command line with:

$ sudo /usr/sbin/apachectl [stop | start | restart]

Download the unix version of the debugger and command line front end from http://sourceforge.net/projects/dbg2. Unpack them somewhere – your home directory is fine the source directories are not needed after install.

$ tar -zxvf [tar.gz file]

Go into the dbg source directory and edit the file deferphpize. Edit the phpize like to look like the following:

...
phpize=${phpize:-"/usr/bin/phpize"}
...

In a terminal, in the source directory run the deferphpize script (the script will run phpize and configure).

$ ./deferphpize

If you have no errors, run make (if you have errors you’re on your own ;-D)

$ make

Then install the compiled libraries with make install

$ sudo make install

Once make install is done it should put the new .so into: /usr/lib/php/extensions/no-debug-non-zts-20020429/ or something similar. This step might not be needed, but to keep things somewhat clean I also created a symlink to the debug .so (I did it without too and both ways seemed to work):

$ cd /usr/lib/php/extensions
$ sudo ln -s no-debug-non-zts-20020429/dbg.so dbg.so

By default Mac doesn’t seem to use php.ini, so if you haven’t already, create a copy of the default php.ini and put it in the /etc directory:

$ cp /private/etc/php.ini.default /etc/php.ini

Then edit that file (sudo vi /etc/php.ini), and set the variables extension_dir, extension and add the debugger section:

...

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/lib/php/extensions/"

...

extension=dbg.so

...

[debugger]
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = clienthost
debugger.JIT_port = 7869

...

Stop and start Apache. After Apache starts, going to a page with phpinfo() on it should show the debugger installed.

Command Line

In a terminal, go into the cli directory. And just run:

$ ./configure
$ make
$ sudo make install

If you don’t get any errors, you should now have the application dbg-cli installed (/usr/local/bin/dbg-cli). Once you start the program, you could (if it worked) attach it to the server by issuing the commands:

dbg>set mode on
dbg>set mapurlroot http://192.168.1.200/
dbg>set mapremoteroot /Library/WebServer/Documents/
dbg>set maplocalroot /Library/WebServer/Documents/

Read the README in the cli directory for commands on how to use the debugger. To set a break point on test.php on line 4, for example, you’d do:

dbg>break /Library/WebServer/Documents/test.php 4

then use your web browser and go to http://192.168.1.200/test.php?DBGSESSID=1@clienthost:7869. The DBGSESSID tells the server it should use the debugger, and the 7869 is the port the cli debugger would be running on if it worked :-/.

Don’t forget to punch holes in your firewall too.

Like I said though, this didn’t work on the default install on my Mac, but it might prove useful to someone out there and when I get time to recompile, install and configure PHP, it might work.

Comments

This entry was posted on Tuesday, May 8th, 2007 at 7:53 am and is filed under Mac, Web Apps. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

8 Comments so far

  1. Russ Johnson on May 8, 2007 8:38 am

    Hey Rob, that sounds like alot of work! I had a need to do some php work a few weeks ago and I went with an old favorite for apache, php and mysql… the xampp project. They have a mac version now and I have found it run perfectly. Not sure how it would work with that debugger but if it works it would be a lot less work.

    I prefer these types of programs on my mac anyways for development since you can just drag the folder to the trash if you want to get rid of it. I have been using Locomotive for Ruby on Rails development as well, same concept.

    XAMMP – http://www.apachefriends.org/

  2. rob on May 8, 2007 9:34 am

    Thanks Russ – I was stoked to hear XAMMP had a Mac version, but sadly “Intel only” :-/

    I might have to look at trying to compile that myself later. And I agree, you’re right it’s a much cleaner way to do development. I use the built in cf server when doing cf work, and http://locomotive.raaum.org/ when doing rails work. I would prefer a standalone, pre built environment… someday… someday…

  3. Aaron Heimlich on May 8, 2007 11:54 am

    Have you tried getting it to work with MAMP (http://www.living-e.com/products/MAMP-PRO/download.php)? or tried Xdebug (http://www.xdebug.org)?

  4. rob on May 8, 2007 2:05 pm

    MAMP is good stuff. The free version is close to what I was looking for in a easy start / stop all-in-one thing (I think the things I’d complain about are in the pro version which is no in my budget at the moment). I’ll have to try dbg with MAMP.

    xdebug looks to be windows / linux only (or pre-comipled that way anyway), and it doesn’t quite look like what I want, but I’ll check it out later.

    Thanks for the tips Aaron

  5. [...] to a lead from Aaron Heimlich in the last post on my debugging attempt, I’ve got PHP debugging working on my [...]

  6. Vik Rubenfeld on August 12, 2007 9:35 am

    Rob, thanks very much for posting this. I’ve been trying to get DBG.SO installed for 3 days!

    I would add that Mac users may need to activate PHP on their machines, by editing /private/etc/httpd/httpd.conf, and removing the comment sign (#) from the beginning of the lines that activate PHP. On my system, these lines are:

    LoadModule php4_module libexec/httpd/libphp4.so

    AddModule mod_php4.c

  7. dmitri on November 20, 2007 2:31 pm

    just few notes about dbg under Mac. If you compile and install php then dbg.so, it will not work. Reason is pretty simple: Mac’s strip strips too much symbols, yet not only debugger’s and resulting binaries can’t be dynamically loaded. Stupid install script calls strip without certain arguments to avoid such problems yet.
    So, to get working binaries, do not install them at all. Grab what compiler produced in the .libs or .modules directory (for dbg.so and php respectively) and either do not run strip or at least consult with man to see how to strip without harm.

    Then it will work.

    Thanks for attention :)

  8. Sam on August 22, 2008 9:46 pm

    Ugh. Forget all this.. just get MacGDBp. It’s free, too, and works really well.

    http://www.bluestatic.org/software/macgdbp/

Name (required)
Email (required)
Website
Share your wisdom