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. %# details.
CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn))); CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn)));
int RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */
insn_len(VALUE i) extern const uint8_t rb_vm_insn_len_info[VM_INSTRUCTION_SIZE];
{ RUBY_SYMBOL_EXPORT_END
static const char t[] = {
#ifdef RUBY_VM_INSNS_INFO
const uint8_t rb_vm_insn_len_info[] = {
% RubyVM::Instructions.each_slice 23 do |a| % RubyVM::Instructions.each_slice 23 do |a|
<%= a.map(&:width).join(', ') -%>, <%= a.map(&:width).join(', ') -%>,
% end % end
}; };
ASSERT_VM_INSTRUCTION_SIZE(t); ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_len_info);
return t[i]; #endif
int
insn_len(VALUE i)
{
return rb_vm_insn_len_info[i];
} }

View file

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

View file

@ -14,24 +14,31 @@
CONSTFUNC(MAYBE_UNUSED(static const char *insn_op_types(VALUE insn))); CONSTFUNC(MAYBE_UNUSED(static const char *insn_op_types(VALUE insn)));
CONSTFUNC(MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos))); CONSTFUNC(MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos)));
const char * RUBY_SYMBOL_EXPORT_BEGIN /* for debuggers */
insn_op_types(VALUE i) extern const char rb_vm_insn_op_base[];
{ extern const unsigned short rb_vm_insn_op_offset[VM_INSTRUCTION_SIZE];
static const char x[] = RUBY_SYMBOL_EXPORT_END
#ifdef RUBY_VM_INSNS_INFO
const char rb_vm_insn_op_base[] =
% a.each_slice 5 do |d| % 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 % end
; ;
static const unsigned short y[] = { const unsigned short rb_vm_insn_op_offset[] = {
% c.each_slice 12 do |d| % c.each_slice 12 do |d|
<%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>,
% end % 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 int