aboutsummaryrefslogtreecommitdiff
path: root/lldb/bindings/python/python-wrapper.swig
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /lldb/bindings/python/python-wrapper.swig
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'lldb/bindings/python/python-wrapper.swig')
-rw-r--r--lldb/bindings/python/python-wrapper.swig86
1 files changed, 35 insertions, 51 deletions
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 626fc47bebb9..9a08c3000b79 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -90,6 +90,32 @@ bool lldb_private::LLDBSwigPythonWatchpointCallbackFunction(
return stop_at_watchpoint;
}
+// This function is called by
+// ScriptInterpreterPython::FormatterMatchingCallbackFunction and it's used when
+// a data formatter provides the name of a callback to inspect a candidate type
+// before considering a match.
+bool lldb_private::LLDBSwigPythonFormatterCallbackFunction(
+ const char *python_function_name, const char *session_dictionary_name,
+ lldb::TypeImplSP type_impl_sp) {
+
+ PyErr_Cleaner py_err_cleaner(true);
+
+ auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
+ session_dictionary_name);
+ auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
+ python_function_name, dict);
+
+ if (!pfunc.IsAllocated())
+ return false;
+
+ PythonObject result =
+ pfunc(ToSWIGWrapper(type_impl_sp), dict);
+
+ // Only if everything goes okay and the function returns True we'll consider
+ // it a match.
+ return result.get() == Py_True;
+}
+
bool lldb_private::LLDBSwigPythonCallTypeScript(
const char *python_function_name, const void *session_dictionary,
const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
@@ -203,9 +229,9 @@ PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
return pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
}
-PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
+PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject(
const char *python_class_name, const char *session_dictionary_name,
- const lldb::TargetSP &target_sp,
+ lldb::ExecutionContextRefSP exe_ctx_sp,
const lldb_private::StructuredDataImpl &args_impl,
std::string &error_string) {
if (python_class_name == NULL || python_class_name[0] == '\0' ||
@@ -225,8 +251,6 @@ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
return PythonObject();
}
- PythonObject target_arg = ToSWIGWrapper(target_sp);
-
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
if (!arg_info) {
llvm::handleAllErrors(
@@ -240,7 +264,7 @@ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
PythonObject result = {};
if (arg_info.get().max_positional_args == 2) {
- result = pfunc(target_arg, ToSWIGWrapper(args_impl));
+ result = pfunc(ToSWIGWrapper(exe_ctx_sp), ToSWIGWrapper(args_impl));
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 "
"(not including self)");
@@ -248,46 +272,6 @@ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
return result;
}
-PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
- const char *python_class_name, const char *session_dictionary_name,
- const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
- std::string &error_string) {
- if (python_class_name == NULL || python_class_name[0] == '\0' ||
- !session_dictionary_name)
- return PythonObject();
-
- PyErr_Cleaner py_err_cleaner(true);
-
- auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
- session_dictionary_name);
- auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
- python_class_name, dict);
-
- if (!pfunc.IsAllocated()) {
- error_string.append("could not find script class: ");
- error_string.append(python_class_name);
- return PythonObject();
- }
-
- llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
- if (!arg_info) {
- llvm::handleAllErrors(
- arg_info.takeError(),
- [&](PythonException &E) { error_string.append(E.ReadBacktrace()); },
- [&](const llvm::ErrorInfoBase &E) {
- error_string.append(E.message());
- });
- return PythonObject();
- }
-
- if (arg_info.get().max_positional_args == 2)
- return pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
-
- error_string.assign("wrong number of arguments in __init__, should be 2 "
- "(not including self)");
- return PythonObject();
-}
-
PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
const char *python_class_name, const char *session_dictionary_name,
const lldb_private::StructuredDataImpl &args_impl,
@@ -915,12 +899,12 @@ bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess(
return true;
}
-llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
+std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
const char *python_function_name, const char *session_dictionary_name,
lldb::ThreadSP thread) {
if (python_function_name == NULL || python_function_name[0] == '\0' ||
!session_dictionary_name)
- return llvm::None;
+ return std::nullopt;
PyErr_Cleaner py_err_cleaner(true);
@@ -930,7 +914,7 @@ llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
python_function_name, dict);
if (!pfunc.IsAllocated())
- return llvm::None;
+ return std::nullopt;
auto result = pfunc(ToSWIGWrapper(std::move(thread)), dict);
@@ -962,12 +946,12 @@ bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
return true;
}
-llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
+std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
const char *python_function_name, const char *session_dictionary_name,
lldb::StackFrameSP frame) {
if (python_function_name == NULL || python_function_name[0] == '\0' ||
!session_dictionary_name)
- return llvm::None;
+ return std::nullopt;
PyErr_Cleaner py_err_cleaner(true);
@@ -977,7 +961,7 @@ llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
python_function_name, dict);
if (!pfunc.IsAllocated())
- return llvm::None;
+ return std::nullopt;
auto result = pfunc(ToSWIGWrapper(std::move(frame)), dict);