Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify
ISeq#disasm
to provide the location as well as the default a…
…rgument part. When you debug a method with default arguments, such as this, ```ruby def f(a = 1, b = 2) 3 end ``` you'd like to see where the method body starts at the ISeq. `ISeq#disasm`, `ISeq#disassemble`, and `ruby --dump=insns` provide this ``` == disasm: #<ISeq:<main>@/tmp/vlDkYWS/294:1 (1,0)-(4,3)> (catch: FALSE) 0000 putspecialobject 1 ( 2)[Li] 0002 putobject :f 0004 putiseq f 0006 opt_send_without_block <callinfo!mid:core#define_method, argc:2, ARGS_SIMPLE>, <callcache> 0009 leave == disasm: #<ISeq:f@/tmp/vlDkYWS/294:2 (2,0)-(4,3)> (catch: FALSE) local table (size: 2, argc: 0 [opts: 2, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 2] a@0<Opt=0> [ 1] b@1<Opt=3> 0000 putobject_INT2FIX_1_ ( 2) 0001 setlocal_WC_0 a@0 0003 putobject 2 0005 setlocal_WC_0 b@1 0007 putobject 3 ( 3)[LiCa] 0009 leave ( 4)[Re] ``` However this does not explain where the method body (in this case `0007 putobject 3`) starts. (Note that `ISeq#to_a` provides where it starts. See `:label_7` below) ``` ["YARVInstructionSequence/SimpleDataFormat", 2, 6, 1, {:arg_size=>2, :local_size=>2, :stack_max=>1, :node_id=>8, :code_location=>[1, 0, 3, 3]}, "f", "<compiled>", "<compiled>", 1, :method, [:a, :b], {:opt=>[:label_0, :label_3, :label_7]}, [], [:label_0, 1, [:putobject_INT2FIX_1_], [:setlocal_WC_0, 4], :label_3, [:putobject, 2], [:setlocal_WC_0, 3], :label_7, 2, :RUBY_EVENT_LINE, :RUBY_EVENT_CALL, [:putobject, 3], 3, :RUBY_EVENT_RETURN, [:leave]]] ``` Modify `ISeq#disasm` to provide the location as well as the default argument part. * before: ` [ 2] a@0<Opt=0> [ 1] b@1<Opt=3>` * after: `[ 2] a@0<Opt=0> [ 1] b@1<Opt=3> [ 0] <Opt=7>` for ``` == disasm: #<ISeq:f@/tmp/vlDkYWS/298:2 (2,0)-(4,3)> (catch: FALSE) local table (size: 2, argc: 0 [opts: 2, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 2] a@0<Opt=0> [ 1] b@1<Opt=3> [ 0] <Opt=7> 0000 putobject_INT2FIX_1_ ( 2) 0001 setlocal_WC_0 a@0 0003 putobject 2 0005 setlocal_WC_0 b@1 0007 putobject 3 ( 3)[LiCa] 0009 leave ( 4)[Re] ```
- Loading branch information