From e02a355f9846d5ec9cd64b086674770ecc795c26 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Thu, 16 Feb 2023 15:15:52 -0800 Subject: [PATCH] [lldb/Plugins] Clean-up Scripted Process interface requirements (NFC) The goal of the simple patch is to clean-up the scripted process interface by removing methods that were introduced with the interface originally, but that were never really implemented (get_thread_with_id & get_registers_for_thread). This patch also changes `get_memory_region_containing_address` to have a base implementation (that retunrs `None`), instead of forcing the user to override it in their derived class. Signed-off-by: Med Ismail Bennani --- .../scripted_process/crashlog_scripted_process.py | 9 ------ .../python/scripted_process/scripted_process.py | 32 +--------------------- .../lldb/Interpreter/ScriptedProcessInterface.h | 8 ------ .../Python/ScriptedProcessPythonInterface.cpp | 19 ------------- .../Python/ScriptedProcessPythonInterface.h | 5 +--- .../scripted_process/dummy_scripted_process.py | 9 ------ .../scripted_process/invalid_scripted_process.py | 9 ------ .../stack_core_scripted_process.py | 6 ---- 8 files changed, 2 insertions(+), 95 deletions(-) diff --git a/lldb/examples/python/scripted_process/crashlog_scripted_process.py b/lldb/examples/python/scripted_process/crashlog_scripted_process.py index dfb32aa..8c32b40 100644 --- a/lldb/examples/python/scripted_process/crashlog_scripted_process.py +++ b/lldb/examples/python/scripted_process/crashlog_scripted_process.py @@ -94,15 +94,6 @@ class CrashLogScriptedProcess(ScriptedProcess): self.extended_thread_info = None self.parse_crashlog() - def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo: - return None - - def get_thread_with_id(self, tid: int): - return {} - - def get_registers_for_thread(self, tid: int): - return {} - def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: # NOTE: CrashLogs don't contain any memory. return lldb.SBData() diff --git a/lldb/examples/python/scripted_process/scripted_process.py b/lldb/examples/python/scripted_process/scripted_process.py index 8f896fc..60b65fc 100644 --- a/lldb/examples/python/scripted_process/scripted_process.py +++ b/lldb/examples/python/scripted_process/scripted_process.py @@ -58,7 +58,6 @@ class ScriptedProcess(metaclass=ABCMeta): """ return self.capabilities - @abstractmethod def get_memory_region_containing_address(self, addr): """ Get the memory region for the scripted process, containing a specific address. @@ -71,7 +70,7 @@ class ScriptedProcess(metaclass=ABCMeta): lldb.SBMemoryRegionInfo: The memory region containing the address. None if out of bounds. """ - pass + return None def get_threads_info(self): """ Get the dictionary describing the process' Scripted Threads. @@ -84,35 +83,6 @@ class ScriptedProcess(metaclass=ABCMeta): return self.threads @abstractmethod - def get_thread_with_id(self, tid): - """ Get the scripted process thread with a specific ID. - - Args: - tid (int): Thread ID to look for in the scripted process. - - Returns: - Dict: The thread represented as a dictionary, with the - tid thread ID. None if tid doesn't match any of the scripted - process threads. - """ - pass - - @abstractmethod - def get_registers_for_thread(self, tid): - """ Get the register context dictionary for a certain thread of - the scripted process. - - Args: - tid (int): Thread ID for the thread's register context. - - Returns: - Dict: The register context represented as a dictionary, for the - tid thread. None if tid doesn't match any of the scripted - process threads. - """ - pass - - @abstractmethod def read_memory_at_address(self, addr, size, error): """ Get a memory buffer from the scripted process at a certain address, of a certain size. diff --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h index 1fdac76..ec0d7de 100644 --- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h +++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h @@ -50,14 +50,6 @@ public: virtual StructuredData::DictionarySP GetThreadsInfo() { return {}; } - virtual StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) { - return {}; - } - - virtual StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) { - return {}; - } - virtual lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size, Status &error) { return {}; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp index c231828..3ca4664 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp @@ -122,25 +122,6 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() { return dict; } -StructuredData::DictionarySP -ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) { - Status error; - StructuredData::ObjectSP obj = Dispatch("get_thread_with_id", error, tid); - - if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error)) - return {}; - - StructuredData::DictionarySP dict{obj->GetAsDictionary()}; - - return dict; -} - -StructuredData::DictionarySP -ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) { - // TODO: Implement - return {}; -} - lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress( lldb::addr_t address, size_t size, Status &error) { Status py_error; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h index 076ac37..44273f1 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h @@ -47,12 +47,9 @@ public: StructuredData::DictionarySP GetThreadsInfo() override; - StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override; - - StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override; - lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size, Status &error) override; + StructuredData::ArraySP GetLoadedImages() override; diff --git a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py index 9466411..4703814 100644 --- a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py @@ -11,15 +11,6 @@ class DummyScriptedProcess(ScriptedProcess): super().__init__(exe_ctx, args) self.threads[0] = DummyScriptedThread(self, None) - def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo: - return None - - def get_thread_with_id(self, tid: int): - return {} - - def get_registers_for_thread(self, tid: int): - return {} - def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: debugger = self.target.GetDebugger() index = debugger.GetIndexOfTarget(self.target) diff --git a/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py b/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py index 5852df9..b931076 100644 --- a/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py @@ -11,15 +11,6 @@ class InvalidScriptedProcess(ScriptedProcess): super().__init__(exe_ctx, args) self.threads[0] = InvalidScriptedThread(self, None) - def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo: - return None - - def get_thread_with_id(self, tid: int): - return {} - - def get_registers_for_thread(self, tid: int): - return {} - def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: error.SetErrorString("This is an invalid scripted process!") return lldb.SBData() diff --git a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py index 44a2a37..e7e27fd 100644 --- a/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py +++ b/lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py @@ -59,12 +59,6 @@ class StackCoreScriptedProcess(ScriptedProcess): return None return mem_region - def get_thread_with_id(self, tid: int): - return {} - - def get_registers_for_thread(self, tid: int): - return {} - def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData: data = lldb.SBData() bytes_read = self.corefile_process.ReadMemory(addr, size, error) -- 2.7.4