[lldb/Interpreter] Introduce ScriptedStopHook{,Python}Interface & make use of it (#105449)

This patch introduces new `ScriptedStopHook{,Python}Interface` classes
that make use of the Scripted Interface infrastructure and makes use of
it in `StopHookScripted`.

It also relax the requirement on the number of argument for initializing
scripting extension if the size of the interface parameter pack contains
1 less element than the extension maximum number of positional arguments
for this initializer.
This addresses the cases where the embedded interpreter session
dictionary is passed to the extension initializer which is not used most
of the time.

---------

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
This commit is contained in:
Med Ismail Bennani
2024-09-19 23:35:34 -07:00
committed by GitHub
parent f9bd08382a
commit 1e131ddfa8
21 changed files with 299 additions and 222 deletions

View File

@@ -1559,6 +1559,11 @@ ScriptInterpreterPythonImpl::CreateScriptedProcessInterface() {
return std::make_unique<ScriptedProcessPythonInterface>(*this);
}
ScriptedStopHookInterfaceSP
ScriptInterpreterPythonImpl::CreateScriptedStopHookInterface() {
return std::make_shared<ScriptedStopHookPythonInterface>(*this);
}
ScriptedThreadInterfaceSP
ScriptInterpreterPythonImpl::CreateScriptedThreadInterface() {
return std::make_shared<ScriptedThreadPythonInterface>(*this);
@@ -1654,57 +1659,6 @@ ScriptInterpreterPythonImpl::ScriptedBreakpointResolverSearchDepth(
return lldb::eSearchDepthModule;
}
StructuredData::GenericSP ScriptInterpreterPythonImpl::CreateScriptedStopHook(
TargetSP target_sp, const char *class_name,
const StructuredDataImpl &args_data, Status &error) {
if (!target_sp) {
error = Status::FromErrorString("No target for scripted stop-hook.");
return StructuredData::GenericSP();
}
if (class_name == nullptr || class_name[0] == '\0') {
error = Status::FromErrorString("No class name for scripted stop-hook.");
return StructuredData::GenericSP();
}
ScriptInterpreterPythonImpl *python_interpreter =
GetPythonInterpreter(m_debugger);
if (!python_interpreter) {
error = Status::FromErrorString(
"No script interpreter for scripted stop-hook.");
return StructuredData::GenericSP();
}
Locker py_lock(this,
Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedStopHook(
target_sp, class_name, python_interpreter->m_dictionary_name.c_str(),
args_data, error);
return StructuredData::GenericSP(
new StructuredPythonObject(std::move(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 = SWIGBridge::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) {