Ruby and Rails for business

Rants about software development

Installing ruby-debug19 with ruby 1.9.3 on rvm

In the Gemfile of a new Rails 3 application, this section is commented out by default:

Gemfile
1
2
3
...
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

Uncommenting the last line will install ruby-debug19 and dependencies (including linecache19).

However, in the combination of rvm with ruby 1.9.3 on Ubuntu this fails. The bundle install command hangs forever on the installation of linecache19 (until interrupted with Control-C):

1
2
3
4
5
6
7
8
$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.9.2.2)
...
Installing linecache19 (0.5.12) with native extensions
^C
Interrupt: An error occured while installing linecache19 (0.5.12), and Bundler cannot continue.
Make sure that `gem install linecache19 -v '0.5.12'` succeeds before bundling.

The root cause of the problem was not clear, but I was able to make this pass with a “manual” gem install of linecache19 and ruby-debug-base19 with an explicit include of an extra source directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ gem install linecache19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0
Building native extensions.  This could take a while...
Successfully installed linecache19-0.5.12
1 gem installed
$ bundle install
Fetching source index for http://rubygems.org/
...
Installing ruby-debug-base19 (0.11.25) with native extensions ^C
Interrupt: An error occured while installing ruby-debug-base19 (0.11.25), and Bundler cannot continue.
Make sure that `gem install ruby-debug-base19 -v '0.11.25'` succeeds before bundling.
...
$ gem install ruby-debug-base19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0
Building native extensions.  This could take a while...
Successfully installed ruby-debug-base19-0.11.25
1 gem installed
$ bundle install
...
Your bundle is complete! ...
$

Once this hurdle is passed, a second problem arises …

The currently published versions of ruby-debug-base and linecache19

1
2
ruby-debug-base19 (0.11.25)
linecache19 (0.5.12)

raise exceptions on Rails on ruby 1.9.3

1
2
3
4
5
6
.../gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require':
.../gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_current_thread -
.../gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so (LoadError)
 from .../gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `<top (required)>'
  from .../gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `require'
 from .../gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `<top (required)>'

The solution for this problem is found on a number of blog posts:

and boils down to this:

  • download newer versions linecache19-0.5.13.gem and ruby-debug-base19-0.11.26.gem from http://rubyforge.org/frs/?group_id=8883
  • gem install those 2 gems from the local Download location, with the above include trick into the current rvm gemset
1
2
3
4
5
6
7
8
$ gem install ~/Downloads/linecache19-0.5.13.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0
Building native extensions.  This could take a while...
Successfully installed linecache19-0.5.13
1 gem installed
$ gem install ~/Downloads/ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0
Building native extensions.  This could take a while...
Successfully installed ruby-debug-base19-0.11.26
1 gem installed
  • force the Gemfile to use these version
1
2
3
4
5
# To use debugger
gem 'linecache19', '0.5.13', :path => "~/.rvm/gems/ruby-1.9.3-p0/gems/linecache19-0.5.13/"
gem 'ruby-debug-base19', '0.11.26', :path => "~/.rvm/gems/ruby-1.9.3-p0/gems/ruby-debug-base19-0.11.26/"

gem 'ruby-debug19', :require => 'ruby-debug'
  • run bundle install

Once these higher level gems are used, using the ruby-debugger works. E.g. in an rspec test spec:

1
2
3
4
5
require 'ruby-debug'

  describe "my difficult feature" do
  ...
  end

and now simply adding to the code under test

1
  debugger

yields us a debugging prompt to check in detail the operational code

1
2
result = false
(rdb:1) n