Merging the iohandler branch back into main. 

The many many benefits include:
1 - Input/Output/Error streams are now handled as real streams not a push style input
2 - auto completion in python embedded interpreter
3 - multi-line input for "script" and "expression" commands now allow you to edit previous/next lines using up and down arrow keys and this makes multi-line input actually a viable thing to use
4 - it is now possible to use curses to drive LLDB (please try the "gui" command)

We will need to deal with and fix any buildbot failures and tests and arise now that input/output and error are correctly hooked up in all cases.

llvm-svn: 200263
diff --git a/lldb/scripts/Python/build-swig-Python.sh b/lldb/scripts/Python/build-swig-Python.sh
index c424c06..34a1ff2 100755
--- a/lldb/scripts/Python/build-swig-Python.sh
+++ b/lldb/scripts/Python/build-swig-Python.sh
@@ -99,7 +99,6 @@
 " ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
 " ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
 " ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
-" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
 " ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
 " ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
 " ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
@@ -147,7 +146,6 @@
 " ${SRC_ROOT}/scripts/Python/interface/SBFrame.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBFunction.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBHostOS.i"\
-" ${SRC_ROOT}/scripts/Python/interface/SBInputReader.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBInstruction.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBInstructionList.i"\
 " ${SRC_ROOT}/scripts/Python/interface/SBLineEntry.i"\
diff --git a/lldb/scripts/Python/interface/SBCommandInterpreter.i b/lldb/scripts/Python/interface/SBCommandInterpreter.i
index 4cf3d22..9dc842e 100644
--- a/lldb/scripts/Python/interface/SBCommandInterpreter.i
+++ b/lldb/scripts/Python/interface/SBCommandInterpreter.i
@@ -78,6 +78,9 @@
     bool
     IsValid() const;
 
+    const char *
+    GetIOHandlerControlSequence(char ch);
+
     bool
     CommandExists (const char *cmd);
 
@@ -120,6 +123,10 @@
                       int match_start_point,
                       int max_return_elements,
                       lldb::SBStringList &matches);
+    
+    bool
+    IsActive ();
+
 };
 
 } // namespace lldb
diff --git a/lldb/scripts/Python/interface/SBDebugger.i b/lldb/scripts/Python/interface/SBDebugger.i
index 6d075ac..ba1c189 100644
--- a/lldb/scripts/Python/interface/SBDebugger.i
+++ b/lldb/scripts/Python/interface/SBDebugger.i
@@ -292,15 +292,6 @@
     void
     DispatchInputEndOfFile ();
     
-    void
-    PushInputReader (lldb::SBInputReader &reader);
-
-    void
-    NotifyTopInputReader (lldb::InputReaderAction notification);
-
-    bool
-    InputReaderIsTopReader (const lldb::SBInputReader &reader);
-
     const char *
     GetInstanceName  ();
 
@@ -372,7 +363,11 @@
 
     lldb::SBTypeSynthetic
     GetSyntheticForType (lldb::SBTypeNameSpecifier);
-                
+    
+    void
+    RunCommandInterpreter (bool auto_handle_events,
+                           bool spawn_thread);
+
 }; // class SBDebugger
 
 } // namespace lldb
diff --git a/lldb/scripts/Python/interface/SBInputReader.i b/lldb/scripts/Python/interface/SBInputReader.i
deleted file mode 100644
index 9398624..0000000
--- a/lldb/scripts/Python/interface/SBInputReader.i
+++ /dev/null
@@ -1,53 +0,0 @@
-//===-- SWIG Interface for SBInputREader ------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-namespace lldb {
-
-class SBInputReader
-{
-public:
-
-    typedef size_t (*Callback) (void *baton, 
-                                SBInputReader *reader, 
-                                InputReaderAction notification,
-                                const char *bytes, 
-                                size_t bytes_len);
-
-    SBInputReader ();
-
-    SBInputReader (const lldb::SBInputReader &rhs);
-
-    ~SBInputReader ();
-
-    SBError
-    Initialize (SBDebugger &debugger,
-                Callback callback,
-                void *callback_baton,
-                lldb::InputReaderGranularity granularity,
-                const char *end_token,
-                const char *prompt,
-                bool echo);
-    
-    bool
-    IsValid () const;
-
-    bool
-    IsActive () const;
-
-    bool
-    IsDone () const;
-
-    void
-    SetIsDone (bool value);
-
-    InputReaderGranularity
-    GetGranularity ();
-};
-
-} // namespace lldb
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index c4bc8b9..3dbcb88 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -777,15 +777,6 @@
 //                 Py_XDECREF($self->GetCallbackBaton());
 //         }
 // }
-// %extend lldb::SBInputReader {
-//         // FIXME: m_callback_function is private and we have no other
-//         // way to access it.
-//         PyObject *lldb::SBInputReader::__del__ (){
-//             // Only call Py_XDECREF if we have a Python object (or NULL)
-//             if (LLDBSwigPythonCallSBInputReaderCallback == $self->m_callback_function)
-//                 Py_XDECREF($self->m_callback_baton);
-//         }
-// }
 
 %pythoncode %{
 
diff --git a/lldb/scripts/Python/python-swigsafecast.swig b/lldb/scripts/Python/python-swigsafecast.swig
index da7444c..0150854 100644
--- a/lldb/scripts/Python/python-swigsafecast.swig
+++ b/lldb/scripts/Python/python-swigsafecast.swig
@@ -112,10 +112,3 @@
 {
     return SWIG_NewPointerObj((void *) cmd_ret_obj_sb, SWIGTYPE_p_lldb__SBCommandReturnObject, 0);
 }
-
-template <>
-PyObject*
-SBTypeToSWIGWrapper (lldb::SBInputReader* input_reader_sb)
-{
-    return SWIG_NewPointerObj((void *) input_reader_sb, SWIGTYPE_p_lldb__SBInputReader, 0);
-}
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index 24bb2b8..7a6e0d3 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -355,28 +355,6 @@
     free($1);
 }
 
-// For lldb::SBInputReader::Callback
-%typemap(in) (lldb::SBInputReader::Callback callback, void *callback_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 = LLDBSwigPythonCallSBInputReaderCallback;
-  $2 = $input;
-}
-
-%typemap(typecheck) (lldb::SBInputReader::Callback callback, void *baton) {
-  $1 = $input == Py_None;
-  $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject*>($input));
-}
 
 // For Log::LogOutputCallback
 %typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig
index addfa29..d28f0cda 100644
--- a/lldb/scripts/Python/python-wrapper.swig
+++ b/lldb/scripts/Python/python-wrapper.swig
@@ -929,10 +929,6 @@
 
 %runtime %{
 // Forward declaration to be inserted at the start of LLDBWrapPython.h
-// I used runtime as a hack to make SWIG place it where it's needed.
-// 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"
 #include "lldb/API/SBValue.h"
  
@@ -952,13 +948,6 @@
 extern "C" {
 #endif
 
-size_t
-LLDBSwigPythonCallSBInputReaderCallback(void *baton,
-                                        lldb::SBInputReader *reader,
-                                        lldb::InputReaderAction notification,
-                                        const char*bytes,
-                                        size_t bytes_len);
-
 void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton);
 
 #ifdef __cplusplus
@@ -967,47 +956,7 @@
 %}
 
 %wrapper %{
-// For the InputReader Callback functions
-SWIGEXPORT size_t
-LLDBSwigPythonCallSBInputReaderCallback(void *baton,
-                                        lldb::SBInputReader *reader,
-                                        lldb::InputReaderAction notification,
-                                        const char*bytes,
-                                        size_t bytes_len) {
-    if (baton != Py_None) {
-        SWIG_PYTHON_THREAD_BEGIN_BLOCK;
-    
-        PyObject *py_InputReader = SBTypeToSWIGWrapper(reader);
-        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_XDECREF(tuple);
-        Py_XDECREF(py_InputReader);
-        Py_XDECREF(py_Notification);
-        Py_XDECREF(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_XDECREF(res);
-        SWIG_PYTHON_THREAD_END_BLOCK;
-        return result;
-    }
-    return 0;
-}
+
 
 // For the LogOutputCallback functions
 void LLDBSwigPythonCallPythonLogOutputCallback(const char *str, void *baton) {
diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig
index d53ba8b..8633f15 100644
--- a/lldb/scripts/lldb.swig
+++ b/lldb/scripts/lldb.swig
@@ -72,7 +72,6 @@
 #include "lldb/API/SBFrame.h"
 #include "lldb/API/SBFunction.h"
 #include "lldb/API/SBHostOS.h"
-#include "lldb/API/SBInputReader.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBInstructionList.h"
 #include "lldb/API/SBLineEntry.h"
@@ -139,7 +138,6 @@
 %include "./Python/interface/SBFrame.i"
 %include "./Python/interface/SBFunction.i"
 %include "./Python/interface/SBHostOS.i"
-%include "./Python/interface/SBInputReader.i"
 %include "./Python/interface/SBInstruction.i"
 %include "./Python/interface/SBInstructionList.i"
 %include "./Python/interface/SBLineEntry.i"