Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Debugger API

Ruby Debugger API

Ruby Debugger API overview with

Avatar for Dennis Ushakov

Dennis Ushakov

November 23, 2013
Tweet

More Decks by Dennis Ushakov

Other Decks in Technology

Transcript

  1. Sample Program MAGIC_NUMBER = 10000000 ! def is_anybody_out_there? "Is anybody

    out there?" end ! def hardcore_action MAGIC_NUMBER.times { is_anybody_out_there? } end
  2. Sample Program MAGIC_NUMBER = 10000000 ! def is_anybody_out_there? "Is anybody

    out there?" end ! def hardcore_action MAGIC_NUMBER.times { is_anybody_out_there? } end 3.45s
  3. Event Types • line • call & return • c-call

    & c-return • class & end • raise • b-call & b-return — Ruby 2.0 • thread-begin & thread-end — Ruby 2.0
  4. Sample Output line debug_bench.rb:22 
 call debug_bench.rb:10 hardcore_action Object
 line

    debug_bench.rb:11 hardcore_action Object
 c-call debug_bench.rb:11 times Integer
 line debug_bench.rb:11 hardcore_action Object
 call debug_bench.rb:6 is_anybody_out_there? Object
 line debug_bench.rb:7 is_anybody_out_there? Object
 return debug_bench.rb:8 is_anybody_out_there? Object
 c-return debug_bench.rb:11 times Integer
 return debug_bench.rb:12 hardcore_action Object
 line debug_bench.rb:23
  5. Sample Output line debug_bench.rb:22 
 call debug_bench.rb:10 hardcore_action Object
 line

    debug_bench.rb:11 hardcore_action Object
 c-call debug_bench.rb:11 times Integer
 line debug_bench.rb:11 hardcore_action Object
 call debug_bench.rb:6 is_anybody_out_there? Object
 line debug_bench.rb:7 is_anybody_out_there? Object
 return debug_bench.rb:8 is_anybody_out_there? Object
 c-return debug_bench.rb:11 times Integer
 return debug_bench.rb:12 hardcore_action Object
 line debug_bench.rb:23 61.73s
  6. event_hook gem • If there’s a C API there should

    be a wrapper gem for it • Well, no
  7. Performance summary • run 3.45s • set_trace_func 61.73s • binding

    58.33s • rb_add_event_hook • Ruby callback 31.46s • C callback 6.48s • TracePoint 18.27s
  8. debug_inspector gem • If there’s a C API there should

    be a wrapper gem for it that’s obsolete • Well, no
  9. debug_inspector gem RubyVM::DebugInspector.open { |dc|
 locations = dc.backtrace_locations
 locations.size.times do

    |i|
 p dc.frame_binding(i)
 p dc.frame_iseq(i)
 p dc.frame_class(i)
 end
 }
  10. line te.rb:9 call te.rb:5 m1
 9 if m1 line te.rb:5

    m1
 10 1 return te.rb:5 m1 
 11 elsif m2 call te.rb:6 m2
 12 2 line te.rb:6 m2
 13 end return te.rb:6 m2
 line te.rb:12 Catch me if you can
  11. JRuby • org.jruby.runtime.EventHook • public boolean isInterestedInEvent(RubyEvent event) • public

    void eventHandler(
 ThreadContext tCtx, 
 String event, 
 String file, int line, 
 String methodName, 
 IRubyObject klass
 )