Lonely Cactus

A life of punk, code and apathy

Thursday, November 06, 2008

Debug

One of the pointless projects I've been working on is porting PHP's MySQL interface to Guile. There is already a MySQL interface for Guile: Guile-DBI. It has recently fallen into decadence and is being unoficially updated through a series of patches pushed to the guile-user mailing list. Typical Scheme story: the miniscule developer community can't keep up with the maintenence of packages. If I were a good community citizen, I'd be helping maintain the Guile-DBI package, but, since it doensn't really have a home on the web, I'm a bit leery of digging in.

Anyway, the great fun and challenge I've had in porting php_mysql.c over as a Guile library has been how to step through the debuggers. Since I want them to be essentially identical in functionality, I write short PHP and Guile scripts that should accomplish the same thing, and then step through, making sure that the are doing identical actions.

Debuggin PHP is largely written in C. But my Guile-MySQL library is mostly scheme with a very thin layer of C code mostly involved in directly calling MySQL C API functions.

On the PHP side, I compiled a CGI version of PHP with the debugging symbols in. I use libtool to call gdb on the cgi php and set my breakpoints to catch its entry into the php_mysql.c. Debugging is mostly occurs in GDB.

The trick on the scheme side is running scheme code in GDS in EMACS from within a libtool --mode=execute call to gdb.

It is turtles all the way down.