1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Expose instruction information for debuggers [Feature #18026]

This commit is contained in:
Nobuyoshi Nakada 2021-07-07 12:22:40 +09:00 committed by Aaron Patterson
parent aa2a1fb047
commit b44c5187b4
Notes: git 2021-10-05 01:43:31 +09:00
3 changed files with 58 additions and 38 deletions

View file

@ -7,15 +7,22 @@
%# details.
CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn)));
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(', ') -%>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_len_info);
#endif
int
insn_len(VALUE i)
{
static const char t[] = {
% RubyVM::Instructions.each_slice 23 do |a|
<%= a.map(&:width).join(', ') -%>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(t);
return t[i];
return rb_vm_insn_len_info[i];
}

View file

@ -13,26 +13,32 @@
%
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 %>;
const char rb_vm_insn_name_base[] =
% a.each do |i|
<%=cstr i%> "\0"
% end
;
const unsigned short rb_vm_insn_name_offset[] = {
% c.each_slice 12 do |d|
<%= d.map {|i| sprintf("%4d", i) }.join(', ') %>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_name_offset);
#endif
const char *
insn_name(VALUE i)
{
static const char x[] =
% a.each do |i|
<%=cstr i%> "\0"
% end
;
static const unsigned short y[] = {
% c.each_slice 12 do |d|
<%= d.map {|i| sprintf("%4d", i) }.join(', ') %>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(y);
return &x[y[i]];
return &rb_vm_insn_name_base[rb_vm_insn_name_offset[i]];
}

View file

@ -14,24 +14,31 @@
CONSTFUNC(MAYBE_UNUSED(static const char *insn_op_types(VALUE insn)));
CONSTFUNC(MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos)));
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"
% end
;
const unsigned short rb_vm_insn_op_offset[] = {
% c.each_slice 12 do |d|
<%= d.map {|i| sprintf("%3d", i) }.join(', ') %>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_op_offset);
#endif
const char *
insn_op_types(VALUE i)
{
static const char x[] =
% a.each_slice 5 do |d|
<%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(' "\0" ') %> "\0"
% end
;
static const unsigned short y[] = {
% c.each_slice 12 do |d|
<%= d.map {|i| sprintf("%3d", i) }.join(', ') %>,
% end
};
ASSERT_VM_INSTRUCTION_SIZE(y);
return &x[y[i]];
return &rb_vm_insn_op_base[rb_vm_insn_op_offset[i]];
}
int