diff options
author | Filipe Cabecinhas <me@filcab.net> | 2012-08-25 00:29:07 +0000 |
---|---|---|
committer | Filipe Cabecinhas <me@filcab.net> | 2012-08-25 00:29:07 +0000 |
commit | c5041918dda38fbb480ce73da2784ae4765171d3 (patch) | |
tree | ea75625abea7c97cddbbd150967d006b50dbb230 /lldb/scripts/Python/python-wrapper.swig | |
parent | de70e0ef454ce294b5526815e8ce657aa6806bff (diff) | |
download | bcm5719-llvm-c5041918dda38fbb480ce73da2784ae4765171d3.tar.gz bcm5719-llvm-c5041918dda38fbb480ce73da2784ae4765171d3.zip |
Added SBDebugger's log callbacks to Python-land
- Tweaked a parameter name in SBDebugger.h so my typemap will catch it;
- Added a SBDebugger.Create(bool, callback, baton) to the swig interface;
- Added SBDebugger.SetLoggingCallback to the swig interface;
- Added a callback utility function for log callbacks;
- Guard against Py_None on both callback utility functions;
- Added a FIXME to the SBDebugger API test;
- Added a __del__() stub for SBDebugger.
We need to be able to get both the log callback and baton from an
SBDebugger if we want to protect against memory leaks (or make the user
responsible for holding another reference to the callback).
Additionally, it's impossible to revert from a callback-backed log
mechanism to a file-backed log mechanism.
llvm-svn: 162633
Diffstat (limited to 'lldb/scripts/Python/python-wrapper.swig')
-rw-r--r-- | lldb/scripts/Python/python-wrapper.swig | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index 1acbe277d3d..ea8fb29750d 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -929,6 +929,7 @@ LLDBSwigPythonCallModuleInit // This is needed to use LLDBSwigPythonCallSBInputReaderCallback in the // typemaps and in the extensions (SBInputReader.__del__()). #include "lldb/API/SBInputReader.h" +#include "lldb/API/SBDebugger.h" size_t LLDBSwigPythonCallSBInputReaderCallback(void *baton, @@ -936,6 +937,8 @@ LLDBSwigPythonCallSBInputReaderCallback(void *baton, lldb::InputReaderAction notification, const char*bytes, size_t bytes_len); + +void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton); %} %wrapper %{ @@ -946,35 +949,46 @@ LLDBSwigPythonCallSBInputReaderCallback(void *baton, lldb::InputReaderAction notification, const char*bytes, size_t bytes_len) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - - PyObject *py_InputReader = SWIG_NewPointerObj(reader, SWIGTYPE_p_lldb__SBInputReader, false); - PyObject *py_Notification = PyInt_FromLong(notification); - PyObject *py_Bytes = PyBytes_FromStringAndSize(bytes, bytes_len); - - PyObject *tuple = PyTuple_Pack(3, py_InputReader, py_Notification, py_Bytes); - PyObject *res = PyObject_Call(reinterpret_cast<PyObject*>(baton), tuple, NULL); - Py_DECREF(tuple); - Py_DECREF(py_InputReader); - Py_DECREF(py_Notification); - Py_DECREF(py_Bytes); - - if (res == NULL) { - PyObject *exc = PyErr_Occurred(); - if (exc) { - ::puts("\nErroring out at LLDBSwigPythonCallSBInputReaderCallback"); - PyErr_Print(); - } - return 0; + if (baton != Py_None) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + + PyObject *py_InputReader = SWIG_NewPointerObj(reader, SWIGTYPE_p_lldb__SBInputReader, false); + PyObject *py_Notification = PyInt_FromLong(notification); + PyObject *py_Bytes = PyBytes_FromStringAndSize(bytes, bytes_len); + + PyObject *tuple = PyTuple_Pack(3, py_InputReader, py_Notification, py_Bytes); + PyObject *res = PyObject_Call(reinterpret_cast<PyObject*>(baton), tuple, NULL); + Py_DECREF(tuple); + Py_DECREF(py_InputReader); + Py_DECREF(py_Notification); + Py_DECREF(py_Bytes); + + if (res == NULL) { + PyObject *exc = PyErr_Occurred(); + if (exc) { + ::puts("\nErroring out at LLDBSwigPythonCallSBInputReaderCallback"); + PyErr_Print(); + } + return 0; + } + + size_t result = 0; + // If the callback misbehaves and returns Py_None, assume it returned 0 + if (res != Py_None) + result = static_cast<size_t>(PyInt_AsSsize_t(res)); + + Py_DECREF(res); + SWIG_PYTHON_THREAD_END_BLOCK; + return result; } +} - size_t result = 0; - // If the callback misbehaves and returns Py_None, assume it returned 0 - if (res != Py_None) - result = static_cast<size_t>(PyInt_AsSsize_t(res)); - - Py_DECREF(res); - SWIG_PYTHON_THREAD_END_BLOCK; - return result; +// For the LogOutputCallback functions +void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) { + if (baton != Py_None) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyObject_CallFunction(reinterpret_cast<PyObject*>(baton), const_cast<char*>("s"), str); + SWIG_PYTHON_THREAD_END_BLOCK; + } } %} |