Rubykaigi 2010 present part4 - rocky/rb-threadframe GitHub Wiki
We saw in the new debugger that I can set breakpoints at specific offsets in instruction sequences. Of course people want to refer to locations by a file name and a line number or a method name. So I need to be able to find the associated instruction sequences.
To enable a debugger to do this, I do something analogous to the constant in Ruby SCRIPT_LINES__
which captures source-code lines.
If constant ISEQS__
is defined as a hash, any new instruction sequence gets added to that hash. The key is the instruction sequence name. So again this is why it is helpful to change the instruction sequence name from ‘top required’ to something more unique.
Let me show how ISEQ__ works.
$ irb # From before
>> require 'thread_frame'
>> ISEQS__ = {}
=> {"irb_binding"=>[<RubyVM::InstructionSequence:irb_binding@/usr/local/lib/ruby/1.9.1/irb/workspace.rb>]}
>> def five; 5 end
=> nil
>> ISEQS__['five']
=> [<RubyVM::InstructionSequence:five@(irb)>]
>> puts ISEQS__['five'][0].disasm
== disasm: <RubyVM::InstructionSequence:five@(irb)>=====================
0000 trace 8 ( 3)
0002 trace 1
0004 putobject 5
0006 trace 16
0008 leave
=> nil
>>