Debugging in ruby 1.9
Note: this answer was correct but is now out of date. See the below correct answer. TL;DR: use 'debugger' now.
ruby-debug is now available with Ruby 1.9.x. See http://www.github.com/mark-moseley
To install (using gem on 1.9 Ruby installation):
gem install ruby-debug19
(with perhaps the necessary 'sudo' in front of it).
ruby-debug with Ruby 1.9.3?
Update (April 28, 2012)
Try the new debugger gem as a replacement for ruby-debug.
(credit to @ryanb)
Update (March 2, 2012)
Installation of linecache19 and ruby-debug-base19 can be easily done with:
bash < <(curl -L https://raw.github.com/gist/1333785)
(credit to @fredostarr)
Original answer
Have you looked at ruby-debug19 on ruby-1.9.3-preview1?
Here's a temporary solution:
http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debugExcerpt from the site:
First download linecache19-0.5.13.gem and
ruby-debug-base19-0.11.26.gem from
http://rubyforge.org/frs/?group_id=8883, then …$ gem install linecache19-0.5.13.gem
Building native extensions. This could take a while...
Successfully installed linecache19-0.5.13
1 gem installed
$ gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=/Users/santiago/.rbenv/source/ruby-1.9.3-p0
Building native extensions. This could take a while...
Successfully installed ruby-debug-base19-0.11.26
1 gem installed
$ irb
irb(main):001:0> require 'ruby-debug'
=> true
How can I debug require in Ruby 1.9
When rubygems
is required it replaces Ruby’s Kernel.require
method with its own that searches for required files in the installed gems. The integration with Ruby 1.9 and above is basically a call to require 'rubygems'
during start up. This can be disabled with the (poorly documented) --disable-gems
option to the ruby
executable. You could make use of this to set up your debugging before explicitly calling require 'rubygems'
.
# start with ruby --disable-gems
require 'debug' #standard library debug - doesn't load rubygems
require 'rubygems' #now you can debug this
If you want to use the debugger
gem for your debugging it’s still possible but a little trickier as you have to load debugger
without loading Rubygems. In order to do this you’ll need to manually set up your load path to include Debugger’s lib dir, as well as the lib dirs of any gems Debugger depends on. This is basically what Rubygems does for you when you call require 'debugger'
with Rubygems loaded.
To determine what libs Debugger needs, you can use this command:
ruby -e "lp = $:.dup; gem 'debugger'; puts $: - lp"
This is little Ruby script that first takes a copy of the load path ($:
is the load path, you can also use $LOAD_PATH
), then activates the Debugger gem, then prints out the difference between the new load path and the original. This will give you the dirs that activating debugger
adds to the load path.
On my machine this looks like this:
$ ruby -e "lp = $:.dup; gem 'debugger'; puts $: - lp"
/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/columnize-0.3.6/lib
/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-ruby_core_source-1.2.0/lib
/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-linecache-1.2.0/lib
/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-1.5.0/lib
You can now use this to create a script to use Debugger to debug require 'rubygems'
:
# start with ruby --disable-gems
# set up the load path without loading rubygems
$:.unshift '/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/columnize-0.3.6/lib'
$:.unshift '/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-ruby_core_source-1.2.0/lib'
$:.unshift '/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-linecache-1.2.0/lib'
$:.unshift '/Users/matt/.rvm/gems/ruby-1.9.3-p385/gems/debugger-1.5.0/lib'
# require debugger and start it
require 'debugger'
debugger
require "rubygems" #now you can debug this with debugger
Unable to debug in RubyMine 4.5 using Ruby 1.9.3
UPDATE: RubyMine 6+ supports debugger gem.
Make sure to remove gem 'debugger'
from your Gemfile
, it's a known conflict that will break debugging from RubyMine. You need only 2 gems related to debugger, exactly as stated in my another answer linked in your question.
After removing the gem you need to ensure it's not referenced anywhere in the project. In this particular case r_spec_runner.rb
had require 'ruby-debug'
statement causing cannot load such file -- ruby-debug
error when trying to run rails console
.
rails4 debugging breakpoints with ruby 1.9.3?
Use debugger. In general, do this
ruby-debug - for ruby 1.8
debugger - for ruby 1.9
byebug - for ruby 2.0
and things should be fine.
how do I install ruby-debug in ruby 1.9.3 / Rails 3.2.1
Thanks to @Marc Talbot's comment in the OP, I found a working recipe.
download linecache19 and ruby-debug-base19 from RubyForge:
% curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
% curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
compile the two gems
% gem install linecache19-0.5.13.gem
Building native extensions. This could take a while...
Successfully installed linecache19-0.5.13
1 gem installed
...
% gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$SANDBOX/packages/ruby-1.9.3-p0
Building native extensions. This could take a while...
Successfully installed ruby-debug-base19-0.11.26
1 gem installed
...
update your Gemfile
# file: Gemfile
...
group :development do
gem 'linecache19', '0.5.13'
gem 'ruby-debug-base19', '0.11.26'
gem 'ruby-debug19', :require => 'ruby-debug'
end
bundle install and test the debugger
% bundle install
Fetching source index for http://rubygems.org/
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
% irb
irb(main):001:0> require 'ruby-debug'
=> true
irb(main):002:0> debugger
$SANDBOX/usr/lib/ruby/1.9.1/irb/context.rb:166
@last_value = value
(rdb:1) p 'hooray'
"hooray"
Hopefully this will help others.
Trying to use a debugger in rails 3 - ruby 1.9.3 [Refactoring]
If you want something flexible with the option of setting breakpoints and navigating through code I can recommend pry-debugger
. If you want something with glitter and magic jazz_hands
is the gem you are looking for.
Trying to debug ruby 1.9.3p194 rails 3.2.7
Even though this question duplicates two other questions here, I'll answer it for the sake of completeness.
In order to debug from RubyMine you must use only 2 debug gems:
ruby-debug-base19x
ruby-debug-ide
Exactly these gems must be used, not ruby-debug-base19
, not ruby-debug19
, not debugger
. All the other debug gems must be uninstalled and removed from the Gemfile
.
See this answer for the details how to install proper debug gem versions. If you have a problem downloading linecache19-0.5.13.gem
gem, try this mirror instead.
Verify with gem list
that you have the following or more recent versions installed:
ruby-debug-base19x (0.11.30.pre10)
ruby-debug-ide (0.4.17.beta9)
No other debug gems should be listed by this command.
As stated in another answer, debugger
gem must not be used, it will conflict with the debug gems used by RubyMine and debugger will not work. You must uninstall this gem, remove it from the Gemfile
and ensure that your code doesn't call any methods from this gem and is not trying to load it.
Happy debugging!
As suggested by @Anjan, your Gemfile
for debugging can look like this:
gem 'linecache19', '>= 0.5.13', :git => 'https://github.com/robmathews/linecache19-0.5.13.git'
gem 'ruby-debug-base19x', '>= 0.11.30.pre10'
gem 'ruby-debug-ide', '>= 0.4.17.beta14'`
Just run bundle install
to get the proper versions of the required debug gems.
Using ruby-debug with rails 3.1.1 and ruby 1.9.3
Just put the line gem 'ruby-debug19', :require => 'ruby-debug'
in your Gemfile should do. Then run bundle install
Related Topics
Error: While Executing Gem ... (Gem::Filepermissionerror)
Getting Output of System() Calls in Ruby
How to Convert a String Object into a Hash Object
Connecting Rails 3.1 With Multiple Databases
Rails 4: Before_Filter Vs. Before_Action
Add a Default Value to a Column Through a Migration
Detect Mime Type of Uploaded File in Ruby
Rvm and Thin, Root Vs. Local User
Validation for Non-Negative Integers and Decimal Values
Difference Between Rake Db:Migrate Db:Reset and Db:Schema:Load
How to Find and Return a Duplicate Value in Array
In Rails, How to Render Json Using a View
Sort Hash by Key, Return Hash in Ruby