Very large changes that were needed in order to allow multiple connections
to the debugger from GUI windows. Previously there was one global debugger
instance that could be accessed that had its own command interpreter and
current state (current target/process/thread/frame). When a GUI debugger
was attached, if it opened more than one window that each had a console
window, there were issues where the last one to setup the global debugger
object won and got control of the debugger.

To avoid this we now create instances of the lldb_private::Debugger that each 
has its own state:
- target list for targets the debugger instance owns
- current process/thread/frame
- its own command interpreter
- its own input, output and error file handles to avoid conflicts
- its own input reader stack

So now clients should call:

    SBDebugger::Initialize(); // (static function)

    SBDebugger debugger (SBDebugger::Create());
    // Use which ever file handles you wish
    debugger.SetErrorFileHandle (stderr, false);
    debugger.SetOutputFileHandle (stdout, false);
    debugger.SetInputFileHandle (stdin, true);

    // main loop
    
    SBDebugger::Terminate(); // (static function)
    
SBDebugger::Initialize() and SBDebugger::Terminate() are ref counted to
ensure nothing gets destroyed too early when multiple clients might be
attached.

Cleaned up the command interpreter and the CommandObject and all subclasses
to take more appropriate arguments.

llvm-svn: 106615
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 6e4efbf..38534f0 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -21,7 +21,8 @@
 #include "lldb/Expression/ClangExpressionVariable.h"
 #include "lldb/Expression/DWARFExpression.h"
 #include "lldb/Host/Host.h"
-#include "lldb/Interpreter/CommandContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Variable.h"
@@ -124,9 +125,8 @@
 bool
 CommandObjectExpression::Execute
 (
+    CommandInterpreter &interpreter,
     Args& command,
-    CommandContext *context,
-    CommandInterpreter *interpreter,
     CommandReturnObject &result
 )
 {
@@ -138,24 +138,22 @@
 CommandObjectExpression::MultiLineExpressionCallback
 (
     void *baton, 
-    InputReader *reader, 
+    InputReader &reader, 
     lldb::InputReaderAction notification,
     const char *bytes, 
     size_t bytes_len
 )
 {
-    FILE *out_fh = Debugger::GetSharedInstance().GetOutputFileHandle();
     CommandObjectExpression *cmd_object_expr = (CommandObjectExpression *) baton;
 
     switch (notification)
     {
     case eInputReaderActivate:
-        if (out_fh)
-            ::fprintf (out_fh, "%s\n", "Enter expressions, then terminate with an empty line to evaluate:");
+        reader.GetDebugger().GetOutputStream().Printf("%s\n", "Enter expressions, then terminate with an empty line to evaluate:");
         // Fall through
     case eInputReaderReactivate:
         //if (out_fh)
-        //    ::fprintf (out_fh, "%3u: ", cmd_object_expr->m_expr_line_count);
+        //    reader.GetDebugger().GetOutputStream().Printf ("%3u: ", cmd_object_expr->m_expr_line_count);
         break;
 
     case eInputReaderDeactivate:
@@ -169,20 +167,18 @@
         }
 
         if (bytes_len == 0)
-            reader->SetIsDone(true);
+            reader.SetIsDone(true);
         //else if (out_fh && !reader->IsDone())
         //    ::fprintf (out_fh, "%3u: ", cmd_object_expr->m_expr_line_count);
         break;
         
     case eInputReaderDone:
         {
-            StreamFile out_stream(Debugger::GetSharedInstance().GetOutputFileHandle());
-            StreamFile err_stream(Debugger::GetSharedInstance().GetErrorFileHandle());
             bool bare = false;
             cmd_object_expr->EvaluateExpression (cmd_object_expr->m_expr_lines.c_str(), 
                                                  bare, 
-                                                 out_stream, 
-                                                 err_stream);
+                                                 reader.GetDebugger().GetOutputStream(), 
+                                                 reader.GetDebugger().GetErrorStream());
         }
         break;
     }
@@ -329,21 +325,20 @@
 bool
 CommandObjectExpression::ExecuteRawCommandString
 (
+    CommandInterpreter &interpreter,
     const char *command,
-    CommandContext *context,
-    CommandInterpreter *interpreter,
     CommandReturnObject &result
 )
 {
     ConstString target_triple;
-    Target *target = context->GetTarget ();
+    Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
     if (target)
         target->GetTargetTriple(target_triple);
 
     if (!target_triple)
         target_triple = Host::GetTargetTriple ();
 
-    ExecutionContext exe_ctx(context->GetExecutionContext());
+    ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
 
     Stream &output_stream = result.GetOutputStream();
 
@@ -356,18 +351,18 @@
         m_expr_lines.clear();
         m_expr_line_count = 0;
         
-        InputReaderSP reader_sp (new InputReader());
+        InputReaderSP reader_sp (new InputReader(interpreter.GetDebugger()));
         if (reader_sp)
         {
             Error err (reader_sp->Initialize (CommandObjectExpression::MultiLineExpressionCallback,
                                               this,                         // baton
                                               eInputReaderGranularityLine,  // token size, to pass to callback function
-                                              NULL,                       // end token
+                                              NULL,                         // end token
                                               NULL,                         // prompt
                                               true));                       // echo input
             if (err.Success())
             {
-                Debugger::GetSharedInstance().PushInputReader (reader_sp);
+                interpreter.GetDebugger().PushInputReader (reader_sp);
                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
             }
             else
@@ -408,8 +403,8 @@
 
         if (end_options)
         {
-            Args args(command, end_options - command);
-            if (!ParseOptions(args, interpreter, result))
+            Args args (command, end_options - command);
+            if (!ParseOptions (interpreter, args, result))
                 return false;
         }
     }