aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2020-09-28 10:28:29 -0700
committerJim Ingham <jingham@apple.com>2020-09-29 12:01:14 -0700
commit1b1d9815987a753f2f3524cfad050b85972dae5b (patch)
treeed2bbf35bafd76b8ff1fd6103527a6c09a978f98 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
parent962a247aebba39bc8f2d6aa901ed512f5c09dc72 (diff)
downloadllvm-1b1d9815987a753f2f3524cfad050b85972dae5b.zip
llvm-1b1d9815987a753f2f3524cfad050b85972dae5b.tar.gz
llvm-1b1d9815987a753f2f3524cfad050b85972dae5b.tar.bz2
Revert "Revert "Add the ability to write target stop-hooks using the ScriptInterpreter.""
This reverts commit f775fe59640a2e837ad059a8f40e26989d4f9831. I fixed a return type error in the original patch that was causing a test failure. Also added a REQUIRES: python to the shell test so we'll skip this for people who build lldb w/o Python. Also added another test for the error printing.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 9f56b4f..f67572c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -127,6 +127,16 @@ extern "C" unsigned int
LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
lldb_private::SymbolContext *sym_ctx);
+extern "C" void *LLDBSwigPythonCreateScriptedStopHook(
+ TargetSP target_sp, const char *python_class_name,
+ const char *session_dictionary_name, lldb_private::StructuredDataImpl *args,
+ lldb_private::Status &error);
+
+extern "C" bool
+LLDBSwigPythonStopHookCallHandleStop(void *implementor,
+ lldb::ExecutionContextRefSP exc_ctx,
+ lldb::StreamSP stream);
+
extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor,
uint32_t max);
@@ -1979,6 +1989,60 @@ ScriptInterpreterPythonImpl::ScriptedBreakpointResolverSearchDepth(
return lldb::eSearchDepthModule;
}
+StructuredData::GenericSP ScriptInterpreterPythonImpl::CreateScriptedStopHook(
+ TargetSP target_sp, const char *class_name, StructuredDataImpl *args_data,
+ Status &error) {
+
+ if (!target_sp) {
+ error.SetErrorString("No target for scripted stop-hook.");
+ return StructuredData::GenericSP();
+ }
+
+ if (class_name == nullptr || class_name[0] == '\0') {
+ error.SetErrorString("No class name for scripted stop-hook.");
+ return StructuredData::GenericSP();
+ }
+
+ ScriptInterpreter *script_interpreter = m_debugger.GetScriptInterpreter();
+ ScriptInterpreterPythonImpl *python_interpreter =
+ static_cast<ScriptInterpreterPythonImpl *>(script_interpreter);
+
+ if (!script_interpreter) {
+ error.SetErrorString("No script interpreter for scripted stop-hook.");
+ return StructuredData::GenericSP();
+ }
+
+ void *ret_val;
+
+ {
+ Locker py_lock(this,
+ Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
+
+ ret_val = LLDBSwigPythonCreateScriptedStopHook(
+ target_sp, class_name, python_interpreter->m_dictionary_name.c_str(),
+ args_data, error);
+ }
+
+ return StructuredData::GenericSP(new StructuredPythonObject(ret_val));
+}
+
+bool ScriptInterpreterPythonImpl::ScriptedStopHookHandleStop(
+ StructuredData::GenericSP implementor_sp, ExecutionContext &exc_ctx,
+ lldb::StreamSP stream_sp) {
+ assert(implementor_sp &&
+ "can't call a stop hook with an invalid implementor");
+ assert(stream_sp && "can't call a stop hook with an invalid stream");
+
+ Locker py_lock(this,
+ Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
+
+ lldb::ExecutionContextRefSP exc_ctx_ref_sp(new ExecutionContextRef(exc_ctx));
+
+ bool ret_val = LLDBSwigPythonStopHookCallHandleStop(
+ implementor_sp->GetValue(), exc_ctx_ref_sp, stream_sp);
+ return ret_val;
+}
+
StructuredData::ObjectSP
ScriptInterpreterPythonImpl::LoadPluginModule(const FileSpec &file_spec,
lldb_private::Status &error) {