summaryrefslogtreecommitdiff
path: root/misc/lldb_rb/commands
diff options
context:
space:
mode:
Diffstat (limited to 'misc/lldb_rb/commands')
-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
6 files changed, 165 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)