Debugging Support in Edge Rails

Posted by Mike
Liquid error: wrong number of arguments (5 for 2)

One of the things that DHH announced as a feature for Rails 2.0 in yesterday’s keynote was “breakpoints are back.” Given that I’m still at the stage in my Rails journey where my applications tend to spit out large stack traces at a moment’s notice, this was definitely of interest to me. So I took a few minutes today to find out how easy it was to do this with the current cutting-edge bits. The answer turns out to be, pretty easy. If you want to poke at this stuff today, here’s what you need to do.

1. Get on to Edge Rails (anything more recent than Changeset 6611 will do).

2. Install the ruby-debug gem:


sudo gem install ruby-debug

3. Build your Rails application (this step left as an exercise for the reader).

4. Start up your development server with


ruby script/server --debugger

If you haven’t looked at Edge lately, this now starts Mongrel by default instead of WEBrick.

5. Anywhere in your source where you want to fall out into irb, insert the single line of code


debugger

6. Browse to a page that will hit the debugger statement and then flip over to the terminal window where you started the server. You’ll be sitting at an irb prompt. You can evaluate expressions, inspect and change objects, and so on. Type cont to continue on with execution.

7. ruby-debug supports a bunch of other commands. To drop from irb into the debugger proper, type Ctrl-d. Type help to see the command list. Type irb to return to irb (and then cont to go on with your application’s business).