Manu Raghavan

Ruby-Debug on 1.9.1

If you’re running Ruby 1.9.1, you might have problems installing the latest version of Ruby-debug (as of this writing), which now requires linecache19 — a gem that itself has a dependency on Ruby >= 1.9.2. With a little hacking, I managed to fork a version of Mark Moseley’s awesome ruby-debug19 and patched it for legacy applications that need to run on 1.9.1.

To install, use the following ordered dependencies in your Gemfile (if you’re using Bundler):

Gemfile
1
2
3
  gem "linecache19", "0.5.11"
  gem "ruby-debug-base19", :git => 'git@github.com:manur/ruby-debug.git', :branch => 'ruby191'
  gem "ruby-debug19"

Subsequently, you should be able to launch an inline debugger at server-launch time:

1
2
3
4
5
6
7
8
# Rails < v3:
$ script/server --debugger
Booting WEBrick
=> Rails 3.0.0 application starting on http://0.0.0.0:3000
=> Debugger enabled

# Rails >= 3.0
$ rails s --debugger

When you want to inspect specific variables, insert debug slugs like so in a Rails view to pause execution of the Ruby engine mid-template:

app/views/info/index.html.erb
1
2
3
  <p> Lorem ipsum </p>
  <% debugger -%>
  <p>dolor sit amet...</p>

On page load, launch an IRB session to interact to inspect the current state of execution:

1
(rdb:1)  irb

Now, feel free to execute arbitrary Ruby code, within the scope you embedded a debugger in.

For more documentation, refer to the ruby-debug Command Syntax.

Comments