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.