summaryrefslogtreecommitdiff
path: root/misc/lldb_rb
diff options
context:
space:
mode:
Diffstat (limited to 'misc/lldb_rb')
-rw-r--r--misc/lldb_rb/commands/command_template.py30
-rw-r--r--misc/lldb_rb/commands/heap_page_command.py26
-rw-r--r--misc/lldb_rb/commands/print_flags_command.py31
-rw-r--r--misc/lldb_rb/commands/rb_id2str_command.py49
-rw-r--r--misc/lldb_rb/commands/rclass_ext_command.py14
-rw-r--r--misc/lldb_rb/commands/rp_command.py15
-rw-r--r--misc/lldb_rb/constants.py6
-rw-r--r--misc/lldb_rb/lldb_interface.py7
-rw-r--r--misc/lldb_rb/rb_base_command.py57
-rw-r--r--misc/lldb_rb/rb_heap_structs.py143
-rw-r--r--misc/lldb_rb/utils.py494
11 files changed, 872 insertions, 0 deletions
diff --git a/misc/lldb_rb/commands/command_template.py b/misc/lldb_rb/commands/command_template.py
new file mode 100644
index 0000000000..21014a993e
--- /dev/null
+++ b/misc/lldb_rb/commands/command_template.py
@@ -0,0 +1,30 @@
+# This is a command template for implementing a helper function inside LLDB. To
+# use this file
+# 1. Copy it and rename the copy so it ends with `_command.py`.
+# 2. Rename the class to something descriptive that ends with Command.
+# 3. Change the program variable to be a descriptive command name
+# 4. Ensure you are inheriting from RbBaseCommand or another command that
+# implements the same interface
+
+import lldb
+
+from lldb_rb.constants import *
+from lldb_rb.rb_base_command import RbBaseCommand
+
+# This test command inherits from RbBaseCommand which provides access to Ruby
+# globals and utility helpers
+class TestCommand(RbBaseCommand):
+ # program is the keyword the user will type in lldb to execute this command
+ program = "test"
+
+ # help_string will be displayed in lldb when the user uses the help functions
+ help_string = "This is a test command to show how to implement lldb commands"
+
+ # call is where our command logic will be implemented
+ def call(self, debugger, command, exe_ctx, result):
+ # This method will be called once the LLDB environment has been setup.
+ # You will have access to self.target, self.process, self.frame, and
+ # self.thread
+ #
+ # This is where we should implement our command logic
+ pass
diff --git a/misc/lldb_rb/commands/heap_page_command.py b/misc/lldb_rb/commands/heap_page_command.py
new file mode 100644
index 0000000000..b56a3eae4e
--- /dev/null
+++ b/misc/lldb_rb/commands/heap_page_command.py
@@ -0,0 +1,26 @@
+import lldb
+
+from lldb_rb.constants import *
+from lldb_rb.rb_base_command import RbBaseCommand
+
+class HeapPageCommand(RbBaseCommand):
+ program = "heap_page"
+ help_string = "prints out 'struct heap_page' for a VALUE pointer in the page"
+
+ def call(self, debugger, command, exe_ctx, result):
+ self.t_heap_page_body = self.target.FindFirstType("struct heap_page_body")
+ self.t_heap_page_ptr = self.target.FindFirstType("struct heap_page").GetPointerType()
+
+ page = self._get_page(self.frame.EvaluateExpression(command))
+ page.Cast(self.t_heap_page_ptr)
+
+ self._append_expression(debugger, "(struct heap_page *) %0#x" % page.GetValueAsUnsigned(), result)
+ self._append_expression(debugger, "*(struct heap_page *) %0#x" % page.GetValueAsUnsigned(), result)
+
+ def _get_page(self, val):
+ addr = val.GetValueAsUnsigned()
+ page_addr = addr & ~(HEAP_PAGE_ALIGN_MASK)
+ address = lldb.SBAddress(page_addr, self.target)
+ body = self.target.CreateValueFromAddress("page", address, self.t_heap_page_body)
+
+ return body.GetValueForExpressionPath("->header.page")
diff --git a/misc/lldb_rb/commands/print_flags_command.py b/misc/lldb_rb/commands/print_flags_command.py
new file mode 100644
index 0000000000..00da4834bf
--- /dev/null
+++ b/misc/lldb_rb/commands/print_flags_command.py
@@ -0,0 +1,31 @@
+import lldb
+import re
+
+from lldb_rb.constants import *
+from lldb_rb.rb_base_command import RbBaseCommand
+
+class PrintFlagsCommand(RbBaseCommand):
+ program = "print_flags"
+
+ help_string = "Print out the individial flags of an RVALUE object in human readable format"
+
+ # call is where our command logic will be implemented
+ def call(self, debugger, command, exe_ctx, result):
+ rclass_t = self.target.FindFirstType("struct RBasic")
+ rcass_ptr = self.target.EvaluateExpression(command).Cast(rclass_t.GetPointerType())
+ obj_flags = rcass_ptr.GetValueForExpressionPath("->flags").GetValueAsUnsigned()
+
+ flags = [
+ "RUBY_FL_WB_PROTECTED", "RUBY_FL_PROMOTED0", "RUBY_FL_PROMOTED1", "RUBY_FL_FINALIZE",
+ "RUBY_FL_SHAREABLE", "RUBY_FL_EXIVAR", "RUBY_FL_FREEZE",
+ "RUBY_FL_USER0", "RUBY_FL_USER1", "RUBY_FL_USER2", "RUBY_FL_USER3", "RUBY_FL_USER4",
+ "RUBY_FL_USER5", "RUBY_FL_USER6", "RUBY_FL_USER7", "RUBY_FL_USER8", "RUBY_FL_USER9",
+ "RUBY_FL_USER10", "RUBY_FL_USER11", "RUBY_FL_USER12", "RUBY_FL_USER13", "RUBY_FL_USER14",
+ "RUBY_FL_USER15", "RUBY_FL_USER16", "RUBY_FL_USER17", "RUBY_FL_USER18"
+ ]
+
+ types_index = {v: k for k, v in self.ruby_globals.items() if re.match(r'RUBY_T_', k)}
+ print("TYPE: {}".format(types_index[obj_flags & self.ruby_globals["RUBY_T_MASK"]]))
+ for flag in flags:
+ output = "{} : {}".format(flag, "1" if (obj_flags & self.ruby_globals[flag]) else "0")
+ print(output, file=result)
diff --git a/misc/lldb_rb/commands/rb_id2str_command.py b/misc/lldb_rb/commands/rb_id2str_command.py
new file mode 100644
index 0000000000..6ee859ebf6
--- /dev/null
+++ b/misc/lldb_rb/commands/rb_id2str_command.py
@@ -0,0 +1,49 @@
+import lldb
+
+from lldb_rb.constants import *
+from lldb_rb.utils import *
+from lldb_rb.rb_base_command import RbBaseCommand
+
+class RbID2StrCommand(RbBaseCommand):
+ program = "rb_id2str"
+
+ help_string = "convert and print a Ruby ID to a C string and print it to the LLDB console"
+
+ def call(self, debugger, command, exe_ctx, result):
+ global_symbols = self.target.FindFirstGlobalVariable("ruby_global_symbols")
+
+ id_val = self.frame.EvaluateExpression(command).GetValueAsUnsigned()
+ num = self.rb_id_to_serial(id_val)
+
+ last_id = global_symbols.GetChildMemberWithName("last_id").GetValueAsUnsigned()
+ ID_ENTRY_SIZE = 2
+ ID_ENTRY_UNIT = int(self.target.FindFirstGlobalVariable("ID_ENTRY_UNIT").GetValue())
+
+ ids = global_symbols.GetChildMemberWithName("ids")
+
+ if num <= last_id:
+ idx = num // ID_ENTRY_UNIT
+ ary = self.rb_ary_entry(ids, idx, result)
+ pos = (num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE
+ id_str = self.rb_ary_entry(ary, pos, result)
+
+ RbInspector(debugger, result, self.ruby_globals).inspect(id_str)
+
+ def rb_id_to_serial(self, id_val):
+ if id_val > self.ruby_globals["tLAST_OP_ID"]:
+ return id_val >> self.ruby_globals["RUBY_ID_SCOPE_SHIFT"]
+ else:
+ return id_val
+
+ def rb_ary_entry(self, ary, idx, result):
+ tRArray = self.target.FindFirstType("struct RArray").GetPointerType()
+ ary = ary.Cast(tRArray)
+ flags = ary.GetValueForExpressionPath("->flags").GetValueAsUnsigned()
+
+ if flags & self.ruby_globals["RUBY_FL_USER1"]:
+ ptr = ary.GetValueForExpressionPath("->as.ary")
+ else:
+ ptr = ary.GetValueForExpressionPath("->as.heap.ptr")
+
+ ptr_addr = ptr.GetValueAsUnsigned() + (idx * ptr.GetType().GetByteSize())
+ return self.target.CreateValueFromAddress("ary_entry[%d]" % idx, lldb.SBAddress(ptr_addr, self.target), ptr.GetType().GetPointeeType())
diff --git a/misc/lldb_rb/commands/rclass_ext_command.py b/misc/lldb_rb/commands/rclass_ext_command.py
new file mode 100644
index 0000000000..8bae911457
--- /dev/null
+++ b/misc/lldb_rb/commands/rclass_ext_command.py
@@ -0,0 +1,14 @@
+from lldb_rb.rb_base_command import RbBaseCommand
+
+class RclassExtCommand(RbBaseCommand):
+ program = "rclass_ext"
+ help_string = "retrieves and prints the rb_classext_struct for the VALUE pointer passed in"
+
+ def call(self, debugger, command, exe_ctx, result):
+ uintptr_t = self.target.FindFirstType("uintptr_t")
+ rclass_t = self.target.FindFirstType("struct RClass")
+ rclass_ext_t = self.target.FindFirstType("rb_classext_t")
+
+ rclass_addr = self.target.EvaluateExpression(command).Cast(uintptr_t)
+ rclass_ext_addr = (rclass_addr.GetValueAsUnsigned() + rclass_t.GetByteSize())
+ debugger.HandleCommand("p *(rb_classext_t *)%0#x" % rclass_ext_addr)
diff --git a/misc/lldb_rb/commands/rp_command.py b/misc/lldb_rb/commands/rp_command.py
new file mode 100644
index 0000000000..06b2516d50
--- /dev/null
+++ b/misc/lldb_rb/commands/rp_command.py
@@ -0,0 +1,15 @@
+import lldb
+
+from lldb_rb.constants import *
+from lldb_rb.utils import *
+from lldb_rb.rb_base_command import RbBaseCommand
+
+class RbID2StrCommand(RbBaseCommand):
+ program = "rp"
+
+ help_string = "convert and print a Ruby ID to a C string and print it to the LLDB console"
+
+ def call(self, debugger, command, exe_ctx, result):
+ val = self.frame.EvaluateExpression(command)
+ inspector = RbInspector(debugger, result, self.ruby_globals)
+ inspector.inspect(val)
diff --git a/misc/lldb_rb/constants.py b/misc/lldb_rb/constants.py
new file mode 100644
index 0000000000..9cd56eccb0
--- /dev/null
+++ b/misc/lldb_rb/constants.py
@@ -0,0 +1,6 @@
+HEAP_PAGE_ALIGN_LOG = 16
+HEAP_PAGE_ALIGN_MASK = (~(~0 << HEAP_PAGE_ALIGN_LOG))
+HEAP_PAGE_ALIGN = (1 << HEAP_PAGE_ALIGN_LOG)
+HEAP_PAGE_SIZE = HEAP_PAGE_ALIGN
+
+IMEMO_MASK = 0x0F
diff --git a/misc/lldb_rb/lldb_interface.py b/misc/lldb_rb/lldb_interface.py
new file mode 100644
index 0000000000..785a54b3e3
--- /dev/null
+++ b/misc/lldb_rb/lldb_interface.py
@@ -0,0 +1,7 @@
+class LLDBInterface:
+ def build_environment(self, debugger):
+ self.debugger = debugger
+ self.target = debugger.GetSelectedTarget()
+ self.process = self.target.GetProcess()
+ self.thread = self.process.GetSelectedThread()
+ self.frame = self.thread.GetSelectedFrame()
diff --git a/misc/lldb_rb/rb_base_command.py b/misc/lldb_rb/rb_base_command.py
new file mode 100644
index 0000000000..70a5addd6d
--- /dev/null
+++ b/misc/lldb_rb/rb_base_command.py
@@ -0,0 +1,57 @@
+import lldb
+from pydoc import locate
+from lldb_rb.constants import *
+from lldb_rb.utils import *
+
+class RbBaseCommand(LLDBInterface):
+ @classmethod
+ def register_lldb_command(cls, debugger, module_name):
+ # Add any commands contained in this module to LLDB
+ command = f"command script add -c {module_name}.{cls.__name__} {cls.program}"
+ debugger.HandleCommand(command)
+
+ @classmethod
+ def lldb_init(cls, debugger):
+ target = debugger.GetSelectedTarget()
+ global SIZEOF_VALUE
+ SIZEOF_VALUE = target.FindFirstType("VALUE").GetByteSize()
+
+ value_types = []
+ g = globals()
+
+ imemo_types = target.FindFirstType("enum imemo_type")
+
+ #for member in imemo_types.GetEnumMembers():
+ # g[member.GetName()] = member.GetValueAsUnsigned()
+
+ for enum in target.FindFirstGlobalVariable("ruby_dummy_gdb_enums"):
+ enum = enum.GetType()
+ members = enum.GetEnumMembers()
+ for i in range(0, members.GetSize()):
+ member = members.GetTypeEnumMemberAtIndex(i)
+ name = member.GetName()
+ value = member.GetValueAsUnsigned()
+ g[name] = value
+
+ if name.startswith("RUBY_T_"):
+ value_types.append(name)
+ g["value_types"] = value_types
+ return g
+
+ def __init__(self, debugger, _internal_dict):
+ self.ruby_globals = RbBaseCommand.lldb_init(debugger)
+ self.internal_dict = _internal_dict
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ self.ruby_globals = RbBaseCommand.lldb_init(debugger)
+ self.build_environment(debugger)
+ self.call(debugger, command, exe_ctx, result)
+
+ def call(self, debugger, command, exe_ctx, result):
+ raise NotImplementedError("subclasses must implement call")
+
+ def get_short_help(self):
+ return self.__class__.help_string
+
+ def get_long_help(self):
+ return self.__class__.help_string
diff --git a/misc/lldb_rb/rb_heap_structs.py b/misc/lldb_rb/rb_heap_structs.py
new file mode 100644
index 0000000000..86b38dbbbd
--- /dev/null
+++ b/misc/lldb_rb/rb_heap_structs.py
@@ -0,0 +1,143 @@
+import lldb
+from lldb_rb.lldb_interface import LLDBInterface
+from lldb_rb.constants import *
+
+class HeapPage(LLDBInterface):
+ def __init__(self, debugger, val):
+ self.build_environment(debugger)
+ self.page_type = self.target.FindFirstType("struct heap_page").GetPointerType()
+ self.val = val
+
+ def heap_page_body(self, command, ctx, result, internal_dict):
+ process = self.target.GetProcess()
+ thread = process.GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ val = frame.EvaluateExpression(command)
+ page = self.get_page_body(val)
+ print("Page body address: ", page.GetAddress(), file=result)
+ print(page, file=result)
+
+ def get_page_body(self, val):
+ tHeapPageBody = self.target.FindFirstType("struct heap_page_body")
+ addr = val.GetValueAsUnsigned()
+ page_addr = addr & ~(HEAP_PAGE_ALIGN_MASK)
+ address = lldb.SBAddress(page_addr, self.target)
+ return self.target.CreateValueFromAddress("page", address, tHeapPageBody)
+
+ def get_page_raw(self, val):
+ body = self.get_page_body(val)
+ return body.GetValueForExpressionPath("->header.page")
+
+ def to_heap_page_struct(self):
+ pagePtr = self.get_page_raw(self.val)
+ return pagePtr.Cast(self.page_type)
+
+
+class RbObject(LLDBInterface):
+ def __init__(self, ptr, debugger, ruby_globals):
+ self.build_environment(debugger)
+ self.ruby_globals = ruby_globals
+
+ self.flUser1 = self.ruby_globals["RUBY_FL_USER1"]
+ self.flUser2 = self.ruby_globals["RUBY_FL_USER2"]
+ self.flUser3 = self.ruby_globals["RUBY_FL_USER3"]
+ self.flUser4 = self.ruby_globals["RUBY_FL_USER4"]
+ self.flUser5 = self.ruby_globals["RUBY_FL_USER5"]
+ self.flUser6 = self.ruby_globals["RUBY_FL_USER6"]
+ self.flUser7 = self.ruby_globals["RUBY_FL_USER7"]
+ self.flUser8 = self.ruby_globals["RUBY_FL_USER8"]
+ self.flUser9 = self.ruby_globals["RUBY_FL_USER9"]
+ self.flUshift = self.ruby_globals["RUBY_FL_USHIFT"]
+
+ self.tRBasic = self.target.FindFirstType("struct RBasic").GetPointerType()
+ self.tRValue = self.target.FindFirstType("struct RVALUE")
+
+ self.val = ptr.Cast(self.tRBasic)
+ self.page = HeapPage(self.debugger, self.val)
+ self.flags = self.val.GetValueForExpressionPath("->flags").GetValueAsUnsigned()
+
+ self.type = None
+ self.type_name = ""
+
+ def check_bits(self, bitmap_name, bitmap_index, bitmap_bit, v):
+ page = self.page.to_heap_page_struct()
+ bits = page.GetChildMemberWithName(bitmap_name)
+ plane = bits.GetChildAtIndex(bitmap_index).GetValueAsUnsigned()
+ if (plane & bitmap_bit) != 0:
+ return v
+ else:
+ return ' '
+
+ def dump_bits(self, result, end = "\n"):
+ tRValue = self.target.FindFirstType("struct RVALUE")
+ tUintPtr = self.target.FindFirstType("uintptr_t") # bits_t
+
+ num_in_page = (self.val.GetValueAsUnsigned() & HEAP_PAGE_ALIGN_MASK) // tRValue.GetByteSize();
+ bits_bitlength = tUintPtr.GetByteSize() * 8
+ bitmap_index = num_in_page // bits_bitlength
+ bitmap_offset = num_in_page & (bits_bitlength - 1)
+ bitmap_bit = 1 << bitmap_offset
+
+ page = self.page.to_heap_page_struct()
+ print("bits: [%s%s%s%s%s]" % (
+ self.check_bits("uncollectible_bits", bitmap_index, bitmap_bit, "L"),
+ self.check_bits("mark_bits", bitmap_index, bitmap_bit, "M"),
+ self.check_bits("pinned_bits", bitmap_index, bitmap_bit, "P"),
+ self.check_bits("marking_bits", bitmap_index, bitmap_bit, "R"),
+ self.check_bits("wb_unprotected_bits", bitmap_index, bitmap_bit, "U"),
+ ), end=end, file=result)
+
+ def promoted_p(self):
+ rbFlPromoted = self.ruby_globals["RUBY_FL_PROMOTED"]
+ return (self.flags & rbFlPromoted) == rbFlPromoted
+
+ def frozen_p(self):
+ rbFlFreeze = self.ruby_globals["RUBY_FL_FREEZE"]
+ return (self.flags & rbFlFreeze) == rbFlFreeze
+
+ def is_type(self, type_name):
+ if self.type is None:
+ flTMask = self.ruby_globals["RUBY_T_MASK"]
+ flType = self.flags & flTMask
+ self.type = flType
+
+ if self.type == self.ruby_globals[type_name]:
+ self.type_name = type_name
+ return True
+ else:
+ return False
+
+ def as_type(self, type_name):
+ return self.val.Cast(self.tRValue.GetPointerType()).GetValueForExpressionPath("->as."+type_name)
+
+ def ary_ptr(self):
+ rval = self.as_type("array")
+ if self.flags & self.ruby_globals["RUBY_FL_USER1"]:
+ ptr = rval.GetValueForExpressionPath("->as.ary")
+ else:
+ ptr = rval.GetValueForExpressionPath("->as.heap.ptr")
+ return ptr
+
+ def ary_len(self):
+ if self.flags & self.flUser1:
+ len = ((self.flags &
+ (self.flUser3 | self.flUser4 | self.flUser5 | self.flUser6 |
+ self.flUser7 | self.flUser8 | self.flUser9)
+ ) >> (self.flUshift + 3))
+ else:
+ rval = self.as_type("array")
+ len = rval.GetValueForExpressionPath("->as.heap.len").GetValueAsSigned()
+
+ return len
+
+ def bignum_len(self):
+ if self.flags & self.flUser2:
+ len = ((self.flags &
+ (self.flUser3 | self.flUser4 | self.flUser5)
+ ) >> (self.flUshift + 3))
+ else:
+ len = (self.as_type("bignum").GetValueForExpressionPath("->as.heap.len").
+ GetValueAsUnsigned())
+
+ return len
diff --git a/misc/lldb_rb/utils.py b/misc/lldb_rb/utils.py
new file mode 100644
index 0000000000..86b5bdda2d
--- /dev/null
+++ b/misc/lldb_rb/utils.py
@@ -0,0 +1,494 @@
+from lldb_rb.lldb_interface import LLDBInterface
+from lldb_rb.rb_heap_structs import HeapPage, RbObject
+from lldb_rb.constants import *
+
+class RbInspector(LLDBInterface):
+ def __init__(self, debugger, result, ruby_globals):
+ self.build_environment(debugger)
+ self.result = result
+ self.ruby_globals = ruby_globals
+
+ def _append_command_output(self, command):
+ output1 = self.result.GetOutput()
+ self.debugger.GetCommandInterpreter().HandleCommand(command, self.result)
+ output2 = self.result.GetOutput()
+ self.result.Clear()
+ self.result.write(output1)
+ self.result.write(output2)
+
+ def _append_expression(self, expression):
+ self._append_command_output("expression " + expression)
+
+ def string2cstr(self, rstring):
+ """Returns the pointer to the C-string in the given String object"""
+ if rstring.TypeIsPointerType():
+ rstring = rstring.Dereference()
+
+ flags = rstring.GetValueForExpressionPath(".basic->flags").unsigned
+ clen = int(rstring.GetValueForExpressionPath(".len").value, 0)
+ if flags & self.ruby_globals["RUBY_FL_USER1"]:
+ cptr = int(rstring.GetValueForExpressionPath(".as.heap.ptr").value, 0)
+ else:
+ cptr = int(rstring.GetValueForExpressionPath(".as.embed.ary").location, 0)
+
+ return cptr, clen
+
+ def output_string(self, rstring):
+ cptr, clen = self.string2cstr(rstring)
+ self._append_expression("*(const char (*)[%d])%0#x" % (clen, cptr))
+
+ def fixnum_p(self, x):
+ return x & self.ruby_globals["RUBY_FIXNUM_FLAG"] != 0
+
+ def flonum_p(self, x):
+ return (x & self.ruby_globals["RUBY_FLONUM_MASK"]) == self.ruby_globals["RUBY_FLONUM_FLAG"]
+
+ def static_sym_p(self, x):
+ special_shift = self.ruby_globals["RUBY_SPECIAL_SHIFT"]
+ symbol_flag = self.ruby_globals["RUBY_SYMBOL_FLAG"]
+ return (x & ~(~0 << special_shift)) == symbol_flag
+
+ def generic_inspect(self, val, rtype):
+ tRType = self.target.FindFirstType("struct %s" % rtype).GetPointerType()
+ val = val.Cast(tRType)
+ self._append_expression("*(struct %s *) %0#x" % (rtype, val.GetValueAsUnsigned()))
+
+ def inspect(self, val):
+ rbTrue = self.ruby_globals["RUBY_Qtrue"]
+ rbFalse = self.ruby_globals["RUBY_Qfalse"]
+ rbNil = self.ruby_globals["RUBY_Qnil"]
+ rbUndef = self.ruby_globals["RUBY_Qundef"]
+ rbImmediateMask = self.ruby_globals["RUBY_IMMEDIATE_MASK"]
+
+ num = val.GetValueAsSigned()
+ if num == rbFalse:
+ print('false', file=self.result)
+ elif num == rbTrue:
+ print('true', file=self.result)
+ elif num == rbNil:
+ print('nil', file=self.result)
+ elif num == rbUndef:
+ print('undef', file=self.result)
+ elif self.fixnum_p(num):
+ print(num >> 1, file=self.result)
+ elif self.flonum_p(num):
+ self._append_expression("rb_float_value(%0#x)" % val.GetValueAsUnsigned())
+ elif self.static_sym_p(num):
+ if num < 128:
+ print("T_SYMBOL: %c" % num, file=self.result)
+ else:
+ print("T_SYMBOL: (%x)" % num, file=self.result)
+ self._append_expression("rb_id2name(%0#x)" % (num >> 8))
+
+ elif num & rbImmediateMask:
+ print('immediate(%x)' % num, file=self.result)
+ else:
+ rval = RbObject(val, self.debugger, self.ruby_globals)
+ rval.dump_bits(self.result)
+
+ flaginfo = ""
+ if rval.promoted_p():
+ flaginfo += "[PROMOTED] "
+ if rval.frozen_p():
+ flaginfo += "[FROZEN] "
+
+ if rval.is_type("RUBY_T_NONE"):
+ print('T_NONE: %s%s' % (flaginfo, val.Dereference()), file=self.result)
+
+ elif rval.is_type("RUBY_T_NIL"):
+ print('T_NIL: %s%s' % (flaginfo, val.Dereference()), file=self.result)
+
+ elif rval.is_type("RUBY_T_OBJECT"):
+ self.result.write('T_OBJECT: %s' % flaginfo)
+ self._append_expression("*(struct RObject*)%0#x" % val.GetValueAsUnsigned())
+
+ elif (rval.is_type("RUBY_T_CLASS") or
+ rval.is_type("RUBY_T_MODULE") or
+ rval.is_type("RUBY_T_ICLASS")):
+ self.result.write('T_%s: %s' % (rval.type_name.split('_')[-1], flaginfo))
+ tRClass = self.target.FindFirstType("struct RClass")
+
+ self._append_expression("*(struct RClass*)%0#x" % val.GetValueAsUnsigned())
+ if not val.Cast(tRClass).GetChildMemberWithName("ptr").IsValid():
+ self._append_expression(
+ "*(struct rb_classext_struct*)%0#x" %
+ (val.GetValueAsUnsigned() + tRClass.GetByteSize())
+ )
+
+ elif rval.is_type("RUBY_T_STRING"):
+ self.result.write('T_STRING: %s' % flaginfo)
+ tRString = self.target.FindFirstType("struct RString").GetPointerType()
+
+ chilled = self.ruby_globals["RUBY_FL_USER3"]
+ if (rval.flags & chilled) != 0:
+ self.result.write("[CHILLED] ")
+
+ rb_enc_mask = self.ruby_globals["RUBY_ENCODING_MASK"]
+ rb_enc_shift = self.ruby_globals["RUBY_ENCODING_SHIFT"]
+ encidx = ((rval.flags & rb_enc_mask) >> rb_enc_shift)
+ encname = self.target.FindFirstType("enum ruby_preserved_encindex") \
+ .GetEnumMembers().GetTypeEnumMemberAtIndex(encidx) \
+ .GetName()
+
+ if encname is not None:
+ self.result.write('[%s] ' % encname[14:])
+ else:
+ self.result.write('[enc=%d] ' % encidx)
+
+ ptr, len = self.string2cstr(val.Cast(tRString))
+ if len == 0:
+ self.result.write("(empty)\n")
+ else:
+ self._append_expression("*(const char (*)[%d])%0#x" % (len, ptr))
+
+ elif rval.is_type("RUBY_T_SYMBOL"):
+ self.result.write('T_SYMBOL: %s' % flaginfo)
+ tRSymbol = self.target.FindFirstType("struct RSymbol").GetPointerType()
+ tRString = self.target.FindFirstType("struct RString").GetPointerType()
+
+ val = val.Cast(tRSymbol)
+ self._append_expression('(ID)%0#x ' % val.GetValueForExpressionPath("->id").GetValueAsUnsigned())
+ self.output_string(val.GetValueForExpressionPath("->fstr").Cast(tRString))
+
+ elif rval.is_type("RUBY_T_ARRAY"):
+ len = rval.ary_len()
+ ptr = rval.ary_ptr()
+
+ self.result.write("T_ARRAY: %slen=%d" % (flaginfo, len))
+
+ if rval.flags & self.ruby_globals["RUBY_FL_USER1"]:
+ self.result.write(" (embed)")
+ elif rval.flags & self.ruby_globals["RUBY_FL_USER2"]:
+ shared = val.GetValueForExpressionPath("->as.heap.aux.shared").GetValueAsUnsigned()
+ self.result.write(" (shared) shared=%016x" % shared)
+ else:
+ capa = val.GetValueForExpressionPath("->as.heap.aux.capa").GetValueAsSigned()
+ self.result.write(" (ownership) capa=%d" % capa)
+ if len == 0:
+ self.result.write(" {(empty)}\n")
+ else:
+ self.result.write("\n")
+ if ptr.GetValueAsSigned() == 0:
+ self._append_expression("-fx -- ((struct RArray*)%0#x)->as.ary" % val.GetValueAsUnsigned())
+ else:
+ self._append_expression("-Z %d -fx -- (const VALUE*)%0#x" % (len, ptr.GetValueAsUnsigned()))
+
+ elif rval.is_type("RUBY_T_HASH"):
+ self.result.write("T_HASH: %s" % flaginfo)
+ ptr = val.GetValueAsUnsigned()
+ self._append_expression("*(struct RHash *) %0#x" % ptr)
+ if rval.flags & self.ruby_globals["RUBY_FL_USER3"]:
+ self._append_expression("*(struct st_table *) (%0#x + sizeof(struct RHash))" % ptr)
+ else:
+ self._append_expression("*(struct ar_table *) (%0#x + sizeof(struct RHash))" % ptr)
+
+ elif rval.is_type("RUBY_T_BIGNUM"):
+ sign = '-'
+ if (rval.flags & self.ruby_globals["RUBY_FL_USER1"]) != 0:
+ sign = '+'
+ len = rval.bignum_len()
+
+ if rval.flags & self.ruby_globals["RUBY_FL_USER2"]:
+ print("T_BIGNUM: sign=%s len=%d (embed)" % (sign, len), file=self.result)
+ self._append_expression("((struct RBignum *) %0#x)->as.ary"
+ % val.GetValueAsUnsigned())
+ else:
+ print("T_BIGNUM: sign=%s len=%d" % (sign, len), file=self.result)
+ print(rval.as_type("bignum"), file=self.result)
+ self._append_expression("-Z %d -fx -- ((struct RBignum*)%d)->as.heap.digits" %
+ (len, val.GetValueAsUnsigned()))
+
+ elif rval.is_type("RUBY_T_FLOAT"):
+ self._append_expression("((struct RFloat *)%d)->float_value"
+ % val.GetValueAsUnsigned())
+
+ elif rval.is_type("RUBY_T_RATIONAL"):
+ tRRational = self.target.FindFirstType("struct RRational").GetPointerType()
+ val = val.Cast(tRRational)
+ self.inspect(val.GetValueForExpressionPath("->num"))
+ output = self.result.GetOutput()
+ self.result.Clear()
+ self.result.write("(Rational) " + output.rstrip() + " / ")
+ self.inspect(val.GetValueForExpressionPath("->den"))
+
+ elif rval.is_type("RUBY_T_COMPLEX"):
+ tRComplex = self.target.FindFirstType("struct RComplex").GetPointerType()
+ val = val.Cast(tRComplex)
+ self.inspect(val.GetValueForExpressionPath("->real"))
+ real = self.result.GetOutput().rstrip()
+ self.result.Clear()
+ self.inspect(val.GetValueForExpressionPath("->imag"))
+ imag = self.result.GetOutput().rstrip()
+ self.result.Clear()
+ if not imag.startswith("-"):
+ imag = "+" + imag
+ print("(Complex) " + real + imag + "i", file=self.result)
+
+ elif rval.is_type("RUBY_T_REGEXP"):
+ tRRegex = self.target.FindFirstType("struct RRegexp").GetPointerType()
+ val = val.Cast(tRRegex)
+ print("(Regex) ->src {", file=self.result)
+ self.inspect(val.GetValueForExpressionPath("->src"))
+ print("}", file=self.result)
+
+ elif rval.is_type("RUBY_T_DATA"):
+ tRTypedData = self.target.FindFirstType("struct RTypedData").GetPointerType()
+ val = val.Cast(tRTypedData)
+ flag = val.GetValueForExpressionPath("->typed_flag")
+
+ if flag.GetValueAsUnsigned() == 1:
+ print("T_DATA: %s" %
+ val.GetValueForExpressionPath("->type->wrap_struct_name"),
+ file=self.result)
+ self._append_expression("*(struct RTypedData *) %0#x" % val.GetValueAsUnsigned())
+ else:
+ print("T_DATA:", file=self.result)
+ self._append_expression("*(struct RData *) %0#x" % val.GetValueAsUnsigned())
+
+ elif rval.is_type("RUBY_T_NODE"):
+ tRNode = self.target.FindFirstType("struct RNode").GetPointerType()
+ rbNodeTypeMask = self.ruby_globals["RUBY_NODE_TYPEMASK"]
+ rbNodeTypeShift = self.ruby_globals["RUBY_NODE_TYPESHIFT"]
+
+ nd_type = (rval.flags & rbNodeTypeMask) >> rbNodeTypeShift
+ val = val.Cast(tRNode)
+
+ self._append_expression("(node_type) %d" % nd_type)
+
+ if nd_type == self.ruby_globals["NODE_SCOPE"]:
+ self._append_expression("*(struct RNode_SCOPE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_BLOCK"]:
+ self._append_expression("*(struct RNode_BLOCK *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_IF"]:
+ self._append_expression("*(struct RNode_IF *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_UNLESS"]:
+ self._append_expression("*(struct RNode_UNLESS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CASE"]:
+ self._append_expression("*(struct RNode_CASE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CASE2"]:
+ self._append_expression("*(struct RNode_CASE2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CASE3"]:
+ self._append_expression("*(struct RNode_CASE3 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_WHEN"]:
+ self._append_expression("*(struct RNode_WHEN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_IN"]:
+ self._append_expression("*(struct RNode_IN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_WHILE"]:
+ self._append_expression("*(struct RNode_WHILE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_UNTIL"]:
+ self._append_expression("*(struct RNode_UNTIL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ITER"]:
+ self._append_expression("*(struct RNode_ITER *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FOR"]:
+ self._append_expression("*(struct RNode_FOR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FOR_MASGN"]:
+ self._append_expression("*(struct RNode_FOR_MASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_BREAK"]:
+ self._append_expression("*(struct RNode_BREAK *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_NEXT"]:
+ self._append_expression("*(struct RNode_NEXT *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_REDO"]:
+ self._append_expression("*(struct RNode_REDO *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_RETRY"]:
+ self._append_expression("*(struct RNode_RETRY *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_BEGIN"]:
+ self._append_expression("*(struct RNode_BEGIN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_RESCUE"]:
+ self._append_expression("*(struct RNode_RESCUE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_RESBODY"]:
+ self._append_expression("*(struct RNode_RESBODY *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ENSURE"]:
+ self._append_expression("*(struct RNode_ENSURE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_AND"]:
+ self._append_expression("*(struct RNode_AND *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OR"]:
+ self._append_expression("*(struct RNode_OR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_MASGN"]:
+ self._append_expression("*(struct RNode_MASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_LASGN"]:
+ self._append_expression("*(struct RNode_LASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DASGN"]:
+ self._append_expression("*(struct RNode_DASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_GASGN"]:
+ self._append_expression("*(struct RNode_GASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_IASGN"]:
+ self._append_expression("*(struct RNode_IASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CDECL"]:
+ self._append_expression("*(struct RNode_CDECL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CVASGN"]:
+ self._append_expression("*(struct RNode_CVASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OP_ASGN1"]:
+ self._append_expression("*(struct RNode_OP_ASGN1 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OP_ASGN2"]:
+ self._append_expression("*(struct RNode_OP_ASGN2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OP_ASGN_AND"]:
+ self._append_expression("*(struct RNode_OP_ASGN_AND *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OP_ASGN_OR"]:
+ self._append_expression("*(struct RNode_OP_ASGN_OR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OP_CDECL"]:
+ self._append_expression("*(struct RNode_OP_CDECL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CALL"]:
+ self._append_expression("*(struct RNode_CALL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OPCALL"]:
+ self._append_expression("*(struct RNode_OPCALL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FCALL"]:
+ self._append_expression("*(struct RNode_FCALL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_VCALL"]:
+ self._append_expression("*(struct RNode_VCALL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_QCALL"]:
+ self._append_expression("*(struct RNode_QCALL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_SUPER"]:
+ self._append_expression("*(struct RNode_SUPER *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ZSUPER"]:
+ self._append_expression("*(struct RNode_ZSUPER *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_LIST"]:
+ self._append_expression("*(struct RNode_LIST *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ZLIST"]:
+ self._append_expression("*(struct RNode_ZLIST *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_HASH"]:
+ self._append_expression("*(struct RNode_HASH *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_RETURN"]:
+ self._append_expression("*(struct RNode_RETURN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_YIELD"]:
+ self._append_expression("*(struct RNode_YIELD *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_LVAR"]:
+ self._append_expression("*(struct RNode_LVAR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DVAR"]:
+ self._append_expression("*(struct RNode_DVAR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_GVAR"]:
+ self._append_expression("*(struct RNode_GVAR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CONST"]:
+ self._append_expression("*(struct RNode_CONST *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CVAR"]:
+ self._append_expression("*(struct RNode_CVAR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_NTH_REF"]:
+ self._append_expression("*(struct RNode_NTH_REF *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_BACK_REF"]:
+ self._append_expression("*(struct RNode_BACK_REF *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_MATCH"]:
+ self._append_expression("*(struct RNode_MATCH *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_MATCH2"]:
+ self._append_expression("*(struct RNode_MATCH2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_MATCH3"]:
+ self._append_expression("*(struct RNode_MATCH3 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_STR"]:
+ self._append_expression("*(struct RNode_STR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DSTR"]:
+ self._append_expression("*(struct RNode_DSTR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_XSTR"]:
+ self._append_expression("*(struct RNode_XSTR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DXSTR"]:
+ self._append_expression("*(struct RNode_DXSTR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_EVSTR"]:
+ self._append_expression("*(struct RNode_EVSTR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_REGX"]:
+ self._append_expression("*(struct RNode_REGX *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DREGX"]:
+ self._append_expression("*(struct RNode_DREGX *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ONCE"]:
+ self._append_expression("*(struct RNode_ONCE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ARGS"]:
+ self._append_expression("*(struct RNode_ARGS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ARGS_AUX"]:
+ self._append_expression("*(struct RNode_ARGS_AUX *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_OPT_ARG"]:
+ self._append_expression("*(struct RNode_OPT_ARG *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_KW_ARG"]:
+ self._append_expression("*(struct RNode_KW_ARG *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_POSTARG"]:
+ self._append_expression("*(struct RNode_POSTARG *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ARGSCAT"]:
+ self._append_expression("*(struct RNode_ARGSCAT *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ARGSPUSH"]:
+ self._append_expression("*(struct RNode_ARGSPUSH *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_SPLAT"]:
+ self._append_expression("*(struct RNode_SPLAT *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DEFN"]:
+ self._append_expression("*(struct RNode_DEFN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DEFS"]:
+ self._append_expression("*(struct RNode_DEFS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ALIAS"]:
+ self._append_expression("*(struct RNode_ALIAS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_VALIAS"]:
+ self._append_expression("*(struct RNode_VALIAS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_UNDEF"]:
+ self._append_expression("*(struct RNode_UNDEF *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_CLASS"]:
+ self._append_expression("*(struct RNode_CLASS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_MODULE"]:
+ self._append_expression("*(struct RNode_MODULE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_SCLASS"]:
+ self._append_expression("*(struct RNode_SCLASS *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_COLON2"]:
+ self._append_expression("*(struct RNode_COLON2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_COLON3"]:
+ self._append_expression("*(struct RNode_COLON3 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DOT2"]:
+ self._append_expression("*(struct RNode_DOT2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DOT3"]:
+ self._append_expression("*(struct RNode_DOT3 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FLIP2"]:
+ self._append_expression("*(struct RNode_FLIP2 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FLIP3"]:
+ self._append_expression("*(struct RNode_FLIP3 *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_SELF"]:
+ self._append_expression("*(struct RNode_SELF *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_NIL"]:
+ self._append_expression("*(struct RNode_NIL *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_TRUE"]:
+ self._append_expression("*(struct RNode_TRUE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FALSE"]:
+ self._append_expression("*(struct RNode_FALSE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ERRINFO"]:
+ self._append_expression("*(struct RNode_ERRINFO *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DEFINED"]:
+ self._append_expression("*(struct RNode_DEFINED *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_POSTEXE"]:
+ self._append_expression("*(struct RNode_POSTEXE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_DSYM"]:
+ self._append_expression("*(struct RNode_DSYM *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ATTRASGN"]:
+ self._append_expression("*(struct RNode_ATTRASGN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_LAMBDA"]:
+ self._append_expression("*(struct RNode_LAMBDA *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ARYPTN"]:
+ self._append_expression("*(struct RNode_ARYPTN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_HSHPTN"]:
+ self._append_expression("*(struct RNode_HSHPTN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FNDPTN"]:
+ self._append_expression("*(struct RNode_FNDPTN *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_ERROR"]:
+ self._append_expression("*(struct RNode_ERROR *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_LINE"]:
+ self._append_expression("*(struct RNode_LINE *) %0#x" % val.GetValueAsUnsigned())
+ elif nd_type == self.ruby_globals["NODE_FILE"]:
+ self._append_expression("*(struct RNode_FILE *) %0#x" % val.GetValueAsUnsigned())
+ else:
+ self._append_expression("*(struct RNode *) %0#x" % val.GetValueAsUnsigned())
+
+ elif rval.is_type("RUBY_T_IMEMO"):
+ imemo_type = ((rval.flags >> self.ruby_globals["RUBY_FL_USHIFT"])
+ & IMEMO_MASK)
+ print("T_IMEMO: ", file=self.result)
+
+ self._append_expression("(enum imemo_type) %d" % imemo_type)
+ self._append_expression("*(struct MEMO *) %0#x" % val.GetValueAsUnsigned())
+
+ elif rval.is_type("RUBY_T_FILE"):
+ self.generic_inspect(val, "RFile")
+
+ elif rval.is_type("RUBY_T_MOVED"):
+ self.generic_inspect(val, "RMoved")
+
+ elif rval.is_type("RUBY_T_MATCH"):
+ self.generic_inspect(val, "RMatch")
+
+ elif rval.is_type("RUBY_T_STRUCT"):
+ self.generic_inspect(val, "RStruct")
+
+ elif rval.is_type("RUBY_T_ZOMBIE"):
+ self.generic_inspect(val, "RZombie")
+
+ else:
+ print("Not-handled type %0#x" % rval.type, file=self.result)
+ print(val, file=self.result)