The ultimate guide to ruby debuggingRafael Rosa Fu @rafaelrosafu
March 2012 - Montreal.rb
The ultimate guide to ruby debuggingRafael Rosa Fu @rafaelrosafu
March 2012 - Montreal.rb
Ruby debugging basicsRafael Rosa Fu @rafaelrosafu
March 2012 - Montreal.rb
About meMore on that later
Why?● TDD won't save you all the time● Understand untested, legacy, complicated
code● Understand unexpected behavior● Interactive coding
Why?● "When I coded in Delphi 2 I had support for it
on my IDE"
How?● Stack traces● puts, p, pp● Logging● debug module
● ruby-debug○ ruby-debug19
● Pry○ pry-nav○ pry-stack_explorer
How?● Stack traces● puts, p, pp● Logging● debug module
● ruby-debug○ ruby-debug19
● Pry○ pry-nav○ pry-stack_explorer
ruby-debugCreated by Kent Sibilev and Rocky Bernstein
● https://github.com/ruby-debug/ruby-debug
● http://bashdb.sourceforge.net/ruby-debug.html
ruby-debug19 is a port by Mark Moseley
ruby-debug for 1.8.71. gem install ruby-debug
2. profit
ruby-debug for 1.9.x1. gem install ruby-debug19
2. profit (almost)
● Workaround for 1.9.3:○ Need newer versions for linecache and ruby-debug-
base, not on rubygems○ Some stuff is still broken○ https://gist.github.com/2047760○ Thanks to @fredostarr, @spastorino, @rafaeldx7
and @garyharan
ruby-debug● Follow the code execution● Inspect objects● Set breakpoints● See the stack● Change state (be careful)● Debug remotely
ruby-debug demo● Lots of commands
○ debugger, rdebug○ list, help, quit○ p, pp, ps, display, info○ break, next, step, continue○ disable, condition○ irb, where, edit, set, show
● Fingers crossed
ruby-debug demo
Live demos always go wrong
Sorry in advance :)
Pry
Pry● Developed by John Mair (@banisterfiend)
● http://github.com/pry/pry
● Started as a turbo irb
● An ecosystem is growing around it○ Lots of plugins
Pry● gem install pry
● gem install pry-doc
Pry demo● Nice features
○ pagination○ autocomplete○ syntax highlight○ highly customizable
● Lots of commands and features○ ls, ls --help○ cd, nesting, exit○ .commands○ show-doc, show-method, edit-method
● pry-nav is not ready for primetime● pry-stack_explorer is ok
Lessons learned● Debugging is not a bad thing when used
properly and sparingly● Basic tools solve ~ 90% of the issues● BDD/TDD will save you from debugging
most of the time● The future is quite cloudy for Ruby debug
tools:○ https://github.com/rocky/rb-trepanning○ Cross-implementation?○ http://blog.bithug.org/2011/09/maglev-debug
References - ruby-debug● http://bashdb.sourceforge.net/ruby-debug.html● http://railscasts.com/episodes/54-debugging-with-ruby-
debug● http://guides.rubyonrails.
org/debugging_rails_applications.html● https://github.com/ruby-debug● https://github.com/mark-moseley/ruby-debug/● https://gist.github.com/2047760
References - Pry● http://pry.github.com● https://github.com/pry● http://banisterfiend.wordpress.com/2012/02/14/the-pry-
ecosystem/● http://pry.github.com/screencasts.html
○ Special thanks to @fnando :)● http://railscasts.com/episodes/280-pry-with-rails● http://twitter.com/banisterfiend
Questions
?
I just need 5 more minutes after this :)
About me
http://flagwallpapers.com/water-color-brazilian-flag/
About me● Coding professionally for 16 years● Agilist, product and community guy too● I love Ruby
"Ruby is designed to make programmers happy"
- Matz
About me
About me
Ruby community in Brazil
40 to 60 people every month
Ruby community in Brazil
https://picasaweb.google.com/105291946909431816672
Ruby community in Brazil
https://picasaweb.google.com/105291946909431816672
Ruby community in Brazil
http://groups.google.com/group/dojo_sp
Ruby community in Brazil
http://pothix.com/blog/events/encontro-de-numero-5-do-guru-sp
Ruby community in Brazil
http://blog.lambda3.com.br/2012/02/dojo-dojo-dojo/
Ruby community in Brazil
~ 1,500 attendees, this year will be the 5th edition
http://www.flickr.com/photos/locaweb/sets/72157628091808954/
Ruby community in Brazil
~ 1,500 attendees, this year will be the 5th edition
http://www.flickr.com/photos/locaweb/sets/72157628091808954/
Ruby community in Brazil
Everybody is invited - August 30 and 31 2012 - São Paulo
http://www.flickr.com/photos/locaweb/sets/72157628091808954/
Top Related