aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp104
1 files changed, 61 insertions, 43 deletions
diff --git a/contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp b/contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp
index d6de6b3c3cf0..dfcb67eb1902 100644
--- a/contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp
+++ b/contrib/llvm-project/lldb/source/Target/ThreadPlanPython.cpp
@@ -10,6 +10,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
@@ -32,6 +33,26 @@ ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
eVoteNoOpinion, eVoteNoOpinion),
m_class_name(class_name), m_args_data(args_data), m_did_push(false),
m_stop_others(false) {
+ ScriptInterpreter *interpreter = GetScriptInterpreter();
+ if (!interpreter) {
+ SetPlanComplete(false);
+ // FIXME: error handling
+ // error.SetErrorStringWithFormat(
+ // "ThreadPlanPython::%s () - ERROR: %s", __FUNCTION__,
+ // "Couldn't get script interpreter");
+ return;
+ }
+
+ m_interface = interpreter->CreateScriptedThreadPlanInterface();
+ if (!m_interface) {
+ SetPlanComplete(false);
+ // FIXME: error handling
+ // error.SetErrorStringWithFormat(
+ // "ThreadPlanPython::%s () - ERROR: %s", __FUNCTION__,
+ // "Script interpreter couldn't create Scripted Thread Plan Interface");
+ return;
+ }
+
SetIsControllingPlan(true);
SetOkayToDiscard(true);
SetPrivate(false);
@@ -60,13 +81,14 @@ void ThreadPlanPython::DidPush() {
// We set up the script side in DidPush, so that it can push other plans in
// the constructor, and doesn't have to care about the details of DidPush.
m_did_push = true;
- if (!m_class_name.empty()) {
- ScriptInterpreter *script_interp = GetScriptInterpreter();
- if (script_interp) {
- m_implementation_sp = script_interp->CreateScriptedThreadPlan(
- m_class_name.c_str(), m_args_data, m_error_str,
- this->shared_from_this());
- }
+ if (m_interface) {
+ auto obj_or_err = m_interface->CreatePluginObject(
+ m_class_name, this->shared_from_this(), m_args_data);
+ if (!obj_or_err) {
+ m_error_str = llvm::toString(obj_or_err.takeError());
+ SetPlanComplete(false);
+ } else
+ m_implementation_sp = *obj_or_err;
}
}
@@ -77,14 +99,13 @@ bool ThreadPlanPython::ShouldStop(Event *event_ptr) {
bool should_stop = true;
if (m_implementation_sp) {
- ScriptInterpreter *script_interp = GetScriptInterpreter();
- if (script_interp) {
- bool script_error;
- should_stop = script_interp->ScriptedThreadPlanShouldStop(
- m_implementation_sp, event_ptr, script_error);
- if (script_error)
- SetPlanComplete(false);
- }
+ auto should_stop_or_err = m_interface->ShouldStop(event_ptr);
+ if (!should_stop_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), should_stop_or_err.takeError(),
+ "Can't call ScriptedThreadPlan::ShouldStop.");
+ SetPlanComplete(false);
+ } else
+ should_stop = *should_stop_or_err;
}
return should_stop;
}
@@ -96,14 +117,13 @@ bool ThreadPlanPython::IsPlanStale() {
bool is_stale = true;
if (m_implementation_sp) {
- ScriptInterpreter *script_interp = GetScriptInterpreter();
- if (script_interp) {
- bool script_error;
- is_stale = script_interp->ScriptedThreadPlanIsStale(m_implementation_sp,
- script_error);
- if (script_error)
- SetPlanComplete(false);
- }
+ auto is_stale_or_err = m_interface->IsStale();
+ if (!is_stale_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), is_stale_or_err.takeError(),
+ "Can't call ScriptedThreadPlan::IsStale.");
+ SetPlanComplete(false);
+ } else
+ is_stale = *is_stale_or_err;
}
return is_stale;
}
@@ -115,14 +135,14 @@ bool ThreadPlanPython::DoPlanExplainsStop(Event *event_ptr) {
bool explains_stop = true;
if (m_implementation_sp) {
- ScriptInterpreter *script_interp = GetScriptInterpreter();
- if (script_interp) {
- bool script_error;
- explains_stop = script_interp->ScriptedThreadPlanExplainsStop(
- m_implementation_sp, event_ptr, script_error);
- if (script_error)
- SetPlanComplete(false);
- }
+ auto explains_stop_or_error = m_interface->ExplainsStop(event_ptr);
+ if (!explains_stop_or_error) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Thread),
+ explains_stop_or_error.takeError(),
+ "Can't call ScriptedThreadPlan::ExplainsStop.");
+ SetPlanComplete(false);
+ } else
+ explains_stop = *explains_stop_or_error;
}
return explains_stop;
}
@@ -150,14 +170,8 @@ lldb::StateType ThreadPlanPython::GetPlanRunState() {
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
m_class_name.c_str());
lldb::StateType run_state = eStateRunning;
- if (m_implementation_sp) {
- ScriptInterpreter *script_interp = GetScriptInterpreter();
- if (script_interp) {
- bool script_error;
- run_state = script_interp->ScriptedThreadPlanGetRunState(
- m_implementation_sp, script_error);
- }
- }
+ if (m_implementation_sp)
+ run_state = m_interface->GetRunState();
return run_state;
}
@@ -168,12 +182,16 @@ void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
if (m_implementation_sp) {
ScriptInterpreter *script_interp = GetScriptInterpreter();
if (script_interp) {
- bool script_error;
- bool added_desc = script_interp->ScriptedThreadPlanGetStopDescription(
- m_implementation_sp, s, script_error);
- if (script_error || !added_desc)
+ lldb::StreamSP stream = std::make_shared<lldb_private::StreamString>();
+ llvm::Error err = m_interface->GetStopDescription(stream);
+ if (err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
+ "Can't call ScriptedThreadPlan::GetStopDescription.");
s->Printf("Python thread plan implemented by class %s.",
m_class_name.c_str());
+ } else
+ s->PutCString(
+ reinterpret_cast<StreamString *>(stream.get())->GetData());
}
return;
}