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/CommandObjectMultiword.cpp b/source/Commands/CommandObjectMultiword.cpp
index b5553d6..d8e8f54 100644
--- a/source/Commands/CommandObjectMultiword.cpp
+++ b/source/Commands/CommandObjectMultiword.cpp
@@ -12,7 +12,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Interpreter/CommandContext.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -80,8 +80,12 @@
 }
 
 bool
-CommandObjectMultiword::LoadSubCommand (CommandObjectSP cmd_obj, const char *name,
-                                          CommandInterpreter *interpreter)
+CommandObjectMultiword::LoadSubCommand 
+(
+    CommandInterpreter &interpreter, 
+    const char *name,
+    const CommandObjectSP& cmd_obj
+)
 {
     CommandMap::iterator pos;
     bool success = true;
@@ -90,7 +94,7 @@
     if (pos == m_subcommand_dict.end())
     {
         m_subcommand_dict[name] = cmd_obj;
-        interpreter->CrossRegisterCommand (name, GetCommandName());
+        interpreter.CrossRegisterCommand (name, GetCommandName());
     }
     else
         success = false;
@@ -101,16 +105,15 @@
 bool
 CommandObjectMultiword::Execute
 (
+    CommandInterpreter &interpreter,
     Args& args,
-    CommandContext *context,
-    CommandInterpreter *interpreter,
     CommandReturnObject &result
 )
 {
     const size_t argc = args.GetArgumentCount();
     if (argc == 0)
     {
-        GenerateHelpText (result, interpreter);
+        GenerateHelpText (interpreter, result);
     }
     else
     {
@@ -120,7 +123,7 @@
         {
             if (::strcasecmp (sub_command, "help") == 0)
             {
-                GenerateHelpText (result, interpreter);
+                GenerateHelpText (interpreter, result);
             }
             else if (!m_subcommand_dict.empty())
             {
@@ -133,7 +136,7 @@
 
                     args.Shift();
 
-                    sub_cmd_obj->ExecuteWithOptions (args, context, interpreter, result);
+                    sub_cmd_obj->ExecuteWithOptions (interpreter, args, result);
                 }
                 else
                 {
@@ -176,7 +179,7 @@
 }
 
 void
-CommandObjectMultiword::GenerateHelpText (CommandReturnObject &result, CommandInterpreter *interpreter)
+CommandObjectMultiword::GenerateHelpText (CommandInterpreter &interpreter, CommandReturnObject &result)
 {
     // First time through here, generate the help text for the object and
     // push it to the return result object as well
@@ -185,7 +188,7 @@
     output_stream.PutCString ("The following subcommands are supported:\n\n");
 
     CommandMap::iterator pos;
-    std::string longest_word = interpreter->FindLongestCommandWord (m_subcommand_dict);
+    std::string longest_word = interpreter.FindLongestCommandWord (m_subcommand_dict);
     uint32_t max_len = 0;
 
     if (! longest_word.empty())
@@ -195,8 +198,11 @@
     {
         std::string indented_command ("    ");
         indented_command.append (pos->first);
-        interpreter->OutputFormattedHelpText (result.GetOutputStream(), indented_command.c_str(), "--", 
-                                              pos->second->GetHelp(), max_len);
+        interpreter.OutputFormattedHelpText (result.GetOutputStream(), 
+                                             indented_command.c_str(),
+                                             "--", 
+                                             pos->second->GetHelp(), 
+                                             max_len);
     }
 
     output_stream.PutCString ("\nFor more help on any particular subcommand, type 'help <command> <subcommand>'.\n");
@@ -207,33 +213,40 @@
 int
 CommandObjectMultiword::HandleCompletion
 (
+    CommandInterpreter &interpreter,
     Args &input,
     int &cursor_index,
     int &cursor_char_position,
     int match_start_point,
     int max_return_elements,
-    CommandInterpreter *interpreter,
     StringList &matches
 )
 {
     if (cursor_index == 0)
     {
-        CommandObject::AddNamesMatchingPartialString (m_subcommand_dict, input.GetArgumentAtIndex(0), matches);
+        CommandObject::AddNamesMatchingPartialString (m_subcommand_dict, 
+                                                      input.GetArgumentAtIndex(0), 
+                                                      matches);
 
         if (matches.GetSize() == 1
             && matches.GetStringAtIndex(0) != NULL
             && strcmp (input.GetArgumentAtIndex(0), matches.GetStringAtIndex(0)) == 0)
         {
             StringList temp_matches;
-            CommandObject *cmd_obj = GetSubcommandObject (input.GetArgumentAtIndex(0), &temp_matches);
+            CommandObject *cmd_obj = GetSubcommandObject (input.GetArgumentAtIndex(0), 
+                                                          &temp_matches);
             if (cmd_obj != NULL)
             {
                 matches.DeleteStringAtIndex (0);
                 input.Shift();
                 cursor_char_position = 0;
                 input.AppendArgument ("");
-                return cmd_obj->HandleCompletion (input, cursor_index, cursor_char_position, match_start_point,
-                                                  max_return_elements, interpreter, matches);
+                return cmd_obj->HandleCompletion (interpreter, 
+                                                  input, cursor_index, 
+                                                  cursor_char_position, 
+                                                  match_start_point,
+                                                  max_return_elements, 
+                                                  matches);
             }
             else
                 return matches.GetSize();
@@ -243,7 +256,8 @@
     }
     else
     {
-        CommandObject *sub_command_object = GetSubcommandObject (input.GetArgumentAtIndex(0), &matches);
+        CommandObject *sub_command_object = GetSubcommandObject (input.GetArgumentAtIndex(0), 
+                                                                 &matches);
         if (sub_command_object == NULL)
         {
             return matches.GetSize();
@@ -254,8 +268,13 @@
             matches.DeleteStringAtIndex(0);
             input.Shift();
             cursor_index--;
-            return sub_command_object->HandleCompletion (input, cursor_index, cursor_char_position, match_start_point,
-                                                         max_return_elements, interpreter, matches);
+            return sub_command_object->HandleCompletion (interpreter, 
+                                                         input, 
+                                                         cursor_index, 
+                                                         cursor_char_position, 
+                                                         match_start_point,
+                                                         max_return_elements, 
+                                                         matches);
         }
 
     }