Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify `ISeq#disasm` to provide the location as well as the default argument part. #2158

Open
wants to merge 3 commits into
base: trunk
from

Conversation

2 participants
@ujihisa
Copy link

commented Apr 29, 2019

(I re-created #2125 because it's automatically closed and I can't reopen it directly. The content is exactly same as #2125.)

When you debug a method with default arguments, such as this,

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]
@ujihisa

This comment has been minimized.

Copy link
Author

commented Apr 29, 2019

Same as #2125, I'm happy to refactor my change if it's against the @ko1's style.

Show resolved Hide resolved iseq.c Outdated
@nobu

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

I'm not sure if it is "optional".

ujihisa added some commits Apr 13, 2019

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]
```

@ujihisa ujihisa force-pushed the ujihisa:disasm2 branch from 258b8e9 to 0b8b884 May 21, 2019

@ujihisa

This comment has been minimized.

Copy link
Author

commented May 21, 2019

I'm not sure if it is "optional".

It's definitely not "Opt", so I tried naming it as "Body" at 28fa7c8 without changing the structure a lot, since I wanted to keep the structure not to abstract the internal representation too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.