ruby-changes:68715
From: Aaron <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:33 +0900 (JST)
Subject: [ruby-changes:68715] 11512a80fc (master): add a helper script for ujit disasm
https://git.ruby-lang.org/ruby.git/commit/?id=11512a80fc From 11512a80fce8bfac3adf7038e9d9e3839e5cbbfb Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 21 Jan 2021 14:05:11 -0800 Subject: add a helper script for ujit disasm --- misc/ujit_disasm.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 misc/ujit_disasm.rb diff --git a/misc/ujit_disasm.rb b/misc/ujit_disasm.rb new file mode 100644 index 0000000000..0e54f952c9 --- /dev/null +++ b/misc/ujit_disasm.rb @@ -0,0 +1,34 @@ https://github.com/ruby/ruby/blob/trunk/misc/ujit_disasm.rb#L1 +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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/