Fixed the way set/show variables were being accessed to being natively 
accessed by the objects that own the settings. The previous approach wasn't
very usable and made for a lot of unnecessary code just to access variables
that were already owned by the objects.

While I fixed those things, I saw that CommandObject objects should really
have a reference to their command interpreter so they can access the terminal
with if they want to output usaage. Fixed up all CommandObjects to take
an interpreter and cleaned up the API to not need the interpreter to be
passed in.

Fixed the disassemble command to output the usage if no options are passed
down and arguments are passed (all disassebmle variants take options, there
are no "args only").



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@114252 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index 8562206..48176f7 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -149,29 +149,30 @@
     bool success;
     script_language = Args::StringToScriptLanguage (value.GetStringAtIndex(0), lldb::eScriptLanguageDefault, &success);
     
-    m_command_dict["apropos"]   = CommandObjectSP (new CommandObjectApropos ());
+    m_command_dict["apropos"]   = CommandObjectSP (new CommandObjectApropos (*this));
     m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (*this));
-    //m_command_dict["call"]      = CommandObjectSP (new CommandObjectCall ());
+    //m_command_dict["call"]      = CommandObjectSP (new CommandObjectCall (*this));
     m_command_dict["commands"]  = CommandObjectSP (new CommandObjectMultiwordCommands (*this));
-    m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble ());
-    m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression ());
-    m_command_dict["file"]      = CommandObjectSP (new CommandObjectFile ());
+    m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble (*this));
+    m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression (*this));
+    m_command_dict["file"]      = CommandObjectSP (new CommandObjectFile (*this));
     m_command_dict["frame"]     = CommandObjectSP (new CommandObjectMultiwordFrame (*this));
-    m_command_dict["help"]      = CommandObjectSP (new CommandObjectHelp ());
+    m_command_dict["help"]      = CommandObjectSP (new CommandObjectHelp (*this));
     m_command_dict["image"]     = CommandObjectSP (new CommandObjectImage (*this));
     m_command_dict["log"]       = CommandObjectSP (new CommandObjectLog (*this));
     m_command_dict["memory"]    = CommandObjectSP (new CommandObjectMemory (*this));
     m_command_dict["process"]   = CommandObjectSP (new CommandObjectMultiwordProcess (*this));
-    m_command_dict["quit"]      = CommandObjectSP (new CommandObjectQuit ());
+    m_command_dict["quit"]      = CommandObjectSP (new CommandObjectQuit (*this));
     m_command_dict["register"]  = CommandObjectSP (new CommandObjectRegister (*this));
-    m_command_dict["script"]    = CommandObjectSP (new CommandObjectScript (script_language));
+    m_command_dict["script"]    = CommandObjectSP (new CommandObjectScript (*this, script_language));
     m_command_dict["settings"]  = CommandObjectSP (new CommandObjectMultiwordSettings (*this));
     m_command_dict["source"]    = CommandObjectSP (new CommandObjectMultiwordSource (*this));
     m_command_dict["target"]    = CommandObjectSP (new CommandObjectMultiwordTarget (*this));
     m_command_dict["thread"]    = CommandObjectSP (new CommandObjectMultiwordThread (*this));
 
     std::auto_ptr<CommandObjectRegexCommand>
-    break_regex_cmd_ap(new CommandObjectRegexCommand ("regexp-break",
+    break_regex_cmd_ap(new CommandObjectRegexCommand (*this,
+                                                      "regexp-break",
                                                       "Set a breakpoint using a regular expression to specify the location.",
                                                       "regexp-break [<file>:<line>]\nregexp-break [<address>]\nregexp-break <...>", 2));
     if (break_regex_cmd_ap.get())
@@ -574,14 +575,14 @@
                         stripped_command += strlen(command_cstr);
                         while (isspace(*stripped_command))
                             ++stripped_command;
-                        command_obj->ExecuteRawCommandString (*this, stripped_command, result);
+                        command_obj->ExecuteRawCommandString (stripped_command, result);
                     }
                 }
                 else
                 {
                     // Remove the command from the args.
                     command_args.Shift();
-                    command_obj->ExecuteWithOptions (*this, command_args, result);
+                    command_obj->ExecuteWithOptions (command_args, result);
                 }
             }
             else
@@ -681,8 +682,7 @@
         {
             parsed_line.Shift();
             cursor_index--;
-            num_command_matches = command_object->HandleCompletion (*this,
-                                                                    parsed_line, 
+            num_command_matches = command_object->HandleCompletion (parsed_line, 
                                                                     cursor_index, 
                                                                     cursor_char_position,
                                                                     match_start_point, 
@@ -1010,7 +1010,7 @@
     if (pos != m_command_dict.end())
     {
         CommandObject *script_cmd_obj = pos->second.get();
-        return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (*this);
+        return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter ();
     }
     return NULL;
 }
@@ -1041,15 +1041,8 @@
                                              const char *help_text,
                                              uint32_t max_word_len)
 {
-    lldb::SettableVariableType var_type;
-    const char *width_value = 
-      Debugger::GetSettingsController()->GetVariable ("term-width", var_type,
-                                                      m_debugger.GetInstanceName().AsCString()).GetStringAtIndex(0);
-    int max_columns = atoi (width_value);
-    // Sanity check max_columns, to cope with emacs shell mode with TERM=dumb
-    // (0 rows; 0 columns;).
-    if (max_columns <= 0) max_columns = 80;
-    
+    const uint32_t max_columns = m_debugger.GetTerminalWidth();
+
     int indent_size = max_word_len + strlen (separator) + 2;
 
     strm.IndentMore (indent_size);
@@ -1135,7 +1128,7 @@
           
           complete_command_name.Printf ("%s %s", prefix, command_name);
 
-          if (sub_cmd_obj->HelpTextContainsWord (search_word, *this))
+          if (sub_cmd_obj->HelpTextContainsWord (search_word))
           {
               commands_found.AppendString (complete_command_name.GetData());
               commands_help.AppendString (sub_cmd_obj->GetHelp());
@@ -1159,7 +1152,7 @@
         const char *command_name = pos->first.c_str();
         CommandObject *cmd_obj = pos->second.get();
 
-        if (cmd_obj->HelpTextContainsWord (search_word, *this))
+        if (cmd_obj->HelpTextContainsWord (search_word))
         {
             commands_found.AppendString (command_name);
             commands_help.AppendString (cmd_obj->GetHelp());
diff --git a/source/Interpreter/CommandObject.cpp b/source/Interpreter/CommandObject.cpp
index 571c3d4..0784b4a 100644
--- a/source/Interpreter/CommandObject.cpp
+++ b/source/Interpreter/CommandObject.cpp
@@ -38,7 +38,15 @@
 // CommandObject
 //-------------------------------------------------------------------------
 
-CommandObject::CommandObject (const char *name, const char *help, const char *syntax, uint32_t flags) :
+CommandObject::CommandObject 
+(
+    CommandInterpreter &interpreter, 
+    const char *name, 
+    const char *help, 
+    const char *syntax, 
+    uint32_t flags
+) :
+    m_interpreter (interpreter),
     m_cmd_name (name),
     m_cmd_help_short (),
     m_cmd_help_long (),
@@ -134,19 +142,17 @@
 bool
 CommandObject::ExecuteCommandString
 (
-    CommandInterpreter &interpreter,
     const char *command_line,
     CommandReturnObject &result
 )
 {
     Args command_args(command_line);
-    return ExecuteWithOptions (interpreter, command_args, result);
+    return ExecuteWithOptions (command_args, result);
 }
 
 bool
 CommandObject::ParseOptions
 (
-    CommandInterpreter &interpreter,
     Args& args,
     CommandReturnObject &result
 )
@@ -177,8 +183,7 @@
             else
             {
                 // No error string, output the usage information into result
-                options->GenerateOptionUsage (result.GetErrorStream(), this,
-                                              interpreter.GetDebugger().GetInstanceName().AsCString());
+                options->GenerateOptionUsage (m_interpreter, result.GetErrorStream(), this);
             }
             // Set the return status to failed (this was an error).
             result.SetStatus (eReturnStatusFailed);
@@ -188,21 +193,16 @@
     return true;
 }
 bool
-CommandObject::ExecuteWithOptions
-(
-    CommandInterpreter &interpreter,
-    Args& args,
-    CommandReturnObject &result
-)
+CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result)
 {
     for (size_t i = 0; i < args.GetArgumentCount();  ++i)
     {
         const char *tmp_str = args.GetArgumentAtIndex (i);
         if (tmp_str[0] == '`')  // back-quote
-            args.ReplaceArgumentAtIndex (i, interpreter.ProcessEmbeddedScriptCommands (tmp_str));
+            args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str));
     }
 
-    Process *process = interpreter.GetDebugger().GetExecutionContext().process;
+    Process *process = m_interpreter.GetDebugger().GetExecutionContext().process;
     if (process == NULL)
     {
         if (GetFlags().IsSet(CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused))
@@ -248,11 +248,11 @@
         }
     }
     
-    if (!ParseOptions (interpreter, args, result))
+    if (!ParseOptions (args, result))
         return false;
 
     // Call the command-specific version of 'Execute', passing it the already processed arguments.
-    return Execute (interpreter, args, result);
+    return Execute (args, result);
 }
 
 class CommandDictCommandPartialMatch
@@ -300,7 +300,6 @@
 int
 CommandObject::HandleCompletion
 (
-    CommandInterpreter &interpreter,
     Args &input,
     int &cursor_index,
     int &cursor_char_position,
@@ -341,7 +340,7 @@
             input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1);
 
             bool handled_by_options;
-            handled_by_options = cur_options->HandleOptionCompletion (interpreter, 
+            handled_by_options = cur_options->HandleOptionCompletion (m_interpreter, 
                                                                       input,
                                                                       opt_element_vector,
                                                                       cursor_index,
@@ -355,8 +354,7 @@
         }
 
         // If we got here, the last word is not an option or an option argument.
-        return HandleArgumentCompletion (interpreter, 
-                                         input,
+        return HandleArgumentCompletion (input,
                                          cursor_index,
                                          cursor_char_position,
                                          opt_element_vector,
@@ -397,7 +395,7 @@
 }
 
 bool
-CommandObject::HelpTextContainsWord (const char *search_word, CommandInterpreter &interpreter)
+CommandObject::HelpTextContainsWord (const char *search_word)
 {
     const char *short_help;
     const char *long_help;
@@ -422,7 +420,7 @@
         && GetOptions() != NULL)
     {
         StreamString usage_help;
-        GetOptions()->GenerateOptionUsage (usage_help, this, interpreter.GetDebugger().GetInstanceName().AsCString());
+        GetOptions()->GenerateOptionUsage (m_interpreter, usage_help, this);
         if (usage_help.GetSize() > 0)
         {
             const char *usage_text = usage_help.GetData();
diff --git a/source/Interpreter/CommandObjectRegexCommand.cpp b/source/Interpreter/CommandObjectRegexCommand.cpp
index 30f3eef..534038a 100644
--- a/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -24,12 +24,13 @@
 //----------------------------------------------------------------------
 CommandObjectRegexCommand::CommandObjectRegexCommand
 (
+    CommandInterpreter &interpreter,
     const char *name,
     const char *help,
     const char *syntax,
     uint32_t max_matches
 ) :
-    CommandObject (name, help, syntax),
+    CommandObject (interpreter, name, help, syntax),
     m_max_matches (max_matches),
     m_entries ()
 {
@@ -46,7 +47,6 @@
 bool
 CommandObjectRegexCommand::Execute
 (
-    CommandInterpreter &interpreter,
     Args& command,
     CommandReturnObject &result
 )
@@ -58,7 +58,6 @@
 bool
 CommandObjectRegexCommand::ExecuteRawCommandString
 (
-    CommandInterpreter &interpreter,
     const char *command,
     CommandReturnObject &result
 )
@@ -90,7 +89,7 @@
                 // Interpret the new command and return this as the result!
 //                if (m_options.verbose)
 //                    result.GetOutputStream().Printf("%s\n", new_command.c_str());
-                return interpreter.HandleCommand(new_command.c_str(), true, result);
+                return m_interpreter.HandleCommand(new_command.c_str(), true, result);
             }
         }
         result.SetStatus(eReturnStatusFailed);
diff --git a/source/Interpreter/CommandObjectScript.cpp b/source/Interpreter/CommandObjectScript.cpp
index a9d9afc..59b9a75 100644
--- a/source/Interpreter/CommandObjectScript.cpp
+++ b/source/Interpreter/CommandObjectScript.cpp
@@ -27,8 +27,9 @@
 // CommandObjectScript
 //-------------------------------------------------------------------------
 
-CommandObjectScript::CommandObjectScript (ScriptLanguage script_lang) :
-    CommandObject ("script",
+CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
+    CommandObject (interpreter, 
+                   "script",
                    "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
                    "script [<script-expression-for-evaluation>]"),
     m_script_lang (script_lang),
@@ -43,12 +44,11 @@
 bool
 CommandObjectScript::ExecuteRawCommandString
 (
-    CommandInterpreter &interpreter,
     const char *command,
     CommandReturnObject &result
 )
 {
-    ScriptInterpreter *script_interpreter = GetInterpreter (interpreter);
+    ScriptInterpreter *script_interpreter = GetInterpreter ();
 
     if (script_interpreter == NULL)
     {
@@ -57,13 +57,13 @@
     }
 
     if (command == NULL || command[0] == '\0') {
-        script_interpreter->ExecuteInterpreterLoop (interpreter);
+        script_interpreter->ExecuteInterpreterLoop ();
         result.SetStatus (eReturnStatusSuccessFinishNoResult);
         return result.Succeeded();
     }
 
     // We can do better when reporting the status of one-liner script execution.
-    if (script_interpreter->ExecuteOneLine (interpreter, command, &result))
+    if (script_interpreter->ExecuteOneLine (command, &result))
         result.SetStatus(eReturnStatusSuccessFinishNoResult);
     else
         result.SetStatus(eReturnStatusFailed);
@@ -80,7 +80,6 @@
 bool
 CommandObjectScript::Execute
 (
-    CommandInterpreter &interpreter,
     Args& command,
     CommandReturnObject &result
 )
@@ -91,18 +90,18 @@
 
 
 ScriptInterpreter *
-CommandObjectScript::GetInterpreter (CommandInterpreter &interpreter)
+CommandObjectScript::GetInterpreter ()
 {
     if (m_interpreter_ap.get() == NULL)
     {
         switch (m_script_lang)
         {
         case eScriptLanguagePython:
-            m_interpreter_ap.reset (new ScriptInterpreterPython (interpreter));
+            m_interpreter_ap.reset (new ScriptInterpreterPython (m_interpreter));
             break;
 
         case eScriptLanguageNone:
-            m_interpreter_ap.reset (new ScriptInterpreterNone (interpreter));
+            m_interpreter_ap.reset (new ScriptInterpreterNone (m_interpreter));
             break;
         }
     }
diff --git a/source/Interpreter/CommandObjectScript.h b/source/Interpreter/CommandObjectScript.h
index d74f7b1..eacd3a6 100644
--- a/source/Interpreter/CommandObjectScript.h
+++ b/source/Interpreter/CommandObjectScript.h
@@ -26,7 +26,8 @@
 {
 public:
 
-    CommandObjectScript (lldb::ScriptLanguage script_lang);
+    CommandObjectScript (CommandInterpreter &interpreter,
+                         lldb::ScriptLanguage script_lang);
 
     virtual
     ~CommandObjectScript ();
@@ -34,17 +35,15 @@
     bool WantsRawCommandString();
 
     virtual bool
-    ExecuteRawCommandString (CommandInterpreter &interpreter,
-                             const char *command,
+    ExecuteRawCommandString (const char *command,
                              CommandReturnObject &result);
 
     virtual bool
-    Execute (CommandInterpreter &interpreter,
-             Args& command,
+    Execute (Args& command,
              CommandReturnObject &result);
 
     ScriptInterpreter *
-    GetInterpreter (CommandInterpreter &interpreter);
+    GetInterpreter ();
 
 private:
     lldb::ScriptLanguage m_script_lang;
diff --git a/source/Interpreter/Options.cpp b/source/Interpreter/Options.cpp
index 65171b6..8e7f808 100644
--- a/source/Interpreter/Options.cpp
+++ b/source/Interpreter/Options.cpp
@@ -361,27 +361,21 @@
 void
 Options::GenerateOptionUsage
 (
+    CommandInterpreter &interpreter,
     Stream &strm,
-    CommandObject *cmd,
-    const char *debugger_instance_name,
-    const char *program_name)
+    CommandObject *cmd
+)
 {
-    lldb::SettableVariableType var_type;
-    const char *screen_width_str = 
-      Debugger::GetSettingsController()->GetVariable ("term-width", var_type,
-                                                      debugger_instance_name).GetStringAtIndex(0);
-    uint32_t screen_width = atoi (screen_width_str);
-    if (screen_width == 0)
-        screen_width = 80;
+    const uint32_t screen_width = interpreter.GetDebugger().GetTerminalWidth();
 
     const lldb::OptionDefinition *full_options_table = GetDefinitions();
     const uint32_t save_indent_level = strm.GetIndentLevel();
     const char *name;
 
     if (cmd)
-      name = cmd->GetCommandName();
+        name = cmd->GetCommandName();
     else
-      name = program_name;
+        name = "";
 
     strm.PutCString ("\nCommand Options Usage:\n");
 
diff --git a/source/Interpreter/ScriptInterpreter.cpp b/source/Interpreter/ScriptInterpreter.cpp
index e4b5634..aedeff7 100644
--- a/source/Interpreter/ScriptInterpreter.cpp
+++ b/source/Interpreter/ScriptInterpreter.cpp
@@ -22,7 +22,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
-ScriptInterpreter::ScriptInterpreter (ScriptLanguage script_lang) :
+ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
+    m_interpreter (interpreter),
     m_script_lang (script_lang),
     m_interpreter_pty ()
 {
@@ -54,7 +55,6 @@
 void 
 ScriptInterpreter::CollectDataForBreakpointCommandCallback 
 (
-    CommandInterpreter &interpreter,
     BreakpointOptions *bp_options,
     CommandReturnObject &result
 )
diff --git a/source/Interpreter/ScriptInterpreterNone.cpp b/source/Interpreter/ScriptInterpreterNone.cpp
index dad70aa..3a8f98e 100644
--- a/source/Interpreter/ScriptInterpreterNone.cpp
+++ b/source/Interpreter/ScriptInterpreterNone.cpp
@@ -17,7 +17,7 @@
 using namespace lldb_private;
 
 ScriptInterpreterNone::ScriptInterpreterNone (CommandInterpreter &interpreter) :
-    ScriptInterpreter (eScriptLanguageNone)
+    ScriptInterpreter (interpreter, eScriptLanguageNone)
 {
 }
 
@@ -26,16 +26,16 @@
 }
 
 bool
-ScriptInterpreterNone::ExecuteOneLine (CommandInterpreter &interpreter, const char *command, CommandReturnObject *)
+ScriptInterpreterNone::ExecuteOneLine (const char *command, CommandReturnObject *)
 {
-    interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
+    m_interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
     return false;
 }
 
 void
-ScriptInterpreterNone::ExecuteInterpreterLoop (CommandInterpreter &interpreter)
+ScriptInterpreterNone::ExecuteInterpreterLoop ()
 {
-    interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
+    m_interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
 }
 
 
diff --git a/source/Interpreter/ScriptInterpreterPython.cpp b/source/Interpreter/ScriptInterpreterPython.cpp
index 39ae32a..511de8f 100644
--- a/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/source/Interpreter/ScriptInterpreterPython.cpp
@@ -144,7 +144,7 @@
 }
 
 ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) :
-    ScriptInterpreter (eScriptLanguagePython),
+    ScriptInterpreter (interpreter, eScriptLanguagePython),
     m_compiled_module (NULL),
     m_termios_valid (false)
 {
@@ -254,9 +254,7 @@
 }
 
 bool
-ScriptInterpreterPython::ExecuteOneLine (CommandInterpreter &interpreter,
-                                         const char *command,
-                                         CommandReturnObject *result = 0)
+ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObject *result)
 {
     if (command)
     {
@@ -357,11 +355,11 @@
 
 
 void
-ScriptInterpreterPython::ExecuteInterpreterLoop (CommandInterpreter &interpreter)
+ScriptInterpreterPython::ExecuteInterpreterLoop ()
 {
     Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
 
-    Debugger &debugger = interpreter.GetDebugger();
+    Debugger &debugger = m_interpreter.GetDebugger();
 
     // At the moment, the only time the debugger does not have an input file handle is when this is called
     // directly from Python, in which case it is both dangerous and unnecessary (not to mention confusing) to
@@ -384,7 +382,7 @@
         if (error.Success())
         {
             debugger.PushInputReader (reader_sp);
-            ExecuteOneLine (interpreter, "run_python_interpreter(ConsoleDict)");
+            ExecuteOneLine ("run_python_interpreter(ConsoleDict)", NULL);
             debugger.PopInputReader (reader_sp);
         }
     }
@@ -643,11 +641,10 @@
 }
 
 void
-ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (CommandInterpreter &interpreter,
-                                                                  BreakpointOptions *bp_options,
+ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
                                                                   CommandReturnObject &result)
 {
-    Debugger &debugger = interpreter.GetDebugger();
+    Debugger &debugger = m_interpreter.GetDebugger();
     InputReaderSP reader_sp (new InputReader (debugger));
 
     if (reader_sp)
@@ -677,8 +674,7 @@
 
 // Set a Python one-liner as the callback for the breakpoint.
 void
-ScriptInterpreterPython::SetBreakpointCommandCallback (CommandInterpreter &interpreter,
-                                                       BreakpointOptions *bp_options,
+ScriptInterpreterPython::SetBreakpointCommandCallback (BreakpointOptions *bp_options,
                                                        const char *oneliner)
 {
     std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());