Montreal.rb ruby debugging basics - march 20th 2012

36
The ultimate guide to ruby debugging Rafael Rosa Fu @rafaelrosafu March 2012 - Montreal.rb

description

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

Transcript of Montreal.rb ruby debugging basics - march 20th 2012

Page 1: Montreal.rb   ruby debugging basics - march 20th 2012

The ultimate guide to ruby debuggingRafael Rosa Fu @rafaelrosafu

March 2012 - Montreal.rb

Page 2: Montreal.rb   ruby debugging basics - march 20th 2012

The ultimate guide to ruby debuggingRafael Rosa Fu @rafaelrosafu

March 2012 - Montreal.rb

Page 3: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby debugging basicsRafael Rosa Fu @rafaelrosafu

March 2012 - Montreal.rb

Page 4: Montreal.rb   ruby debugging basics - march 20th 2012

About meMore on that later

Page 5: Montreal.rb   ruby debugging basics - march 20th 2012

Why?● TDD won't save you all the time● Understand untested, legacy, complicated

code● Understand unexpected behavior● Interactive coding

Page 6: Montreal.rb   ruby debugging basics - march 20th 2012

Why?● "When I coded in Delphi 2 I had support for it

on my IDE"

Page 7: Montreal.rb   ruby debugging basics - march 20th 2012

How?● Stack traces● puts, p, pp● Logging● debug module

● ruby-debug○ ruby-debug19

● Pry○ pry-nav○ pry-stack_explorer

Page 8: Montreal.rb   ruby debugging basics - march 20th 2012

How?● Stack traces● puts, p, pp● Logging● debug module

● ruby-debug○ ruby-debug19

● Pry○ pry-nav○ pry-stack_explorer

Page 9: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 10: Montreal.rb   ruby debugging basics - march 20th 2012

ruby-debug for 1.8.71. gem install ruby-debug

2. profit

Page 11: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 12: Montreal.rb   ruby debugging basics - march 20th 2012

ruby-debug● Follow the code execution● Inspect objects● Set breakpoints● See the stack● Change state (be careful)● Debug remotely

Page 13: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 14: Montreal.rb   ruby debugging basics - march 20th 2012

ruby-debug demo

Live demos always go wrong

Sorry in advance :)

Page 15: Montreal.rb   ruby debugging basics - march 20th 2012

Pry

Page 16: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 17: Montreal.rb   ruby debugging basics - march 20th 2012

Pry● gem install pry

● gem install pry-doc

Page 18: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 19: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 20: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 21: Montreal.rb   ruby debugging basics - march 20th 2012

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

Page 22: Montreal.rb   ruby debugging basics - march 20th 2012

Questions

?

I just need 5 more minutes after this :)

Page 23: Montreal.rb   ruby debugging basics - march 20th 2012

About me

http://flagwallpapers.com/water-color-brazilian-flag/

Page 24: Montreal.rb   ruby debugging basics - march 20th 2012

About me● Coding professionally for 16 years● Agilist, product and community guy too● I love Ruby

"Ruby is designed to make programmers happy"

- Matz

Page 25: Montreal.rb   ruby debugging basics - march 20th 2012

About me

Page 26: Montreal.rb   ruby debugging basics - march 20th 2012

About me

Page 27: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

40 to 60 people every month

Page 28: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

https://picasaweb.google.com/105291946909431816672

Page 29: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

https://picasaweb.google.com/105291946909431816672

Page 30: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

http://groups.google.com/group/dojo_sp

Page 31: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

http://pothix.com/blog/events/encontro-de-numero-5-do-guru-sp

Page 32: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

http://blog.lambda3.com.br/2012/02/dojo-dojo-dojo/

Page 33: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

~ 1,500 attendees, this year will be the 5th edition

http://www.flickr.com/photos/locaweb/sets/72157628091808954/

Page 34: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

~ 1,500 attendees, this year will be the 5th edition

http://www.flickr.com/photos/locaweb/sets/72157628091808954/

Page 35: Montreal.rb   ruby debugging basics - march 20th 2012

Ruby community in Brazil

Everybody is invited - August 30 and 31 2012 - São Paulo

http://www.flickr.com/photos/locaweb/sets/72157628091808954/

Page 36: Montreal.rb   ruby debugging basics - march 20th 2012

Thank you

Merci :)

@[email protected]

[email protected]

linkedin.com/in/rafaelrosafu