summaryrefslogtreecommitdiff
path: root/misc/lldb_rb/rb_base_command.py
diff options
context:
space:
mode:
authorMatt Valentine-House <[email protected]>2022-07-13 18:14:44 +0100
committerPeter Zhu <[email protected]>2022-08-18 13:25:32 -0400
commitb26aec9daa03a4f3da225e9e4f7a43e916928712 (patch)
treeb2002f074b354f743f701b28d3c080d2ec70f5f8 /misc/lldb_rb/rb_base_command.py
parenta4ef2f16728b4b1eb49cc3aded26219cabdfa7e7 (diff)
[ci-skip][Feature #18910][lldb] New directory structure
Push the newly refactored lldb files into a sub-directory so that we're not cluttering up the misc directory
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6129
Diffstat (limited to 'misc/lldb_rb/rb_base_command.py')
-rw-r--r--misc/lldb_rb/rb_base_command.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/misc/lldb_rb/rb_base_command.py b/misc/lldb_rb/rb_base_command.py
new file mode 100644
index 0000000000..44b2996d80
--- /dev/null
+++ b/misc/lldb_rb/rb_base_command.py
@@ -0,0 +1,68 @@
+import lldb
+from pydoc import locate
+
+class RbBaseCommand:
+ @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)
+
+ def __init__(self, debugger, _internal_dict):
+ self.internal_dict = _internal_dict
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ if not ("RUBY_Qfalse" in globals()):
+ self._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
+
+ def build_environment(self, debugger):
+ self.target = debugger.GetSelectedTarget()
+ self.process = self.target.GetProcess()
+ self.thread = self.process.GetSelectedThread()
+ self.frame = self.thread.GetSelectedFrame()
+
+ def _append_command_output(self, debugger, command, result):
+ output1 = result.GetOutput()
+ debugger.GetCommandInterpreter().HandleCommand(command, result)
+ output2 = result.GetOutput()
+ result.Clear()
+ result.write(output1)
+ result.write(output2)
+
+ def _lldb_init(self, 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