Skip to content

Commit 84a9005

Browse files
committed
[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 <[email protected]>
1 parent 9a9bc0c commit 84a9005

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

lldb/examples/python/scripted_process/scripted_process.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ScriptedProcess(metaclass=ABCMeta):
1414
THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
1515
"""
1616

17+
capabilities = None
1718
memory_regions = None
1819
loaded_images = None
1920
threads = None
@@ -42,6 +43,17 @@ def __init__(self, target, args):
4243
self.threads = {}
4344
self.loaded_images = []
4445
self.metadata = {}
46+
self.capabilities = {}
47+
48+
def get_capabilities(self):
49+
""" Get a dictionary containing the process capabilities.
50+
51+
Returns:
52+
Dict[str:bool]: The dictionary of capability, with the capability
53+
name as the key and a boolean flag as the value.
54+
The dictionary can be empty.
55+
"""
56+
return self.capabilities
4557

4658
@abstractmethod
4759
def get_memory_region_containing_address(self, addr):

lldb/include/lldb/Interpreter/ScriptedProcessInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class ScriptedProcessInterface : virtual public ScriptedInterface {
2727
return {};
2828
}
2929

30+
virtual StructuredData::DictionarySP GetCapabilities() { return {}; }
31+
3032
virtual Status Launch() { return Status("ScriptedProcess did not launch"); }
3133

3234
virtual Status Resume() { return Status("ScriptedProcess did not resume"); }

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
5353
return m_object_instance_sp;
5454
}
5555

56+
StructuredData::DictionarySP ScriptedProcessPythonInterface::GetCapabilities() {
57+
Status error;
58+
StructuredData::DictionarySP dict =
59+
Dispatch<StructuredData::DictionarySP>("get_capabilities", error);
60+
61+
if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
62+
return {};
63+
64+
return dict;
65+
}
66+
5667
Status ScriptedProcessPythonInterface::Launch() {
5768
return GetStatusFromMethod("launch");
5869
}
@@ -137,14 +148,8 @@ StructuredData::ArraySP ScriptedProcessPythonInterface::GetLoadedImages() {
137148
StructuredData::ArraySP array =
138149
Dispatch<StructuredData::ArraySP>("get_loaded_images", error);
139150

140-
if (!array || !array->IsValid() || error.Fail()) {
141-
return ScriptedInterface::ErrorWithMessage<StructuredData::ArraySP>(
142-
LLVM_PRETTY_FUNCTION,
143-
llvm::Twine("Null or invalid object (" +
144-
llvm::Twine(error.AsCString()) + llvm::Twine(")."))
145-
.str(),
146-
error);
147-
}
151+
if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, array, error))
152+
return {};
148153

149154
return array;
150155
}

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface,
2828
StructuredData::DictionarySP args_sp,
2929
StructuredData::Generic *script_obj = nullptr) override;
3030

31+
StructuredData::DictionarySP GetCapabilities() override;
32+
3133
Status Launch() override;
3234

3335
Status Resume() override;

0 commit comments

Comments
 (0)