mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add a helper script for ujit disasm
This commit is contained in:
parent
d9176d9fca
commit
11512a80fc
1 changed files with 34 additions and 0 deletions
34
misc/ujit_disasm.rb
Normal file
34
misc/ujit_disasm.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
begin
|
||||
require "crabstone"
|
||||
require "stringio"
|
||||
|
||||
module UJIT
|
||||
def self.disasm(iseq)
|
||||
blocks = UJIT.blocks_for(iseq)
|
||||
return if blocks.empty?
|
||||
|
||||
io = StringIO.new
|
||||
|
||||
cs = Crabstone::Disassembler.new(Crabstone::ARCH_X86, Crabstone::MODE_64)
|
||||
|
||||
io.puts iseq.disasm
|
||||
|
||||
blocks.sort_by(&:address).reverse.each do |block|
|
||||
io.puts "== ISEQ RANGE: #{block.iseq_start_index} -> #{block.iseq_end_index} ".ljust(80, "=")
|
||||
cs.disasm(block.code, 0).each do |i|
|
||||
io.printf(
|
||||
"\t0x%<address>x:\t%<instruction>s\t%<details>s\n",
|
||||
address: i.address,
|
||||
instruction: i.mnemonic,
|
||||
details: i.op_str
|
||||
)
|
||||
end
|
||||
end
|
||||
io.string
|
||||
end
|
||||
end
|
||||
rescue
|
||||
puts "Please install crabstone like this:"
|
||||
puts " $ brew install capstone"
|
||||
puts " $ gem install capstone"
|
||||
end
|
Loading…
Reference in a new issue