Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
The ultimate
guide to ruby
debugging
Rafael Rosa Fu

March 2012 - Montreal.rb

@rafaelrosafu
The ultimate
guide to ruby
debugging
Rafael Rosa Fu

March 2012 - Montreal.rb

@rafaelrosafu
Ruby debugging
basics
Rafael Rosa Fu

March 2012 - Montreal.rb

@rafaelrosafu
About me
More on that later
Why?
● TDD won't save you all the time
● Understand untested, legacy, complicated
code
● Understand unexpected behavior
● ...
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_explo...
How?
●
●
●
●

Stack traces
puts, p, pp
Logging
debug module

● ruby-debug
○ ruby-debug19
● Pry
○ pry-nav
○ pry-stack_explo...
ruby-debug
Created by Kent Sibilev and Rocky Bernstein
● https://github.com/ruby-debug/ruby-debug
● http://bashdb.sourcefo...
ruby-debug for 1.8.7
1. gem install ruby-debug
2. profit
ruby-debug for 1.9.x
1. gem install ruby-debug19
2. profit (almost)
● Workaround for 1.9.3:
○ Need newer versions for line...
ruby-debug
●
●
●
●
●
●

Follow the code execution
Inspect objects
Set breakpoints
See the stack
Change state (be careful)
...
ruby-debug demo
● Lots of commands
○
○
○
○
○
○
●

debugger, rdebug
list, help, quit
p, pp, ps, display, info
break, next, ...
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 growi...
Pry
● gem install pry
● gem install pry-doc
Pry demo
● Nice features
○
○
○
○

pagination
autocomplete
syntax highlight
highly customizable

● Lots of commands and fea...
Lessons learned
● Debugging is not a bad thing when used
properly and sparingly
● Basic tools solve ~ 90% of the issues
● ...
References - ruby-debug
● http://bashdb.sourceforge.net/ruby-debug.html
● http://railscasts.com/episodes/54-debugging-with...
References - Pry
● http://pry.github.com
● https://github.com/pry
● http://banisterfiend.wordpress.com/2012/02/14/the-pry●...
Questions

?
I just need 5 more minutes after this :)
About me

http://flagwallpapers.com/water-color-brazilian-
About me
● Coding professionally for 16 years
● Agilist, product and community guy too
● I love Ruby
"Ruby is designed to ...
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-
Ruby community in Brazil

http://blog.lambda3.com.br/2012/02/dojo-dojo-
Ruby community in Brazil

~ 1,500 attendees, this year will be the 5th edition
http://www.flickr.
Ruby community in Brazil

~ 1,500 attendees, this year will be the 5th edition
http://www.flickr.
Ruby community in Brazil

Everybody is invited - August 30 and 31 2012 - São Paulo
http://www.flickr.
Thank you
Merci :)
@rafaelrosafu
rrosa@iweb.com
rafaelrosafu@gmail.com
grokpodcast.com
linkedin.com/in/rafaelrosafu
Upcoming SlideShare
Loading in …5
×

Montreal.rb ruby debugging basics - march 20th 2012

637 views

Published on

Ruby Debugging - Presented at the Montreal.rb meeting on March 20th 2012

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Montreal.rb ruby debugging basics - march 20th 2012

  1. 1. The ultimate guide to ruby debugging Rafael Rosa Fu March 2012 - Montreal.rb @rafaelrosafu
  2. 2. The ultimate guide to ruby debugging Rafael Rosa Fu March 2012 - Montreal.rb @rafaelrosafu
  3. 3. Ruby debugging basics Rafael Rosa Fu March 2012 - Montreal.rb @rafaelrosafu
  4. 4. About me More on that later
  5. 5. Why? ● TDD won't save you all the time ● Understand untested, legacy, complicated code ● Understand unexpected behavior ● Interactive coding
  6. 6. Why? ● "When I coded in Delphi 2 I had support for it on my IDE"
  7. 7. How? ● ● ● ● Stack traces puts, p, pp Logging debug module ● ruby-debug ○ ruby-debug19 ● Pry ○ pry-nav ○ pry-stack_explorer
  8. 8. How? ● ● ● ● Stack traces puts, p, pp Logging debug module ● ruby-debug ○ ruby-debug19 ● Pry ○ pry-nav ○ pry-stack_explorer
  9. 9. ruby-debug Created 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
  10. 10. ruby-debug for 1.8.7 1. gem install ruby-debug 2. profit
  11. 11. ruby-debug for 1.9.x 1. gem install ruby-debug19 2. profit (almost) ● Workaround for 1.9.3: ○ Need newer versions for linecache and ruby-debugbase, not on rubygems ○ Some stuff is still broken ○ https://gist.github.com/2047760 ○ Thanks to @fredostarr, @spastorino, @rafaeldx7 and @garyharan
  12. 12. ruby-debug ● ● ● ● ● ● Follow the code execution Inspect objects Set breakpoints See the stack Change state (be careful) Debug remotely
  13. 13. 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
  14. 14. ruby-debug demo Live demos always go wrong Sorry in advance :)
  15. 15. Pry
  16. 16. 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
  17. 17. Pry ● gem install pry ● gem install pry-doc
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. Questions ? I just need 5 more minutes after this :)
  23. 23. About me http://flagwallpapers.com/water-color-brazilian-
  24. 24. About me ● Coding professionally for 16 years ● Agilist, product and community guy too ● I love Ruby "Ruby is designed to make programmers happy" - Matz
  25. 25. About me
  26. 26. About me
  27. 27. Ruby community in Brazil 40 to 60 people every month
  28. 28. Ruby community in Brazil https://picasaweb.google.com/105291946909431816672
  29. 29. Ruby community in Brazil https://picasaweb.google.com/105291946909431816672
  30. 30. Ruby community in Brazil http://groups.google.com/group/dojo_sp
  31. 31. Ruby community in Brazil http://pothix.com/blog/events/encontro-de-numero-5-do-guru-
  32. 32. Ruby community in Brazil http://blog.lambda3.com.br/2012/02/dojo-dojo-
  33. 33. Ruby community in Brazil ~ 1,500 attendees, this year will be the 5th edition http://www.flickr.
  34. 34. Ruby community in Brazil ~ 1,500 attendees, this year will be the 5th edition http://www.flickr.
  35. 35. Ruby community in Brazil Everybody is invited - August 30 and 31 2012 - São Paulo http://www.flickr.
  36. 36. Thank you Merci :) @rafaelrosafu rrosa@iweb.com rafaelrosafu@gmail.com grokpodcast.com linkedin.com/in/rafaelrosafu

×