@@ -655,6 +655,51 @@ def ruby_types(debugger):
655655
656656 return types
657657
658+ def rb_ary_entry (target , ary , idx , result ):
659+ tRArray = target .FindFirstType ("struct RArray" ).GetPointerType ()
660+ ary = ary .Cast (tRArray )
661+ flags = ary .GetValueForExpressionPath ("->flags" ).GetValueAsUnsigned ()
662+
663+ if flags & RUBY_FL_USER1 :
664+ ptr = ary .GetValueForExpressionPath ("->as.ary" )
665+ else :
666+ ptr = ary .GetValueForExpressionPath ("->as.heap.ptr" )
667+
668+ ptr_addr = ptr .GetValueAsUnsigned () + (idx * ptr .GetType ().GetByteSize ())
669+ return target .CreateValueFromAddress ("ary_entry[%d]" % idx , lldb .SBAddress (ptr_addr , target ), ptr .GetType ().GetPointeeType ())
670+
671+ def rb_id_to_serial (id_val ):
672+ if id_val > tLAST_OP_ID :
673+ return id_val >> RUBY_ID_SCOPE_SHIFT
674+ else :
675+ return id_val
676+
677+ def rb_id2str (debugger , command , result , internal_dict ):
678+ if not ('RUBY_Qfalse' in globals ()):
679+ lldb_init (debugger )
680+
681+ target = debugger .GetSelectedTarget ()
682+ process = target .GetProcess ()
683+ thread = process .GetSelectedThread ()
684+ frame = thread .GetSelectedFrame ()
685+ global_symbols = target .FindFirstGlobalVariable ("ruby_global_symbols" )
686+
687+ id_val = frame .EvaluateExpression (command ).GetValueAsUnsigned ()
688+ num = rb_id_to_serial (id_val )
689+
690+ last_id = global_symbols .GetChildMemberWithName ("last_id" ).GetValueAsUnsigned ()
691+ ID_ENTRY_SIZE = 2
692+ ID_ENTRY_UNIT = int (target .FindFirstGlobalVariable ("ID_ENTRY_UNIT" ).GetValue ())
693+
694+ ids = global_symbols .GetChildMemberWithName ("ids" )
695+
696+ if (num <= last_id ):
697+ idx = num // ID_ENTRY_UNIT
698+ ary = rb_ary_entry (target , ids , idx , result )
699+ pos = (num % ID_ENTRY_UNIT ) * ID_ENTRY_SIZE
700+ id_str = rb_ary_entry (target , ary , pos , result )
701+ lldb_inspect (debugger , target , result , id_str )
702+
658703def __lldb_init_module (debugger , internal_dict ):
659704 debugger .HandleCommand ("command script add -f lldb_cruby.lldb_rp rp" )
660705 debugger .HandleCommand ("command script add -f lldb_cruby.count_objects rb_count_objects" )
@@ -665,6 +710,7 @@ def __lldb_init_module(debugger, internal_dict):
665710 debugger .HandleCommand ("command script add -f lldb_cruby.rb_backtrace rbbt" )
666711 debugger .HandleCommand ("command script add -f lldb_cruby.dump_page dump_page" )
667712 debugger .HandleCommand ("command script add -f lldb_cruby.dump_page_rvalue dump_page_rvalue" )
713+ debugger .HandleCommand ("command script add -f lldb_cruby.rb_id2str rb_id2str" )
668714
669715 lldb_init (debugger )
670716 print ("lldb scripts for ruby has been installed." )
0 commit comments