summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r--lldb/scripts/Python/interface/SBDebugger.i6
-rw-r--r--lldb/scripts/Python/python-extensions.swig10
-rw-r--r--lldb/scripts/Python/python-typemaps.swig37
-rw-r--r--lldb/scripts/Python/python-wrapper.swig70
4 files changed, 91 insertions, 32 deletions
diff --git a/lldb/scripts/Python/interface/SBDebugger.i b/lldb/scripts/Python/interface/SBDebugger.i
index 883ed1c5fb5..a27d280de7e 100644
--- a/lldb/scripts/Python/interface/SBDebugger.i
+++ b/lldb/scripts/Python/interface/SBDebugger.i
@@ -122,6 +122,9 @@ public:
static lldb::SBDebugger
Create(bool source_init_files);
+ static lldb::SBDebugger
+ Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton);
+
static void
Destroy (lldb::SBDebugger &debugger);
@@ -272,6 +275,9 @@ public:
EnableLog (const char *channel, const char ** types);
void
+ SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
+
+ void
DispatchInput (const void *data, size_t data_len);
void
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index 24f06a189f7..da70f205059 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -484,6 +484,15 @@
}
}
+
+// %extend lldb::SBDebugger {
+// // FIXME: We can't get the callback and baton
+// PyObject *lldb::SBDebugger (){
+// // Only call Py_XDECREF if we have a Python object (or NULL)
+// if (LLDBSwigPythonCallPythonLogOutputCallback == $self->GetLogOutPutCallback())
+// Py_XDECREF($self->GetCallbackBaton());
+// }
+// }
// %extend lldb::SBInputReader {
// // FIXME: m_callback_function is private and we have no other
// // way to access it.
@@ -686,4 +695,3 @@ class value(object):
def __neq__(self, other):
return not self.__eq__(other)
%}
-
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index e212d3f4c69..563c9e98921 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -352,11 +352,16 @@
// For lldb::SBInputReader::Callback
%typemap(in) (lldb::SBInputReader::Callback callback, void *callback_baton) {
- if (!PyCallable_Check(reinterpret_cast<PyObject*>($input))) {
- PyErr_SetString(PyExc_TypeError, "Need a callable object!");
+ if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
+ PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
return NULL;
}
+ // FIXME (filcab): We can't currently check if our callback is already
+ // LLDBSwigPythonCallPythonLogOutputCallback (to DECREF the previous
+ // baton) nor can we just remove all traces of a callback, if we want to
+ // revert to a file logging mechanism.
+
// Don't lose the callback reference
Py_INCREF($input);
$1 = LLDBSwigPythonCallSBInputReaderCallback;
@@ -364,7 +369,33 @@
}
%typemap(typecheck) (lldb::SBInputReader::Callback callback, void *baton) {
- if (!PyCallable_Check(reinterpret_cast<PyObject*>($input))) {
+ if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
+ $1 = 0;
+ } else {
+ $1 = 1;
+ }
+}
+
+// For Log::LogOutputCallback
+%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
+ if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
+ PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
+ return NULL;
+ }
+
+ // FIXME (filcab): We can't currently check if our callback is already
+ // LLDBSwigPythonCallPythonLogOutputCallback (to DECREF the previous
+ // baton) nor can we just remove all traces of a callback, if we want to
+ // revert to a file logging mechanism.
+
+ // Don't lose the callback reference
+ Py_INCREF($input);
+ $1 = LLDBSwigPythonCallPythonLogOutputCallback;
+ $2 = $input;
+}
+
+%typemap(typecheck) (lldb::LogOutputCallback log_callback, void *baton) {
+ if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
$1 = 0;
} else {
$1 = 1;
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;
+ }
}
%}
OpenPOWER on IntegriCloud