Many people (including me) have complained about the lack of a good GUI debugger for Ruby. Now that some are finally getting usable, I’ve found I actually prefer IRB-style ruby-debug to a GUI.
There’s good tutorial links on the ruby-debug homepage, and a very good Cheat sheet, but I wanted to give a bare-bones HOWTO to help you get immediately productive with ruby-debug.
Install the latest gem
$ gem install ruby-debug
Install the cheatsheet
$ gem install cheat
$ cheat rdebug
Set autolist, autoeval, and autoreload as defaults
$ vi ~/.rdebugrc
set autolist
set autoeval
set autoreload
Run Rails (or other app) via rdebug
$ rdebug script/server
Breakpoint from rdebug
(rdb:1) b app/controllers/my_controller.rb:10
Breakpoint in source
require 'ruby-debug'
debugger
my_buggy_method('foo')
Catchpoint
(rdb:1) cat RuntimeError
Continue to breakpoint
(rdb:1) c
Next Line (Step Over)
(rdb:1) n
Step Into
(rdb:1) s
Continue
(rdb:1) c
Where (Display Frame / Call Stack)
(rdb:1) where
List current line
(rdb:1) l=
Evaluate any var or expression
(rdb:1) myvar.class
Modify a var
(rdb:1) @myvar = 'foo'
Help
(rdb:1) h
There are many other commands, but these are the basics you need to poke around. Check the Cheat sheet for details.
This can also be used directly from any IDE that supports input into a running console (such as Intellij Idea).
That should get you started. So, before you stick in another ‘p’ to debug, try out ruby-debug instead!
About the Author