4. Notch8.com Ruby Debugger
Slide No. 4
Bundler
group :test, :development do
gem "ruby-debug", :platform => :ruby_18
gem "ruby-debug19", :platform => :ruby_19
end
5. Notch8.com Ruby Debugger
Slide No. 5
Basic Usage
Starting a program in the debugger
rdebug my_file.rb
Starting with a running program
'debugger' statement
Starting the Rails server
rails server --debugger
6. Notch8.com Ruby Debugger
Slide No. 6
Debugger Commands
backtrace putl finish
delete set jump
enable tmate p
help where reload
list catch source
ps display undisplay
save exit continue
thread irb edit
var next frame
break quit kill
disable show pp
eval trace restart
info condition step
method down up
7. Notch8.com Ruby Debugger
Slide No. 7
Most Important
h[elp]
Displays the help message for an item or the list of
commands
(rdb:1) help delete
del[ete][ nnn...] delete some or all breakpoints
(rdb:1) help
Available commands:
backtrace delete enable help list ps save thread
var break disable eval info method putl set tmate
where catch display exit irb next quit show trace
condition down finish jump p reload source undisplay
continue edit frame kill pp restart step up
8. Notch8.com Ruby Debugger
Slide No. 8
Seeing
disp[lay] expression
Displays value of expression
undisp[lay] [ n]
Removes display of n
p expression
Evaluates the expression
m[ethod] i[instance] object
Displays instance methods of object
m[ethod] class| module
Displays instance methods of the class or module
9. Notch8.com Ruby Debugger
Slide No. 9
Seeing
v[ar] g[lobal]
Displays global variables
v[ar] l[ocal]
Displays local variables
v[ar] i[instance] object
Displays instance variables of object
v[ar] c[onst] object
Displays constants of object
10. Notch8.com Ruby Debugger
Slide No. 10
Moving
c[ont]
Continues execution
s[tep] [ n]
Executes next n lines stepping into methods
n[ext] [ n]
Executes next n lines stepping over methods
fin[ish]
Finishes execution of the current method
q[uit]
Exits debugger
11. Notch8.com Ruby Debugger
Slide No. 11
Where am I?
w[here]
Displays stack frame
l[ist][<-| n- m>]
Displays source lines from n to m
up [ n]
Moves up n levels in the stack frame
down [ n]
Moves down n levels in the stack frame
12. Notch8.com Ruby Debugger
Slide No. 12
There are others:
Setting and clearing breakpoints and watchpoints
Thread manipulation
13. Notch8.com Ruby Debugger
Slide No. 13
What if I'm in Passenger
Rack-debug
https://github.com/ddollar/rack-debug
Add “rack-debug” to Gemfile for development
In config/environments/development.rb
require 'rack/debug'
# for rails 2.3.x
config.middleware.use 'Rack::Debug'
# for rails 3.0.x
config.middleware.use Rack::Debug
Add “require 'rack-debug/tasks'” to Rakefile
Restart passenger
Run the listener “rake debug”
14. Notch8.com Ruby Debugger
Slide No. 14
What if I'm Using an IDE?
Ruby-debug-ide integrates with Emacs, Vim, Rubymine, etc
15. Notch8.com Ruby Debugger
Slide No. 15
Next Steps
The Rails Guide
http://guides.rubyonrails.org/debugging_rails_applications.html
Checkout Pry
http://pry.github.com/
16. Notch8.com
Slide No. 16
by
Rob Kaufman
rob@notch8.com
http://notch8.com
http://www.slideshare.net/notch8
http://speakerrate.com/notch8
@orangewolf