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.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@106615 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandCompletions.cpp b/source/Commands/CommandCompletions.cpp
index f2bf7da..5d42229 100644
--- a/source/Commands/CommandCompletions.cpp
+++ b/source/Commands/CommandCompletions.cpp
@@ -33,13 +33,16 @@
 };
 
 bool
-CommandCompletions::InvokeCommonCompletionCallbacks (uint32_t completion_mask,
-                                                const char *completion_str,
-                                                int match_start_point,
-                                                int max_return_elements,
-                                                lldb_private::CommandInterpreter *interpreter,
-                                                SearchFilter *searcher,
-                                                lldb_private::StringList &matches)
+CommandCompletions::InvokeCommonCompletionCallbacks 
+(
+    CommandInterpreter &interpreter,
+    uint32_t completion_mask,
+    const char *completion_str,
+    int match_start_point,
+    int max_return_elements,
+    SearchFilter *searcher,
+    StringList &matches
+)
 {
     bool handled = false;
 
@@ -54,10 +57,10 @@
                    && g_common_completions[i].callback != NULL)
          {
             handled = true;
-            g_common_completions[i].callback (completion_str,
+            g_common_completions[i].callback (interpreter,
+                                              completion_str,
                                               match_start_point,
                                               max_return_elements,
-                                              interpreter,
                                               searcher,
                                               matches);
         }
@@ -66,20 +69,27 @@
 }
 
 int
-CommandCompletions::SourceFiles (const char *partial_file_name,
-                    int match_start_point,
-                    int max_return_elements,
-                    lldb_private::CommandInterpreter *interpreter,
-                    SearchFilter *searcher,
-                    lldb_private::StringList &matches)
+CommandCompletions::SourceFiles 
+(
+    CommandInterpreter &interpreter,
+    const char *partial_file_name,
+    int match_start_point,
+    int max_return_elements,
+    SearchFilter *searcher,
+    StringList &matches
+)
 {
     // Find some way to switch "include support files..."
-    SourceFileCompleter completer (false, partial_file_name, match_start_point, max_return_elements, interpreter,
+    SourceFileCompleter completer (interpreter,
+                                   false, 
+                                   partial_file_name, 
+                                   match_start_point, 
+                                   max_return_elements,
                                    matches);
 
     if (searcher == NULL)
     {
-        lldb::TargetSP target_sp = interpreter->Context()->GetTarget()->GetSP();
+        lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
         SearchFilter null_searcher (target_sp);
         completer.DoCompletion (&null_searcher);
     }
@@ -91,18 +101,25 @@
 }
 
 int
-CommandCompletions::Modules (const char *partial_file_name,
-                    int match_start_point,
-                    int max_return_elements,
-                    lldb_private::CommandInterpreter *interpreter,
-                    SearchFilter *searcher,
-                    lldb_private::StringList &matches)
+CommandCompletions::Modules 
+(
+    CommandInterpreter &interpreter,
+    const char *partial_file_name,
+    int match_start_point,
+    int max_return_elements,
+    SearchFilter *searcher,
+    StringList &matches
+)
 {
-    ModuleCompleter completer(partial_file_name, match_start_point, max_return_elements, interpreter, matches);
-
+    ModuleCompleter completer (interpreter,
+                               partial_file_name, 
+                               match_start_point, 
+                               max_return_elements, 
+                               matches);
+    
     if (searcher == NULL)
     {
-        lldb::TargetSP target_sp = interpreter->Context()->GetTarget()->GetSP();
+        lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
         SearchFilter null_searcher (target_sp);
         completer.DoCompletion (&null_searcher);
     }
@@ -114,18 +131,24 @@
 }
 
 int
-CommandCompletions::Symbols (const char *partial_file_name,
-                    int match_start_point,
-                    int max_return_elements,
-                    lldb_private::CommandInterpreter *interpreter,
-                    SearchFilter *searcher,
-                    lldb_private::StringList &matches)
+CommandCompletions::Symbols 
+(
+    CommandInterpreter &interpreter,
+    const char *partial_file_name,
+    int match_start_point,
+    int max_return_elements,
+    SearchFilter *searcher,
+    StringList &matches)
 {
-    SymbolCompleter completer(partial_file_name, match_start_point, max_return_elements, interpreter, matches);
+    SymbolCompleter completer (interpreter,
+                               partial_file_name, 
+                               match_start_point, 
+                               max_return_elements, 
+                               matches);
 
     if (searcher == NULL)
     {
-        lldb::TargetSP target_sp = interpreter->Context()->GetTarget()->GetSP();
+        lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
         SearchFilter null_searcher (target_sp);
         completer.DoCompletion (&null_searcher);
     }
@@ -136,17 +159,18 @@
     return matches.GetSize();
 }
 
-CommandCompletions::Completer::Completer (
+CommandCompletions::Completer::Completer 
+(
+    CommandInterpreter &interpreter,
     const char *completion_str,
     int match_start_point,
     int max_return_elements,
-    CommandInterpreter *interpreter,
     StringList &matches
 ) :
+    m_interpreter (interpreter),
     m_completion_str (completion_str),
     m_match_start_point (match_start_point),
     m_max_return_elements (max_return_elements),
-    m_interpreter (interpreter),
     m_matches (matches)
 {
 }
@@ -160,15 +184,16 @@
 // SourceFileCompleter
 //----------------------------------------------------------------------
 
-CommandCompletions::SourceFileCompleter::SourceFileCompleter (
+CommandCompletions::SourceFileCompleter::SourceFileCompleter 
+(
+    CommandInterpreter &interpreter,
     bool include_support_files,
     const char *completion_str,
     int match_start_point,
     int max_return_elements,
-    CommandInterpreter *interpreter,
     StringList &matches
 ) :
-    CommandCompletions::Completer (completion_str, match_start_point, max_return_elements, interpreter, matches),
+    CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches),
     m_include_support_files (include_support_files),
     m_matching_files()
 {
@@ -264,14 +289,15 @@
     else
         return false;
 }
-CommandCompletions::SymbolCompleter::SymbolCompleter (
+CommandCompletions::SymbolCompleter::SymbolCompleter 
+(
+    CommandInterpreter &interpreter,
     const char *completion_str,
     int match_start_point,
     int max_return_elements,
-    CommandInterpreter *interpreter,
     StringList &matches
 ) :
-    CommandCompletions::Completer (completion_str, match_start_point, max_return_elements, interpreter, matches)
+    CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches)
 {
     std::string regex_str ("^");
     regex_str.append(completion_str);
@@ -353,14 +379,15 @@
 //----------------------------------------------------------------------
 // ModuleCompleter
 //----------------------------------------------------------------------
-CommandCompletions::ModuleCompleter::ModuleCompleter (
+CommandCompletions::ModuleCompleter::ModuleCompleter 
+(
+    CommandInterpreter &interpreter,
     const char *completion_str,
     int match_start_point,
     int max_return_elements,
-    CommandInterpreter *interpreter,
     StringList &matches
 ) :
-    CommandCompletions::Completer (completion_str, match_start_point, max_return_elements, interpreter, matches)
+    CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches)
 {
     FileSpec partial_spec (m_completion_str.c_str());
     m_file_name = partial_spec.GetFilename().GetCString();