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.swig299
1 files changed, 98 insertions, 201 deletions
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 6dc8ca170390..079f8d12dafa 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -22,32 +22,8 @@ private:
bool m_print;
};
-%}
-
-%wrapper %{
-
-// resolve a dotted Python name in the form
-// foo.bar.baz.Foobar to an actual Python object
-// if pmodule is NULL, the __main__ module will be used
-// as the starting point for the search
-
-
-// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...)
-// and is used when a script command is attached to a breakpoint for execution.
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
-
-// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has
-// C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is
-// incompatible with C
-#if _MSC_VER
-#pragma warning (push)
-#pragma warning (disable : 4190)
-#endif
-
-SWIGEXPORT llvm::Expected<bool>
-LLDBSwigPythonBreakpointCallbackFunction
+llvm::Expected<bool>
+lldb_private::LLDBSwigPythonBreakpointCallbackFunction
(
const char *python_function_name,
const char *session_dictionary_name,
@@ -93,17 +69,20 @@ LLDBSwigPythonBreakpointCallbackFunction
return result.get().get() != Py_False;
}
-#if _MSC_VER
-#pragma warning (pop)
-#endif
+// resolve a dotted Python name in the form
+// foo.bar.baz.Foobar to an actual Python object
+// if pmodule is NULL, the __main__ module will be used
+// as the starting point for the search
-#pragma clang diagnostic pop
+
+// This function is called by lldb_private::ScriptInterpreterPython::BreakpointCallbackFunction(...)
+// and is used when a script command is attached to a breakpoint for execution.
// This function is called by lldb_private::ScriptInterpreterPython::WatchpointCallbackFunction(...)
// and is used when a script command is attached to a watchpoint for execution.
-SWIGEXPORT bool
-LLDBSwigPythonWatchpointCallbackFunction
+bool
+lldb_private::LLDBSwigPythonWatchpointCallbackFunction
(
const char *python_function_name,
const char *session_dictionary_name,
@@ -134,8 +113,8 @@ LLDBSwigPythonWatchpointCallbackFunction
return stop_at_watchpoint;
}
-SWIGEXPORT bool
-LLDBSwigPythonCallTypeScript
+bool
+lldb_private::LLDBSwigPythonCallTypeScript
(
const char *python_function_name,
const void *session_dictionary,
@@ -145,7 +124,6 @@ LLDBSwigPythonCallTypeScript
std::string& retval
)
{
- lldb::SBValue sb_value (valobj_sp);
lldb::SBTypeSummaryOptions sb_options(options_sp.get());
retval.clear();
@@ -195,7 +173,7 @@ LLDBSwigPythonCallTypeScript
return false;
}
- PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value));
+ PythonObject value_arg = ToSWIGWrapper(valobj_sp);
PythonObject options_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_options));
if (argc.get().max_positional_args < 3)
@@ -208,8 +186,8 @@ LLDBSwigPythonCallTypeScript
return true;
}
-SWIGEXPORT void*
-LLDBSwigPythonCreateSyntheticProvider
+void*
+lldb_private::LLDBSwigPythonCreateSyntheticProvider
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -227,11 +205,10 @@ LLDBSwigPythonCreateSyntheticProvider
if (!pfunc.IsAllocated())
Py_RETURN_NONE;
- // FIXME: SBValue leaked here
- lldb::SBValue *sb_value = new lldb::SBValue(valobj_sp);
+ auto sb_value = std::make_unique<lldb::SBValue>(valobj_sp);
sb_value->SetPreferSyntheticValue(false);
- PythonObject val_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*sb_value));
+ PythonObject val_arg = ToSWIGWrapper(std::move(sb_value));
if (!val_arg.IsAllocated())
Py_RETURN_NONE;
@@ -243,8 +220,8 @@ LLDBSwigPythonCreateSyntheticProvider
Py_RETURN_NONE;
}
-SWIGEXPORT void*
-LLDBSwigPythonCreateCommandObject
+void*
+lldb_private::LLDBSwigPythonCreateCommandObject
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -271,8 +248,8 @@ LLDBSwigPythonCreateCommandObject
Py_RETURN_NONE;
}
-SWIGEXPORT void*
-LLDBSwigPythonCreateScriptedProcess
+void*
+lldb_private::LLDBSwigPythonCreateScriptedProcess
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -295,12 +272,7 @@ LLDBSwigPythonCreateScriptedProcess
return nullptr;
}
- // FIXME: SBTarget leaked here
- PythonObject target_arg(
- PyRefType::Owned, SBTypeToSWIGWrapper(*new lldb::SBTarget(target_sp)));
-
- if (!target_arg.IsAllocated())
- Py_RETURN_NONE;
+ PythonObject target_arg = ToSWIGWrapper(target_sp);
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
if (!arg_info) {
@@ -330,8 +302,8 @@ LLDBSwigPythonCreateScriptedProcess
Py_RETURN_NONE;
}
-SWIGEXPORT void*
-LLDBSwigPythonCreateScriptedThread
+void*
+lldb_private::LLDBSwigPythonCreateScriptedThread
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -354,14 +326,6 @@ LLDBSwigPythonCreateScriptedThread
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(
@@ -379,7 +343,7 @@ LLDBSwigPythonCreateScriptedThread
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);
+ result = pfunc(ToSWIGWrapper(process_sp), args_arg);
} else {
error_string.assign("wrong number of arguments in __init__, should be 2 (not including self)");
Py_RETURN_NONE;
@@ -390,8 +354,8 @@ LLDBSwigPythonCreateScriptedThread
Py_RETURN_NONE;
}
-SWIGEXPORT void*
-LLDBSwigPythonCreateScriptedThreadPlan
+void*
+lldb_private::LLDBSwigPythonCreateScriptedThreadPlan
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -415,13 +379,7 @@ LLDBSwigPythonCreateScriptedThreadPlan
return nullptr;
}
- // FIXME: SBThreadPlan leaked here
- PythonObject tp_arg(
- PyRefType::Owned,
- SBTypeToSWIGWrapper(*new lldb::SBThreadPlan(thread_plan_sp)));
-
- if (!tp_arg.IsAllocated())
- Py_RETURN_NONE;
+ PythonObject tp_arg = ToSWIGWrapper(thread_plan_sp);
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
if (!arg_info) {
@@ -460,8 +418,8 @@ LLDBSwigPythonCreateScriptedThreadPlan
Py_RETURN_NONE;
}
-SWIGEXPORT bool
-LLDBSWIGPythonCallThreadPlan
+bool
+lldb_private::LLDBSWIGPythonCallThreadPlan
(
void *implementor,
const char *method_name,
@@ -507,15 +465,11 @@ LLDBSWIGPythonCallThreadPlan
return false;
}
-SWIGEXPORT void *
-LLDBSwigPythonCreateScriptedBreakpointResolver
-(
- const char *python_class_name,
- const char *session_dictionary_name,
+void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
+ const char *python_class_name, const char *session_dictionary_name,
lldb_private::StructuredDataImpl *args_impl,
- lldb::BreakpointSP &breakpoint_sp
-)
-{
+ const lldb::BreakpointSP &breakpoint_sp) {
+
if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
Py_RETURN_NONE;
@@ -527,16 +481,11 @@ 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));
-
// FIXME: SBStructuredData leaked here
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*args_value));
- PythonObject result = pfunc(bkpt_arg, args_arg, dict);
+ PythonObject result = pfunc(ToSWIGWrapper(breakpoint_sp), args_arg, dict);
// FIXME: At this point we should check that the class we found supports all the methods
// that we need.
@@ -552,8 +501,8 @@ LLDBSwigPythonCreateScriptedBreakpointResolver
Py_RETURN_NONE;
}
-SWIGEXPORT unsigned int
-LLDBSwigPythonCallBreakpointResolver
+unsigned int
+lldb_private::LLDBSwigPythonCallBreakpointResolver
(
void *implementor,
const char *method_name,
@@ -603,8 +552,8 @@ LLDBSwigPythonCallBreakpointResolver
return ret_val;
}
-SWIGEXPORT void *
-LLDBSwigPythonCreateScriptedStopHook
+void *
+lldb_private::LLDBSwigPythonCreateScriptedStopHook
(
lldb::TargetSP target_sp,
const char *python_class_name,
@@ -637,16 +586,11 @@ LLDBSwigPythonCreateScriptedStopHook
return nullptr;
}
- // FIXME: SBTarget leaked here
- lldb::SBTarget *target_val
- = new lldb::SBTarget(target_sp);
- 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 result = pfunc(target_arg, args_arg, dict);
+ PythonObject result = pfunc(ToSWIGWrapper(target_sp), args_arg, dict);
if (result.IsAllocated())
{
@@ -679,8 +623,8 @@ LLDBSwigPythonCreateScriptedStopHook
Py_RETURN_NONE;
}
-SWIGEXPORT bool
-LLDBSwigPythonStopHookCallHandleStop
+bool
+lldb_private::LLDBSwigPythonStopHookCallHandleStop
(
void *implementor,
lldb::ExecutionContextRefSP exc_ctx_sp,
@@ -755,8 +699,8 @@ LLDBSwigPython_CallOptionalMember
return result.release();
}
-SWIGEXPORT size_t
-LLDBSwigPython_CalculateNumChildren
+size_t
+lldb_private::LLDBSwigPython_CalculateNumChildren
(
PyObject *implementor,
uint32_t max
@@ -793,8 +737,8 @@ LLDBSwigPython_CalculateNumChildren
return ret_val;
}
-SWIGEXPORT PyObject*
-LLDBSwigPython_GetChildAtIndex
+PyObject*
+lldb_private::LLDBSwigPython_GetChildAtIndex
(
PyObject *implementor,
uint32_t idx
@@ -823,8 +767,8 @@ LLDBSwigPython_GetChildAtIndex
return result.release();
}
-SWIGEXPORT int
-LLDBSwigPython_GetIndexOfChildWithName
+int
+lldb_private::LLDBSwigPython_GetIndexOfChildWithName
(
PyObject *implementor,
const char* child_name
@@ -853,8 +797,8 @@ LLDBSwigPython_GetIndexOfChildWithName
return UINT32_MAX;
}
-SWIGEXPORT bool
-LLDBSwigPython_UpdateSynthProviderInstance
+bool
+lldb_private::LLDBSwigPython_UpdateSynthProviderInstance
(
PyObject *implementor
)
@@ -873,8 +817,8 @@ LLDBSwigPython_UpdateSynthProviderInstance
return ret_val;
}
-SWIGEXPORT bool
-LLDBSwigPython_MightHaveChildrenSynthProviderInstance
+bool
+lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance
(
PyObject *implementor
)
@@ -893,8 +837,8 @@ LLDBSwigPython_MightHaveChildrenSynthProviderInstance
return ret_val;
}
-SWIGEXPORT PyObject*
-LLDBSwigPython_GetValueSynthProviderInstance
+PyObject*
+lldb_private::LLDBSwigPython_GetValueSynthProviderInstance
(
PyObject *implementor
)
@@ -921,8 +865,8 @@ LLDBSwigPython_GetValueSynthProviderInstance
return ret_val;
}
-SWIGEXPORT void*
-LLDBSWIGPython_CastPyObjectToSBData
+void*
+lldb_private::LLDBSWIGPython_CastPyObjectToSBData
(
PyObject* data
)
@@ -938,8 +882,8 @@ LLDBSWIGPython_CastPyObjectToSBData
}
-SWIGEXPORT void*
-LLDBSWIGPython_CastPyObjectToSBError
+void*
+lldb_private::LLDBSWIGPython_CastPyObjectToSBError
(
PyObject* data
)
@@ -955,8 +899,8 @@ LLDBSWIGPython_CastPyObjectToSBError
}
-SWIGEXPORT void*
-LLDBSWIGPython_CastPyObjectToSBValue
+void*
+lldb_private::LLDBSWIGPython_CastPyObjectToSBValue
(
PyObject* data
)
@@ -971,8 +915,8 @@ LLDBSWIGPython_CastPyObjectToSBValue
return sb_ptr;
}
-SWIGEXPORT void*
-LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo
+void*
+lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo
(
PyObject* data
)
@@ -987,8 +931,8 @@ LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo
return sb_ptr;
}
-SWIGEXPORT bool
-LLDBSwigPythonCallCommand
+bool
+lldb_private::LLDBSwigPythonCallCommand
(
const char *python_function_name,
const char *session_dictionary_name,
@@ -1026,8 +970,8 @@ LLDBSwigPythonCallCommand
return true;
}
-SWIGEXPORT bool
-LLDBSwigPythonCallCommandObject
+bool
+lldb_private::LLDBSwigPythonCallCommandObject
(
PyObject *implementor,
lldb::DebuggerSP& debugger,
@@ -1057,8 +1001,8 @@ LLDBSwigPythonCallCommandObject
return true;
}
-SWIGEXPORT void*
-LLDBSWIGPythonCreateOSPlugin
+void*
+lldb_private::LLDBSWIGPythonCreateOSPlugin
(
const char *python_class_name,
const char *session_dictionary_name,
@@ -1076,13 +1020,7 @@ LLDBSWIGPythonCreateOSPlugin
if (!pfunc.IsAllocated())
Py_RETURN_NONE;
- // FIXME: This leaks the SBProcess object
- lldb::SBProcess *process_sb = new lldb::SBProcess(process_sp);
- PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(*process_sb));
- if (!process_arg.IsAllocated())
- Py_RETURN_NONE;
-
- auto result = pfunc(process_arg);
+ auto result = pfunc(ToSWIGWrapper(process_sp));
if (result.IsAllocated())
return result.release();
@@ -1090,8 +1028,8 @@ LLDBSWIGPythonCreateOSPlugin
Py_RETURN_NONE;
}
-SWIGEXPORT void*
-LLDBSWIGPython_CreateFrameRecognizer
+void*
+lldb_private::LLDBSWIGPython_CreateFrameRecognizer
(
const char *python_class_name,
const char *session_dictionary_name
@@ -1116,8 +1054,8 @@ LLDBSWIGPython_CreateFrameRecognizer
Py_RETURN_NONE;
}
-SWIGEXPORT PyObject*
-LLDBSwigPython_GetRecognizedArguments
+PyObject*
+lldb_private::LLDBSwigPython_GetRecognizedArguments
(
PyObject *implementor,
const lldb::StackFrameSP& frame_sp
@@ -1134,8 +1072,8 @@ LLDBSwigPython_GetRecognizedArguments
return result;
}
-SWIGEXPORT void*
-LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp)
+void*
+lldb_private::LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp)
{
if (!module || !setting)
Py_RETURN_NONE;
@@ -1147,21 +1085,15 @@ LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb:
if (!pfunc.IsAllocated())
Py_RETURN_NONE;
- lldb::SBTarget target_sb(target_sp);
- PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb));
- auto result = pfunc(target_arg, PythonString(setting));
+ auto result = pfunc(ToSWIGWrapper(target_sp), PythonString(setting));
return result.release();
}
-SWIGEXPORT bool
-LLDBSWIGPythonRunScriptKeywordProcess
-(const char* python_function_name,
-const char* session_dictionary_name,
-lldb::ProcessSP& process,
-std::string& output)
+bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess(
+ const char *python_function_name, const char *session_dictionary_name,
+ const lldb::ProcessSP &process, std::string &output) {
-{
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
return false;
@@ -1173,17 +1105,15 @@ std::string& output)
if (!pfunc.IsAllocated())
return false;
- lldb::SBProcess process_sb(process);
- PythonObject process_arg(PyRefType::Owned, SBTypeToSWIGWrapper(process_sb));
- auto result = pfunc(process_arg, dict);
+ auto result = pfunc(ToSWIGWrapper(process), dict);
output = result.Str().GetString().str();
return true;
}
-SWIGEXPORT bool
-LLDBSWIGPythonRunScriptKeywordThread
+bool
+lldb_private::LLDBSWIGPythonRunScriptKeywordThread
(const char* python_function_name,
const char* session_dictionary_name,
lldb::ThreadSP& thread,
@@ -1210,14 +1140,10 @@ std::string& output)
return true;
}
-SWIGEXPORT bool
-LLDBSWIGPythonRunScriptKeywordTarget
-(const char* python_function_name,
-const char* session_dictionary_name,
-lldb::TargetSP& target,
-std::string& output)
+bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
+ const char *python_function_name, const char *session_dictionary_name,
+ const lldb::TargetSP &target, std::string &output) {
-{
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
return false;
@@ -1229,17 +1155,15 @@ std::string& output)
if (!pfunc.IsAllocated())
return false;
- lldb::SBTarget target_sb(target);
- PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_sb));
- auto result = pfunc(target_arg, dict);
+ auto result = pfunc(ToSWIGWrapper(target), dict);
output = result.Str().GetString().str();
return true;
}
-SWIGEXPORT bool
-LLDBSWIGPythonRunScriptKeywordFrame
+bool
+lldb_private::LLDBSWIGPythonRunScriptKeywordFrame
(const char* python_function_name,
const char* session_dictionary_name,
lldb::StackFrameSP& frame,
@@ -1266,14 +1190,10 @@ std::string& output)
return true;
}
-SWIGEXPORT bool
-LLDBSWIGPythonRunScriptKeywordValue
-(const char* python_function_name,
-const char* session_dictionary_name,
-lldb::ValueObjectSP& value,
-std::string& output)
+bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue(
+ const char *python_function_name, const char *session_dictionary_name,
+ const lldb::ValueObjectSP &value, std::string &output) {
-{
if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
return false;
@@ -1285,17 +1205,15 @@ std::string& output)
if (!pfunc.IsAllocated())
return false;
- lldb::SBValue value_sb(value);
- PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(value_sb));
- auto result = pfunc(value_arg, dict);
+ auto result = pfunc(ToSWIGWrapper(value), dict);
output = result.Str().GetString().str();
return true;
}
-SWIGEXPORT bool
-LLDBSwigPythonCallModuleInit
+bool
+lldb_private::LLDBSwigPythonCallModuleInit
(
const char *python_module_name,
const char *session_dictionary_name,
@@ -1322,16 +1240,9 @@ LLDBSwigPythonCallModuleInit
return true;
}
-%}
-
-
-%runtime %{
-// Forward declaration to be inserted at the start of LLDBWrapPython.h
-#include "lldb/API/SBDebugger.h"
-#include "lldb/API/SBValue.h"
-SWIGEXPORT lldb::ValueObjectSP
-LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data)
+lldb::ValueObjectSP
+lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data)
{
lldb::ValueObjectSP valobj_sp;
if (data)
@@ -1342,22 +1253,8 @@ LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data)
return valobj_sp;
}
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton);
-
-#ifdef __cplusplus
-}
-#endif
-%}
-
-%wrapper %{
-
-
// For the LogOutputCallback functions
-void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) {
+static void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) {
if (baton != Py_None) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyObject *result = PyObject_CallFunction(reinterpret_cast<PyObject*>(baton), const_cast<char*>("s"), str);