summaryrefslogtreecommitdiff
path: root/lldb/bindings/python/python-wrapper.swig
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/bindings/python/python-wrapper.swig')
-rw-r--r--lldb/bindings/python/python-wrapper.swig146
1 files changed, 105 insertions, 41 deletions
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 4c39e9c2c776..6dc8ca170390 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -1,9 +1,5 @@
%header %{
-template <typename T>
-PyObject *
-SBTypeToSWIGWrapper (T* item);
-
class PyErr_Cleaner
{
public:
@@ -83,8 +79,9 @@ LLDBSwigPythonBreakpointCallbackFunction
if (max_positional_args < 4) {
return pfunc.Call(frame_arg, bp_loc_arg, dict);
} else {
+ // FIXME: SBStructuredData leaked here
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
return pfunc.Call(frame_arg, bp_loc_arg, args_arg, dict);
}
} ();
@@ -230,12 +227,11 @@ LLDBSwigPythonCreateSyntheticProvider
if (!pfunc.IsAllocated())
Py_RETURN_NONE;
- // I do not want the SBValue to be deallocated when going out of scope because python
- // has ownership of it and will manage memory for this object by itself
+ // FIXME: SBValue leaked here
lldb::SBValue *sb_value = new lldb::SBValue(valobj_sp);
sb_value->SetPreferSyntheticValue(false);
- PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value));
+ PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*sb_value));
if (!val_arg.IsAllocated())
Py_RETURN_NONE;
@@ -288,7 +284,6 @@ LLDBSwigPythonCreateScriptedProcess
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
Py_RETURN_NONE;
-
PyErr_Cleaner py_err_cleaner(true);
auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
@@ -300,10 +295,9 @@ LLDBSwigPythonCreateScriptedProcess
return nullptr;
}
- // I do not want the SBTarget to be deallocated when going out of scope
- // because python has ownership of it and will manage memory for this
- // object by itself
- PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBTarget(target_sp)));
+ // FIXME: SBTarget leaked here
+ PythonObject target_arg(
+ PyRefType::Owned, SBTypeToSWIGWrapper(*new lldb::SBTarget(target_sp)));
if (!target_arg.IsAllocated())
Py_RETURN_NONE;
@@ -323,16 +317,71 @@ LLDBSwigPythonCreateScriptedProcess
PythonObject result = {};
if (arg_info.get().max_positional_args == 2) {
- if (args_impl != nullptr) {
- error_string.assign("args passed, but __init__ does not take an args dictionary");
- Py_RETURN_NONE;
- }
- result = pfunc(target_arg, dict);
- } else if (arg_info.get().max_positional_args >= 3) {
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBStructuredData(args_impl)));
- result = pfunc(target_arg, args_arg, dict);
+ // FIXME: SBStructuredData leaked here
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
+ result = pfunc(target_arg, args_arg);
} else {
- error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
+ error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
+ Py_RETURN_NONE;
+ }
+
+ if (result.IsAllocated())
+ return result.release();
+ Py_RETURN_NONE;
+}
+
+SWIGEXPORT void*
+LLDBSwigPythonCreateScriptedThread
+(
+ const char *python_class_name,
+ const char *session_dictionary_name,
+ const lldb::ProcessSP& process_sp,
+ lldb_private::StructuredDataImpl *args_impl,
+ std::string &error_string
+)
+{
+ if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
+ Py_RETURN_NONE;
+
+ 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 nullptr;
+ }
+
+ // FIXME: This leaks the SBProcess object
+ PythonObject process_arg(
+ PyRefType::Owned,
+ SBTypeToSWIGWrapper(*new lldb::SBProcess(process_sp)));
+
+ if (!process_arg.IsAllocated())
+ Py_RETURN_NONE;
+
+ 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());
+ });
+ Py_RETURN_NONE;
+ }
+
+ PythonObject result = {};
+ if (arg_info.get().max_positional_args == 2) {
+ // FIXME: SBStructuredData leaked here
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
+ result = pfunc(process_arg, args_arg);
+ } else {
+ error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
}
@@ -366,10 +415,10 @@ LLDBSwigPythonCreateScriptedThreadPlan
return nullptr;
}
- // I do not want the SBThreadPlan to be deallocated when going out of scope
- // because python has ownership of it and will manage memory for this
- // object by itself
- PythonObject tp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBThreadPlan(thread_plan_sp)));
+ // FIXME: SBThreadPlan leaked here
+ PythonObject tp_arg(
+ PyRefType::Owned,
+ SBTypeToSWIGWrapper(*new lldb::SBThreadPlan(thread_plan_sp)));
if (!tp_arg.IsAllocated())
Py_RETURN_NONE;
@@ -395,7 +444,8 @@ LLDBSwigPythonCreateScriptedThreadPlan
}
result = pfunc(tp_arg, dict);
} else if (arg_info.get().max_positional_args >= 3) {
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(new lldb::SBStructuredData(args_impl)));
+ // FIXME: SBStructuredData leaked here
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*new lldb::SBStructuredData(args_impl)));
result = pfunc(tp_arg, args_arg, dict);
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 or 3 (not including self)");
@@ -477,12 +527,14 @@ LLDBSwigPythonCreateScriptedBreakpointResolver
if (!pfunc.IsAllocated())
return nullptr;
+ // FIXME: SBBreakpoint leaked here
lldb::SBBreakpoint *bkpt_value = new lldb::SBBreakpoint(breakpoint_sp);
- PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(bkpt_value));
+ PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*bkpt_value));
+ // FIXME: SBStructuredData leaked here
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
PythonObject result = pfunc(bkpt_arg, args_arg, dict);
// FIXME: At this point we should check that the class we found supports all the methods
@@ -585,13 +637,14 @@ LLDBSwigPythonCreateScriptedStopHook
return nullptr;
}
+ // FIXME: SBTarget leaked here
lldb::SBTarget *target_val
= new lldb::SBTarget(target_sp);
+ PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*target_val));
- PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_val));
-
+ // FIXME: SBStructuredData leaked here
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
- PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
PythonObject result = pfunc(target_arg, args_arg, dict);
@@ -918,6 +971,22 @@ LLDBSWIGPython_CastPyObjectToSBValue
return sb_ptr;
}
+SWIGEXPORT void*
+LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo
+(
+ PyObject* data
+)
+{
+ lldb::SBMemoryRegionInfo* sb_ptr = NULL;
+
+ int valid_cast = SWIG_ConvertPtr(data, (void**)&sb_ptr, SWIGTYPE_p_lldb__SBMemoryRegionInfo, 0);
+
+ if (valid_cast == -1)
+ return NULL;
+
+ return sb_ptr;
+}
+
SWIGEXPORT bool
LLDBSwigPythonCallCommand
(
@@ -940,8 +1009,6 @@ LLDBSwigPythonCallCommand
if (!pfunc.IsAllocated())
return false;
- // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
- // see comment above for SBCommandReturnObjectReleaser for further details
auto argc = pfunc.GetArgInfo();
if (!argc) {
llvm::consumeError(argc.takeError());
@@ -949,7 +1016,7 @@ LLDBSwigPythonCallCommand
}
PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb));
- PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb));
+ PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(cmd_retobj_sb));
if (argc.get().max_positional_args < 5u)
pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict);
@@ -981,11 +1048,9 @@ LLDBSwigPythonCallCommandObject
if (!pfunc.IsAllocated())
return false;
- // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
- // see comment above for SBCommandReturnObjectReleaser for further details
PythonObject debugger_arg(PyRefType::Owned, SBTypeToSWIGWrapper(debugger_sb));
PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb));
- PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb));
+ PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(cmd_retobj_sb));
pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg);
@@ -1011,10 +1076,9 @@ LLDBSWIGPythonCreateOSPlugin
if (!pfunc.IsAllocated())
Py_RETURN_NONE;
- // I do not want the SBProcess to be deallocated when going out of scope because python
- // has ownership of it and will manage memory for this object by itself
+ // FIXME: This leaks the SBProcess object
lldb::SBProcess *process_sb = new lldb::SBProcess(process_sp);
- PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb));
+ PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*process_sb));
if (!process_arg.IsAllocated())
Py_RETURN_NONE;