summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp
index b866bf332b7b..3dde5036453f 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/Log.h"
@@ -30,18 +31,45 @@ ScriptedFrameProviderPythonInterface::ScriptedFrameProviderPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedFrameProviderInterface(), ScriptedPythonInterface(interpreter) {}
+bool ScriptedFrameProviderPythonInterface::AppliesToThread(
+ llvm::StringRef class_name, lldb::ThreadSP thread_sp) {
+ // If there is any issue with this method, we will just assume it also applies
+ // to this thread which is the default behavior.
+ constexpr bool fail_value = true;
+ Status error;
+ StructuredData::ObjectSP obj =
+ CallStaticMethod(class_name, "applies_to_thread", error, thread_sp);
+ if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
+ error))
+ return fail_value;
+
+ return obj->GetBooleanValue(fail_value);
+}
+
llvm::Expected<StructuredData::GenericSP>
ScriptedFrameProviderPythonInterface::CreatePluginObject(
const llvm::StringRef class_name, lldb::StackFrameListSP input_frames,
StructuredData::DictionarySP args_sp) {
if (!input_frames)
- return llvm::createStringError("Invalid frame list");
+ return llvm::createStringError("invalid frame list");
StructuredDataImpl sd_impl(args_sp);
return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
input_frames, sd_impl);
}
+std::string ScriptedFrameProviderPythonInterface::GetDescription(
+ llvm::StringRef class_name) {
+ Status error;
+ StructuredData::ObjectSP obj =
+ CallStaticMethod(class_name, "get_description", error);
+ if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
+ error))
+ return {};
+
+ return obj->GetStringValue().str();
+}
+
StructuredData::ObjectSP
ScriptedFrameProviderPythonInterface::GetFrameAtIndex(uint32_t index) {
Status error;
@@ -54,4 +82,32 @@ ScriptedFrameProviderPythonInterface::GetFrameAtIndex(uint32_t index) {
return obj;
}
+bool ScriptedFrameProviderPythonInterface::CreateInstance(
+ lldb::ScriptLanguage language, ScriptedInterfaceUsages usages) {
+ if (language != eScriptLanguagePython)
+ return false;
+
+ return true;
+}
+
+void ScriptedFrameProviderPythonInterface::Initialize() {
+ const std::vector<llvm::StringRef> ci_usages = {
+ "target frame-provider register -C <script-name> [-k key -v value ...]",
+ "target frame-provider list",
+ "target frame-provider remove <provider-name>",
+ "target frame-provider clear"};
+ const std::vector<llvm::StringRef> api_usages = {
+ "SBTarget.RegisterScriptedFrameProvider",
+ "SBTarget.RemoveScriptedFrameProvider",
+ "SBTarget.ClearScriptedFrameProvider"};
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(),
+ llvm::StringRef("Provide scripted stack frames for threads"),
+ CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
+}
+
+void ScriptedFrameProviderPythonInterface::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
#endif