ruby-changes:68247
From: Nobuyoshi <ko1@a...>
Date: Tue, 5 Oct 2021 01:43:27 +0900 (JST)
Subject: [ruby-changes:68247] b44c5187b4 (master): Expose instruction information for debuggers [Feature #18026]
https://git.ruby-lang.org/ruby.git/commit/?id=b44c5187b4 From b44c5187b4d05d8644242e532f2243210d0b74df Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 7 Jul 2021 12:22:40 +0900 Subject: Expose instruction information for debuggers [Feature #18026] --- tool/ruby_vm/views/_insn_len_info.erb | 23 +++++++++++++++-------- tool/ruby_vm/views/_insn_name_info.erb | 30 ++++++++++++++++++------------ tool/ruby_vm/views/_insn_operand_info.erb | 29 ++++++++++++++++++----------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/tool/ruby_vm/views/_insn_len_info.erb b/tool/ruby_vm/views/_insn_len_info.erb index b292f42fb5..569dca5845 100644 --- a/tool/ruby_vm/views/_insn_len_info.erb +++ b/tool/ruby_vm/views/_insn_len_info.erb @@ -7,15 +7,22 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_len_info.erb#L7 %# details. CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn))); -int -insn_len(VALUE i) -{ - static const char t[] = { +RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */ +extern const uint8_t rb_vm_insn_len_info[VM_INSTRUCTION_SIZE]; +RUBY_SYMBOL_EXPORT_END + +#ifdef RUBY_VM_INSNS_INFO +const uint8_t rb_vm_insn_len_info[] = { % RubyVM::Instructions.each_slice 23 do |a| - <%= a.map(&:width).join(', ') -%>, + <%= a.map(&:width).join(', ') -%>, % end - }; +}; - ASSERT_VM_INSTRUCTION_SIZE(t); - return t[i]; +ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_len_info); +#endif + +int +insn_len(VALUE i) +{ + return rb_vm_insn_len_info[i]; } diff --git a/tool/ruby_vm/views/_insn_name_info.erb b/tool/ruby_vm/views/_insn_name_info.erb index 767346093e..e7ded75e65 100644 --- a/tool/ruby_vm/views/_insn_name_info.erb +++ b/tool/ruby_vm/views/_insn_name_info.erb @@ -13,26 +13,32 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_name_info.erb#L13 % CONSTFUNC(MAYBE_UNUSED(static const char *insn_name(VALUE insn))); +RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */ +extern const int rb_vm_max_insn_name_size; +extern const char rb_vm_insn_name_base[]; +extern const unsigned short rb_vm_insn_name_offset[VM_INSTRUCTION_SIZE]; +RUBY_SYMBOL_EXPORT_END + #ifdef RUBY_VM_INSNS_INFO const int rb_vm_max_insn_name_size = <%= a.map(&:size).max %>; -#endif -const char * -insn_name(VALUE i) -{ - static const char x[] = +const char rb_vm_insn_name_base[] = % a.each do |i| - <%=cstr i%> "\0" + <%=cstr i%> "\0" % end - ; + ; - static const unsigned short y[] = { +const unsigned short rb_vm_insn_name_offset[] = { % c.each_slice 12 do |d| - <%= d.map {|i| sprintf("%4d", i) }.join(', ') %>, + <%= d.map {|i| sprintf("%4d", i) }.join(', ') %>, % end - }; +}; - ASSERT_VM_INSTRUCTION_SIZE(y); +ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_name_offset); +#endif - return &x[y[i]]; +const char * +insn_name(VALUE i) +{ + return &rb_vm_insn_name_base[rb_vm_insn_name_offset[i]]; } diff --git a/tool/ruby_vm/views/_insn_operand_info.erb b/tool/ruby_vm/views/_insn_operand_info.erb index 69d361521a..996c33e960 100644 --- a/tool/ruby_vm/views/_insn_operand_info.erb +++ b/tool/ruby_vm/views/_insn_operand_info.erb @@ -14,24 +14,31 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_operand_info.erb#L14 CONSTFUNC(MAYBE_UNUSED(static const char *insn_op_types(VALUE insn))); CONSTFUNC(MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos))); -const char * -insn_op_types(VALUE i) -{ - static const char x[] = +RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */ +extern const char rb_vm_insn_op_base[]; +extern const unsigned short rb_vm_insn_op_offset[VM_INSTRUCTION_SIZE]; +RUBY_SYMBOL_EXPORT_END + +#ifdef RUBY_VM_INSNS_INFO +const char rb_vm_insn_op_base[] = % a.each_slice 5 do |d| - <%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(' "\0" ') %> "\0" + <%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(' "\0" ') %> "\0" % end - ; + ; - static const unsigned short y[] = { +const unsigned short rb_vm_insn_op_offset[] = { % c.each_slice 12 do |d| - <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, + <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, % end - }; +}; - ASSERT_VM_INSTRUCTION_SIZE(y); +ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_op_offset); +#endif - return &x[y[i]]; +const char * +insn_op_types(VALUE i) +{ + return &rb_vm_insn_op_base[rb_vm_insn_op_offset[i]]; } int -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/