Debugging in ruby 1.9
Asked Answered
S

12

90

What do you guys use for debugging in ruby 1.9? rdebug doesn't seem to be compatible.. is there anything out there?

Scarecrow answered 5/7, 2009 at 4:27 Comment(1)
Ignore the first answer; ruby-debug19 is out of date now.Worms
P
50

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).

Primaveria answered 26/7, 2009 at 23:14 Comment(4)
I made a cursory attempt and it didn't work. Need some more time to look at this.Primaveria
ruby-debug-ide is working now - you can get the new gem at cloud.github.com/downloads/mark-moseley/ruby-debug/…Primaveria
nice work :) but could you make a fatgem (containing both 1.8 and 1.9 ruby-debug versions) so we dont have to remember to do rubydebbug19 ? :)Commix
It doesn't seem fair to downvote this just because the passage of time has made it now the wrong answer. SO needs some way of handling such use cases, to allow the new right answer to become the first listed, without penalizing authors of older answers that are not useful to anyone anymore.Hardpressed
C
167

ruby-debug19 is not maintained anymore. All the other answers are outdated.

But there's an alternative:

debugger to the rescue!

Put this in your Gemfile:

gem 'debugger', group: [:development, :test]

It just works. - And it is included in the rails Gemfile since 3.2.something to replace ruby-debug19. It has the exact same functionality and is actively maintained.

Chatav answered 2/5, 2012 at 13:41 Comment(9)
Works nicely. Much better than installing ruby-debug by hand. Thanks.Apiculate
This really needs to be moved up as the top answer.Elisaelisabet
Yes, really this answer must be the top answer.Laundry
And how about where this actually goes in the Gemfile.Townsville
Does not matter. Put it wherever you like, just not inside a group block (Not in group :development do ... end or the like), because it already contains a group.Chatav
I did that, but I still get the message "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'". debugger is installed and in gem. any suggestions?Shop
This works! Verified with Ruby 1.9.1 by adding gem 'debugger' to the Gemfile.Thurgau
Works with RailsInstaller 2.1.0 (ruby 1.9.3p125 (2012-02-16) [i386-mingw32]) on Win XP. Thanks!Schick
Can I use with IDE? How?Lahr
E
70

UPDATE FOR RUBY 2.0+ and FOLLOWING

byebug is the currently recommended debugger for Ruby 2.0+

This issue has been documented here, and cldwalker, the author of debugger, notes that debugger will be scoped to Ruby 1.9.2 and 1.9.3.

UPDATE 2

It is true that ruby-debug is not actively maintained even if I can't find anywhere that is not maintained any longer.

You can use the new debugger gem if you need a help to start with the new gem you can see Ryan Bates rails cast.

In your Gemfile put:

gem 'debugger', group: [:development, :test]

You can then add a breakpoint anywhere in your code using the debugger keyword.

YOU CAN STILL USE

linecache19 and ruby-debug-base19 with:

bash < <(curl -L https://raw.github.com/gist/1333785)

OLD ANSWERS

Just an add on about this with rvm, ruby 1.9.1-p378. True story is that even if ruby-debug is 1.9.x ready, linecache-0.43 is not. The solution is to install:

gem install ruby-debug19

This solves the problem for me.

OLD UPDATE

If you are having problems with ruby 1.9.2 and Rails 3 debugging putting:

gem 'ruby-debug-base19', "0.11.24"
gem 'ruby-debug19', "0.11.6"

In your Gemfile and doing a

bundle install

Will make you a happy debugger again.

Elytron answered 13/5, 2010 at 11:0 Comment(1)
Thanks, to me that was the more appropriate answer. But maybe this is because you replied almost a year later and things changed for good in that regard.Tersanctus
P
50

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).

Primaveria answered 26/7, 2009 at 23:14 Comment(4)
I made a cursory attempt and it didn't work. Need some more time to look at this.Primaveria
ruby-debug-ide is working now - you can get the new gem at cloud.github.com/downloads/mark-moseley/ruby-debug/…Primaveria
nice work :) but could you make a fatgem (containing both 1.8 and 1.9 ruby-debug versions) so we dont have to remember to do rubydebbug19 ? :)Commix
It doesn't seem fair to downvote this just because the passage of time has made it now the wrong answer. SO needs some way of handling such use cases, to allow the new right answer to become the first listed, without penalizing authors of older answers that are not useful to anyone anymore.Hardpressed
R
3

Some things you could try

1) run it with ruby’s normal debugger -rdebug [1] kind of slow

2) run it with unroller gem [kind of stinks, way slow]

3) use a lot of print statements fast, kind of less introspection possible

4) drop to an irb prompt and run some code from there.

you could list the code by creating your own “drop to irb prompt” that listed the code around itself [use caller to discover where you where] then drop to a normal irb prompt.

5) maybe jruby in 1.9 compat mode has a debugger?

[1] http://beaver.net/rdebug/index-0.html

Ruse answered 6/7, 2009 at 12:53 Comment(0)
B
3

If you still have a problem after installing ruby-debug19 try updating ruby-debug-base19. I had errors and couldn't run WEBrick in debug mode until I did that.

gem update ruby-debug-base19

Oh, and thanks Mr. Moseley for all your hard work!

Beatnik answered 22/8, 2010 at 16:55 Comment(0)
M
2

See my answer here : Ruby-debug not working - Stack Overflow

It's about getting Ruby debugging to work with the following setup

  • Mac OS X Lion 10.7.2
  • Aptana Studio 3 (Build 3.0.8.201201201658)
  • Using rvm, in my project working directory I have a .rvmrc stating:

    rvm use ruby-1.9.3-p0@mygemset
    

I hope this helps!

-- Freddy

Maccabees answered 13/2, 2012 at 12:12 Comment(0)
C
2

I used following and it works great for me:

gem 'debugger', group: [:development, :test]

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] rails 3.2.8

Clubwoman answered 1/4, 2013 at 1:10 Comment(0)
T
0

Netbeans is a good IDE for RoR. Good debugger too.

Titfer answered 6/7, 2009 at 14:28 Comment(1)
Correct me if I'm wrong, but I don't believe the debugger works for Ruby 1.9.1 (C implementation) yet. At least, I have not been successful in getting it to work.Hypnogenesis
O
0

The ruby 1.9.1-p243 version is out and compitable ruby-debug-ide is also working properly. Install ruby-debug-ide using the following command:

gem install ruby-debug-ide

This will install the ruby-debug-base19 and ruby-debug-ide gems. But before this make sure you install the mingw successfully by following the Development kit docs available from RubyForge.

Orle answered 29/8, 2009 at 17:4 Comment(0)
P
0

Latest features are available in ruby-debug-ide19 gem.

Primaveria answered 2/10, 2009 at 16:35 Comment(0)
H
0

There is a lot of choices, depending on your needs.

I use pry-moves because I can "look back" into what happened inside of previous command by re-executing them in debug mode right from the place.

Horsetail answered 1/5, 2018 at 10:55 Comment(0)
C
-1

doesn't anyone use: ruby -rdebug script.rb

then you can use: b script.rb:## (where ## is the line number of a valid ruby command) otherwise you are going to maybe be in the middle of rubygems or one of your required chunks of code.

Then you can simply set the next breakpoint as b:##

Coreencorel answered 10/8, 2013 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.