summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
diff options
context:
space:
mode:
authorMed Ismail Bennani <ismail@bennani.ma>2024-09-19 23:35:34 -0700
committerGitHub <noreply@github.com>2024-09-19 23:35:34 -0700
commit1e131ddfa8f1d7b18c85c6e4079458be8b419421 (patch)
tree6aac6c2d98fdb259657996ba7848949ddb3152a5 /lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
parentf9bd08382a4ad84c06e0b572d3b7fc3ecdb81898 (diff)
[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>
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h44
1 files changed, 38 insertions, 6 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index c715295eb9ff..4b9f463ef560 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -180,12 +180,35 @@ public:
llvm::Expected<PythonObject> expected_return_object =
create_error("Resulting object is not initialized.");
- std::apply(
- [&init, &expected_return_object](auto &&...args) {
- llvm::consumeError(expected_return_object.takeError());
- expected_return_object = init(args...);
- },
- transformed_args);
+ // This 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.
+ size_t num_args = sizeof...(Args);
+ if (num_args != arg_info->max_positional_args) {
+ if (num_args != arg_info->max_positional_args - 1)
+ return create_error("Passed arguments ({0}) doesn't match the number "
+ "of expected arguments ({1}).",
+ num_args, arg_info->max_positional_args);
+
+ std::apply(
+ [&init, &expected_return_object](auto &&...args) {
+ llvm::consumeError(expected_return_object.takeError());
+ expected_return_object = init(args...);
+ },
+ std::tuple_cat(transformed_args, std::make_tuple(dict)));
+ } else {
+ std::apply(
+ [&init, &expected_return_object](auto &&...args) {
+ llvm::consumeError(expected_return_object.takeError());
+ expected_return_object = init(args...);
+ },
+ transformed_args);
+ }
if (!expected_return_object)
return expected_return_object.takeError();
@@ -405,6 +428,10 @@ protected:
return python::SWIGBridge::ToSWIGWrapper(arg);
}
+ python::PythonObject Transform(lldb::TargetSP arg) {
+ return python::SWIGBridge::ToSWIGWrapper(arg);
+ }
+
python::PythonObject Transform(lldb::ProcessSP arg) {
return python::SWIGBridge::ToSWIGWrapper(arg);
}
@@ -557,6 +584,11 @@ std::optional<MemoryRegionInfo>
ScriptedPythonInterface::ExtractValueFromPythonObject<
std::optional<MemoryRegionInfo>>(python::PythonObject &p, Status &error);
+template <>
+lldb::ExecutionContextRefSP
+ScriptedPythonInterface::ExtractValueFromPythonObject<
+ lldb::ExecutionContextRefSP>(python::PythonObject &p, Status &error);
+
} // namespace lldb_private
#endif // LLDB_ENABLE_PYTHON