Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby Debugger API
Search
Dennis Ushakov
November 23, 2013
Technology
0
130
Ruby Debugger API
Ruby Debugger API overview with
Dennis Ushakov
November 23, 2013
Tweet
Share
More Decks by Dennis Ushakov
See All by Dennis Ushakov
Ruby Debugger Internals
denofevil
1
70
RubyMine and RubyMotion
denofevil
0
50
RubyMotion #JetBrainsDay
denofevil
0
42
Get More from RubyMotion with RubyMine
denofevil
0
49
Fighting Code Smells #FrozenRails
denofevil
0
59
Other Decks in Technology
See All in Technology
今日から始めるAmazon Bedrock AgentCore
har1101
4
400
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
420
Claude_CodeでSEOを最適化する_AI_Ops_Community_Vol.2__マーケティングx_AIはここまで進化した.pdf
riku_423
2
490
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
0
330
配列に見る bash と zsh の違い
kazzpapa3
1
120
AIと新時代を切り拓く。これからのSREとメルカリIBISの挑戦
0gm
0
820
Cosmos World Foundation Model Platform for Physical AI
takmin
0
490
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
42k
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
340
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
1
130
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
130
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
320
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
72
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
Automating Front-end Workflow
addyosmani
1371
200k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Fireside Chat
paigeccino
41
3.8k
Making Projects Easy
brettharned
120
6.6k
Transcript
Ruby Debugger API Dennis Ushakov or how I stopped worrying
and wrote debugger core
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
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
set_trace_func set_trace_func proc { |event,file,line,id,binding,classname| }
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
Binding • Kernel.binding • execution context (variables, methods)
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
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
set_trace_func set_trace_func proc { |event,file,line,id,binding,classname| }
set_trace_func set_trace_func proc { |event,file,line,id,binding,classname| } 58.33s
rb_add_event_hook void rb_add_event_hook( rb_event_hook_func_t func, rb_event_flag_t events, VALUE data );
event_hook gem • If there’s a C API there should
be a wrapper gem for it • Well, no
event_hook gem • With empty processing Ruby method 31.46s •
With empty processing C method 6.48s
Ruby 2.0: moar API • TracePoint • debug_inspector
Ruby 2.0: TracePoint trace = TracePoint.new(*events) do |tp| end trace.enable
Ruby 2.0: TracePoint trace = TracePoint.new do |tp| end trace.enable
18.27s
Ruby 2.0: TracePoint trace = TracePoint.new do |tp| tp.binding end
trace.enable 70.20s
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
Under the hood • Everyone is using rb_add_event_hook
Ruby 2.0: debug_inspector VALUE rb_debug_inspector_open( rb_debug_inspector_func_t func, void *data );
debug_inspector gem • If there’s a C API there should
be a wrapper gem for it that’s obsolete • Well, no
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 }
Usages • set_trace_func • ruby -r debug.rb • rb_add_event_hook •
ruby-debug-base/debugger • rcov
Usages • TracePoint + DebugInspector • debase • byebug •
binding_of_caller
What seems to be the problem, officer?
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
That’s it
en_Dal
[email protected]
denofevil
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 )