[lldb/Plugins] Clean-up Scripted Process interface requirements (NFC)
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Thu, 16 Feb 2023 23:15:52 +0000 (15:15 -0800)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Sat, 4 Mar 2023 03:33:02 +0000 (19:33 -0800)
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 <medismail.bennani@gmail.com>
lldb/examples/python/scripted_process/crashlog_scripted_process.py
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

index dfb32aa..8c32b40 100644 (file)
@@ -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()
index 8f896fc..60b65fc 100644 (file)
@@ -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.
index 1fdac76..ec0d7de 100644 (file)
@@ -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 {};
index c231828..3ca4664 100644 (file)
@@ -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;
index 076ac37..44273f1 100644 (file)
@@ -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;
 
index 9466411..4703814 100644 (file)
@@ -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)
index 5852df9..b931076 100644 (file)
@@ -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()
index 44a2a37..e7e27fd 100644 (file)
@@ -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)