[Lldb-commits] [lldb] 2d5348b - [lldb/Plugins] Add ScriptedProcess::GetCapabilities affordance (NFC)

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 3 19:33:17 PST 2023


Author: Med Ismail Bennani
Date: 2023-03-03T19:33:02-08:00
New Revision: 2d5348be2561402e284e26a9adf3a2e28e70c1f5

URL: https://github.com/llvm/llvm-project/commit/2d5348be2561402e284e26a9adf3a2e28e70c1f5
DIFF: https://github.com/llvm/llvm-project/commit/2d5348be2561402e284e26a9adf3a2e28e70c1f5.diff

LOG: [lldb/Plugins] Add ScriptedProcess::GetCapabilities affordance (NFC)

This patch introduces a new method to the Scripted Process interface,
GetCapabilities.

This returns a dictionary that contains a list of flags that the
ScriptedProcess instance supports. This can be used for instance, to
force symbol lookup, when loading dynamic libraries in the scripted process.

Differential Revision: https://reviews.llvm.org/D142059

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/scripted_process/scripted_process.py b/lldb/examples/python/scripted_process/scripted_process.py
index 758d0a47d115..db77e125817e 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -14,6 +14,7 @@ class ScriptedProcess(metaclass=ABCMeta):
                 THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
     """
 
+    capabilities = None
     memory_regions = None
     loaded_images = None
     threads = None
@@ -45,6 +46,17 @@ def __init__(self, exe_ctx, args):
         self.threads = {}
         self.loaded_images = []
         self.metadata = {}
+        self.capabilities = {}
+
+    def get_capabilities(self):
+        """ Get a dictionary containing the process capabilities.
+
+        Returns:
+            Dict[str:bool]: The dictionary of capability, with the capability
+            name as the key and a boolean flag as the value.
+            The dictionary can be empty.
+        """
+        return self.capabilities
 
     @abstractmethod
     def get_memory_region_containing_address(self, addr):

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index 6d1860aa310a..0dffa71a873d 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -28,6 +28,8 @@ class ScriptedProcessInterface : virtual public ScriptedInterface {
     return {};
   }
 
+  virtual StructuredData::DictionarySP GetCapabilities() { return {}; }
+
   virtual Status Launch() { return Status("ScriptedProcess did not launch"); }
 
   virtual Status Resume() { return Status("ScriptedProcess did not resume"); }

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index 6f087e8390ce..3a1db7f35b15 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -56,6 +56,17 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
   return m_object_instance_sp;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetCapabilities() {
+  Status error;
+  StructuredData::DictionarySP dict =
+      Dispatch<StructuredData::DictionarySP>("get_capabilities", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+    return {};
+
+  return dict;
+}
+
 Status ScriptedProcessPythonInterface::Launch() {
   return GetStatusFromMethod("launch");
 }
@@ -140,14 +151,8 @@ StructuredData::ArraySP ScriptedProcessPythonInterface::GetLoadedImages() {
   StructuredData::ArraySP array =
       Dispatch<StructuredData::ArraySP>("get_loaded_images", error);
 
-  if (!array || !array->IsValid() || error.Fail()) {
-    return ScriptedInterface::ErrorWithMessage<StructuredData::ArraySP>(
-        LLVM_PRETTY_FUNCTION,
-        llvm::Twine("Null or invalid object (" +
-                    llvm::Twine(error.AsCString()) + llvm::Twine(")."))
-            .str(),
-        error);
-  }
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, array, error))
+    return {};
 
   return array;
 }

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
index 6b4ee3021cfa..6358f9cabffd 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -29,6 +29,8 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface,
                      StructuredData::DictionarySP args_sp,
                      StructuredData::Generic *script_obj = nullptr) override;
 
+  StructuredData::DictionarySP GetCapabilities() override;
+
   Status Launch() override;
 
   Status Resume() override;


        


More information about the lldb-commits mailing list