jlongster

Remotely debugging your iPhone Scheme apps with a REPL

July 5, 2009

View the remote debugger source

In an earlier blog post, I showed you how to develop on the iPhone with Gambit Scheme. Although that is cool, what about debugging? Haven't we just cut ourselves off from using either GDB (we aren't using Objective-C) or Gambit's debugger (we aren't running the program from a console)?

A debugger is an essential tool, especially in dynamic languages like Scheme. It may not be as important in languages like Haskell because of type-checking, but even then you want to watch "data flow" as the program is running. I think we can say that using Scheme on the iPhone is impractical until we can use Gambit's debugger for our iPhone apps.

Fortunately, Marc Feeley, implementer of Gambit Scheme, recently wrote a "proof of concept" remote debugger. It allows you to push REPLs from a running Gambit application (the client) to a different machine (the server).

You guessed it. The client will be our iPhone application and the server will be our main computer, allowing us access to REPLs on our computer which are running inside the iPhone application.

I think this is best explained in the screencast below. First, let me explain the philosophy of the remote debugger a little more.

Marc wrote the remote debugger in response to someone asking about debugging multiple Gambit Scheme threads at once on the Gambit mailing list (view original message). With the remote debugger, you can tell Gambit to create a remote REPL for errors on each thread. So if two threads errored, two separate debugging REPLs would open up on the server.

Now we have facilities for debugging Scheme iPhone apps remotely. We can run Scheme apps on either the iPhone Simulator or the iPhone itself, and when an errors occurs we get a real Gambit REPL on our computer for debugging the problem.

What's even cooler is that we have everything we need for running a full Scheme REPL to interact with our iPhone app real-time! Check it out in the screencast below.

Please note that this library is still "proof of concept," and there are more things to figure out and bugs to fix. I am not publishing it standalone yet, but you can find it included in the gambit iPhone example program on github or in Marc's reply.

You can also see how I integrated the debugger library in the example iPhone app here. A couple lines further down and you can see how I fire up a main REPL.

I apologize for all the static. It was raining and I didn't realize it would pick it up.

Next up is support for touch events and access to the accelerometer!

View the remote debugger source

Comments are not implemented yet. In the meanwhile, send me an email.