How to observe the Ruby bytecode executed by YARV

Viewed 2517

I would like to observe the Ruby bytecode executed by YARV, post mortem.

How can I get this ?

Someone else here told it was not possible. However, there is the hotruby framework that seems to execute ruby bytecode, so I am puzzled...

Thanks a lot!

3 Answers

To get more readable output, you can use disasm after compile

[17] pry(main)> code = <<STR
[17] pry(main)* puts "Hello World"
[17] pry(main)* STR
=> "puts \"Hello World\"\n"
[19] pry(main)> puts RubyVM::InstructionSequence.compile(code).disasm
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
0000 trace            1                                               (   1)
0002 putself
0003 putstring        "Hello World"
0005 opt_send_without_block <callinfo!mid:puts, argc:1, FCALL|ARGS_SIMPLE>
0007 leave
=> nil
[20] pry(main)>
Related