debugging with pry

29
Debugging with pry Murilo Capanema - 2015

Upload: bankfacil

Post on 28-Jul-2015

220 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Debugging with pry

Debugging with pry

Murilo Capanema - 2015

Page 2: Debugging with pry

Who Am I?GitHub: mcapanema

BankFacil (We are Hiring!)

Murilo Capanema - 2015

Page 3: Debugging with pry

What is pry ?Pry is a powerful alternative to the standard IRB shell for Ruby.

Murilo Capanema - 2015

Page 4: Debugging with pry

Why pry ?Features:

4 syntax highlighting;

4 flexible plugin architecture;

4 runtime invocation and source and documentation browsing;

Murilo Capanema - 2015

Page 5: Debugging with pry

Why not to use pry ?

Murilo Capanema - 2015

Page 6: Debugging with pry

Murilo Capanema - 2015

Page 7: Debugging with pry

What really is pry ?One line of ruby:

def repl loop{ puts eval $stdin.readline}end

Murilo Capanema - 2015

Page 8: Debugging with pry

A little bit of REPLReadEvalPrintLoop

Murilo Capanema - 2015

Page 9: Debugging with pry

A little bit of REPLREPL with Tests

4 REPL first !;

4 Record what the code should do ";

4 Write a code that works first time #;

Murilo Capanema - 2015

Page 10: Debugging with pry

Why REPL ?REPL or Debugger Driven Development helps you to reach a code that works pretty quickly

Murilo Capanema - 2015

Page 11: Debugging with pry

Backing to pryrequire 'pry'binding.pry

Murilo Capanema - 2015

Page 12: Debugging with pry

Pry and his friends4 pry-stack-explorer;

4 pry-debugger;

4 pry-rescue;

4 pry-doc;

4 pry-git;

4 helpMurilo Capanema - 2015

Page 13: Debugging with pry

Pry magicsls

[1] pry(main)> lsself.methods: inspect to_slocals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_[2] pry(main)>

Murilo Capanema - 2015

Page 14: Debugging with pry

Pry magicsls

[1] pry(main)> ls Kernelconstants: RUBYGEMS_ACTIVATION_MONITORKernel.methods: Array Rational abort block_given? exit global_variables open putc require sprintf trace_var Complex String ap caller exit! iterator? p puts require_relative srand trap Float __callee__ at_exit caller_locations fail lambda pp raise select syscall untrace_var Hash __dir__ autoload catch fork load print rand set_trace_func system warn Integer __method__ autoload? eval format local_variables printf readline sleep test Pathname ` binding exec gets loop proc readlines spawn throwKernel#methods: !~ clone frozen? kind_of? public_methods tainted? <=> debugger hash method public_send tap === define_singleton_method inspect methods remove_instance_variable to_enum =~ display instance_of? nil? respond_to? to_s ai dup instance_variable_defined? object_id send trust awesome_inspect enum_for instance_variable_get pretty_inspect singleton_class untaint awesome_print eql? instance_variable_set private_methods singleton_method untrust byebug extend instance_variables protected_methods singleton_methods untrusted? class freeze is_a? public_method taint[2] pry(main)>

Murilo Capanema - 2015

Page 15: Debugging with pry

Pry magics$ - show-source

[1] pry(main)> $ Kernel#puts

From: io.c (C Method):Owner: KernelVisibility: privateNumber of lines: 8

static VALUErb_f_puts(argc, argv) int argc; VALUE *argv;{ rb_io_puts(argc, argv, rb_stdout); return Qnil;}[2] pry(main)>

Murilo Capanema - 2015

Page 16: Debugging with pry

Pry magics$ - show-source

[1] pry(main)> $ Hash

From: /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/pp.rb @ line 369:Class name: HashNumber of lines: 9

class Hash # :nodoc: def pretty_print(q) # :nodoc: q.pp_hash self end

def pretty_print_cycle(q) # :nodoc: q.text(empty? ? '{}' : '{...}') endend[2] pry(main)>

Murilo Capanema - 2015

Page 17: Debugging with pry

Pry magics? - show-doc

[1] pry(main)> ? Object

From: /home/vagrant/.rvm/gems/ruby-2.1.3/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/object.rb @ line 1:Class name: ObjectNumber of monkeypatches: 6. Use the `-a` option to display all available monkeypatchesNumber of lines: 5.........[2] pry(main)>

Murilo Capanema - 2015

Page 18: Debugging with pry

Pry magicsbreak

[1] pry(main)> break method_nameBreakpoint 1: /path/to/file.rb @ line 1 (Enabled):.........[2] pry(main)>

Murilo Capanema - 2015

Page 19: Debugging with pry

Pry magicstry-again

[1] pry(main)> try-again[2] pry(main)>

Murilo Capanema - 2015

Page 20: Debugging with pry

Pry magicsstep/next

[1] pry(main)> step[2] pry(main)> next

Murilo Capanema - 2015

Page 21: Debugging with pry

Pry magicsplay

[1] pry(main)> play -l 1[2] pry(main)>

Murilo Capanema - 2015

Page 22: Debugging with pry

Pry magicsedit [OPTIONS]

4 -e Open editor on last exception raised

4 -m Open editor on a given method

4 -c Open editor on current method

[1] pry(main)> edit -m method_name[2] pry(main)>

Murilo Capanema - 2015

Page 23: Debugging with pry

Pry magicsup

[1] pry(main)> up[2] pry(main)>

Murilo Capanema - 2015

Page 24: Debugging with pry

Pry magicsdown

[1] pry(main)> down[2] pry(main)>

Murilo Capanema - 2015

Page 25: Debugging with pry

Pry magics@ - whereami

[1] pry(Kernel):1> cd Kernel#puts[2] pry(Kernel):2> @Inside Kernel.[3] pry(Kernel):2>

Murilo Capanema - 2015

Page 26: Debugging with pry

Debugging4 Reproduce locally;

4 Find the problem;

4 Fix it;

Murilo Capanema - 2015

Page 27: Debugging with pry

More pry magicswtf - _ex_.backtrace

[1] pry(Kernel):1> wtf?.........[2] pry(Kernel):2>

Murilo Capanema - 2015

Page 28: Debugging with pry

Further Readinghttps://www.youtube.com/watch?v=D9j_Mf91M0Ihttps://www.youtube.com/watch?v=4hfMUP5iTq8https://github.com/nixme/jazz_handshttp://pryrepl.org/

Murilo Capanema - 2015

Page 29: Debugging with pry

FinGitHub: mcapanema

Seriously We are Hiring!

Murilo Capanema - 2015