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
67
RubyMine and RubyMotion
denofevil
0
48
RubyMotion #JetBrainsDay
denofevil
0
41
Get More from RubyMotion with RubyMine
denofevil
0
46
Fighting Code Smells #FrozenRails
denofevil
0
57
Other Decks in Technology
See All in Technology
From Live Coding to Vibe Coding with Firebase Studio
firebasethailand
1
290
大規模組織にAIエージェントを迅速に導入するためのセキュリティの勘所 / AI agents for large-scale organizations
i35_267
6
310
[TechNight #91] Oracle Database 最新パフォーマンス分析手法
oracle4engineer
PRO
2
120
Tiptapで実現する堅牢で柔軟なエディター開発
kirik
1
150
LLM開発を支えるエヌビディアの生成AIエコシステム
acceleratedmu3n
0
320
人と生成AIの協調意思決定/Co‑decision making by people and generative AI
moriyuya
0
120
(HackFes)米国国防総省のDevSecOpsライフサイクルをAWSのセキュリティサービスとOSSで実現
syoshie
5
680
ML Pipelineの開発と運用を OpenTelemetryで繋ぐ @ OpenTelemetry Meetup 2025-07
getty708
0
310
OTel 公式ドキュメント翻訳 PJ から始めるコミュニティ活動/Community activities starting with the OTel official document translation project
msksgm
0
290
クマ×共生 HACKATHON - 熊対策を『特別な行動」から「生活の一部」に -
pharaohkj
0
170
少人数でも回る! DevinとPlaybookで支える運用改善
ishikawa_pro
4
1.6k
RapidPen: AIエージェントによる高度なペネトレーションテスト自動化の研究開発
laysakura
1
400
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
KATA
mclloyd
30
14k
Raft: Consensus for Rubyists
vanstee
140
7k
Building Applications with DynamoDB
mza
95
6.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
BBQ
matthewcrist
89
9.7k
Documentation Writing (for coders)
carmenintech
72
4.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
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 )