31

I know the debugger gem is not and never will be compatible with ruby 2.0 per "officially support ruby 2.X".

In the changelog of Ruby 2.0 is:

Debug support

DTrace support, which enables run-time diagnosis in

production TracePoint, which is an improved tracing API

Is there something out of the box for debugging with Ruby 2.0? Can somebody explain this to me?

Community
  • 1
  • 1
Intrepidd
  • 19,772
  • 6
  • 55
  • 63

4 Answers4

54

The debugger gem can be used but it still has issues.

Install byebug which was written for Ruby 2.0 debugging.

For breakpoints, use the byebug command in your code instead of debugger.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Alain Beauvois
  • 5,896
  • 3
  • 44
  • 26
  • Doesn't actually appear to work with Ruby 2.0.0 (http://stackoverflow.com/q/17044127/388916) – Hubro Jun 12 '13 at 10:50
  • It works, I use byebug every day : Rails 3.2.13, rvm 1.20.10, ruby 2.0.0p195 and gem byebug 1.4.0. – Alain Beauvois Jun 13 '13 at 20:01
  • 2
    @Codemonkey, byebug doesn't (and won't) work with Ruby 1.9.x but it _must_ work for Ruby 2.0.0 because that's its only purpose. I just answered your question, if byebug is still not working for you, please let me know. – deivid Jun 14 '13 at 11:28
7

Version 1.4.0 of the debugger gem now installs without problems. There are still some issues but this should be fixed soon.

The debugger gem does not play well with Ruby 2. Instead, install the Byebug gem that is fully compatible with Ruby 2.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • 9
    any details on the issues? I'm having trouble with "next" acting like "step", which makes it impossible to use. – Steven Soroka Mar 28 '13 at 18:49
  • 4
    Hi @StevenSoroka, I made this gem to overcome debugger's issues with Ruby 2.0: [byebug](https://github.com/deivid-rodriguez/byebug). If you try it and have any issues, please let me know. – deivid May 06 '13 at 13:18
  • Thanks @devid! This has been killing me. – Paul Alexander May 21 '13 at 02:48
  • You are welcome @PaulAlexander. It was killing me too...that's why I made it! – deivid May 23 '13 at 10:11
  • @deivid why release yet another gem instead of fixing the debugger gem? it seems to be the most popular debugger library at the moment. – rubiii May 25 '13 at 08:41
  • 1
    @rubii I did try helping, but my help was rejected (see https://github.com/cldwalker/debugger/issues/47#issuecomment-14965459). The way things stand now, I'm very happy using byebug regardless of its lack of popularity. – deivid May 25 '13 at 09:01
  • @deivid i see. maybe i missed it, but i would add some information to the readme about why people should use your fork instead of the debugger gem. thank you. – rubiii May 25 '13 at 09:25
2

debug.rb (aka binding.break)

Consider using a new Ruby debugging tool called debug.rb.

It supports syntax highlighting and many more out-of-the-box.

Also, it is worth mentioning that it is developed by the Ruby core team.

Just place binding.break anywhere in your codebase.

Here is an example:

binding.break example

Also, it is a default Rails debugger starting from version 7.

Notes:

  • Do not forget about require 'debug'
  • q # quit command

Sources:

Marian13
  • 7,740
  • 2
  • 47
  • 51
0

Use pry:

gem install pry  
gem install pry-debugger

See "Debugging Ruby With Pry".

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Kevin Suttle
  • 8,358
  • 3
  • 33
  • 37
  • 3
    Pry is great if I want to print out state or examine things and can know where to hit pry points. It doesn't allow me to step or next or set breakpoints ahead of times, and as such isn't really an adequate substitution for debuggers when debuggers are available. – Sam Hartman May 30 '14 at 01:55