Decoupled Options from CommandInterpreter.

Options used to store a reference to the CommandInterpreter instance
in the base Options class.  This made it impossible to parse options
independent of a CommandInterpreter.

This change removes the reference from the base class.  Instead, it
modifies the options-parsing-related methods to take an
ExecutionContext pointer, which the options may inspect if they need
to do so.

Closes https://reviews.llvm.org/D23416
Reviewers: clayborg, jingham

llvm-svn: 278440
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index d90ef1d..3e5b55a 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -550,7 +550,8 @@
 
 
 Error
-Args::ParseOptions (Options &options)
+Args::ParseOptions (Options &options, ExecutionContext *execution_context,
+                    PlatformSP platform_sp, bool require_validation)
 {
     StreamString sstr;
     Error error;
@@ -622,17 +623,47 @@
         if (long_options_index >= 0 && long_options[long_options_index].definition)
         {
             const OptionDefinition *def = long_options[long_options_index].definition;
-            CommandInterpreter &interpreter = options.GetInterpreter();
+
+            if (!platform_sp)
+            {
+                // User did not pass in an explicit platform.  Try to grab
+                // from the execution context.
+                TargetSP target_sp = execution_context ?
+                    execution_context->GetTargetSP() : TargetSP();
+                platform_sp = target_sp ?
+                    target_sp->GetPlatform() : PlatformSP();
+            }
             OptionValidator *validator = def->validator;
-            if (validator && !validator->IsValid(*interpreter.GetPlatform(true), interpreter.GetExecutionContext()))
+
+            if (!platform_sp && require_validation)
             {
-                error.SetErrorStringWithFormat("Option \"%s\" invalid.  %s", def->long_option, def->validator->LongConditionString());
+                // Caller requires validation but we cannot validate as we
+                // don't have the mandatory platform against which to
+                // validate.
+                error.SetErrorString("cannot validate options: "
+                                     "no platform available");
+                return error;
             }
-            else
+
+            bool validation_failed = false;
+            if (platform_sp)
             {
+                // Ensure we have an execution context, empty or not.
+                ExecutionContext dummy_context;
+                ExecutionContext *exe_ctx_p =
+                    execution_context ? execution_context : &dummy_context;
+                if (validator && !validator->IsValid(*platform_sp, *exe_ctx_p))
+                {
+                    validation_failed = true;
+                    error.SetErrorStringWithFormat("Option \"%s\" invalid.  %s", def->long_option, def->validator->LongConditionString());
+                }
+            }
+
+            // As long as validation didn't fail, we set the option value.
+            if (!validation_failed)
                 error = options.SetOptionValue(long_options_index,
-                                               (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : OptionParser::GetOptionArgument());
-            }
+                                                       (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : OptionParser::GetOptionArgument(),
+                                                       execution_context);
         }
         else
         {
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp
index a915d63..e796f29 100644
--- a/lldb/source/Interpreter/CommandAlias.cpp
+++ b/lldb/source/Interpreter/CommandAlias.cpp
@@ -12,6 +12,7 @@
 #include "llvm/Support/ErrorHandling.h"
 
 #include "lldb/Core/StreamString.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandObject.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/Options.h"
@@ -38,7 +39,9 @@
     if (options)
     {
         // See if any options were specified as part of the alias;  if so, handle them appropriately.
-        options->NotifyOptionParsingStarting ();
+        ExecutionContext exe_ctx =
+            cmd_obj_sp->GetCommandInterpreter().GetExecutionContext();
+        options->NotifyOptionParsingStarting(&exe_ctx);
         args.Unshift ("dummy_arg");
         args.ParseAliasOptions (*options, result, option_arg_vector, options_string);
         args.Shift ();
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 75e4292..3fd2d37 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -159,18 +159,23 @@
     if (options != nullptr)
     {
         Error error;
-        options->NotifyOptionParsingStarting();
+
+        auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
+        options->NotifyOptionParsingStarting(&exe_ctx);
 
         // ParseOptions calls getopt_long_only, which always skips the zero'th item in the array and starts at position 1,
         // so we need to push a dummy value into position zero.
         args.Unshift("dummy_string");
-        error = args.ParseOptions (*options);
+        const bool require_validation = true;
+        error = args.ParseOptions(*options, &exe_ctx,
+                                  GetCommandInterpreter().GetPlatform(true),
+                                  require_validation);
 
         // The "dummy_string" will have already been removed by ParseOptions,
         // so no need to remove it.
 
         if (error.Success())
-            error = options->NotifyOptionParsingFinished();
+            error = options->NotifyOptionParsingFinished(&exe_ctx);
 
         if (error.Success())
         {
@@ -188,7 +193,10 @@
             else
             {
                 // No error string, output the usage information into result
-                options->GenerateOptionUsage (result.GetErrorStream(), this);
+                options->GenerateOptionUsage(result.GetErrorStream(), this,
+                                             GetCommandInterpreter()
+                                                .GetDebugger()
+                                                .GetTerminalWidth());
             }
         }
         result.SetStatus (eReturnStatusFailed);
@@ -393,6 +401,7 @@
                                                                       cursor_char_position,
                                                                       match_start_point,
                                                                       max_return_elements,
+                                                                      GetCommandInterpreter(),
                                                                       word_complete,
                                                                       matches);
             if (handled_by_options)
@@ -438,7 +447,9 @@
         && GetOptions() != nullptr)
     {
         StreamString usage_help;
-        GetOptions()->GenerateOptionUsage (usage_help, this);
+        GetOptions()->GenerateOptionUsage(usage_help, this,
+                                          GetCommandInterpreter()
+                                            .GetDebugger().GetTerminalWidth());
         if (usage_help.GetSize() > 0)
         {
             const char *usage_text = usage_help.GetData();
@@ -929,7 +940,9 @@
     Options *options = GetOptions();
     if (options != nullptr)
     {
-        options->GenerateOptionUsage(output_strm, this);
+        options->GenerateOptionUsage(output_strm, this,
+                                     GetCommandInterpreter()
+                                        .GetDebugger().GetTerminalWidth());
     }
     const char *long_help = GetHelpLong();
     if ((long_help != nullptr) && (strlen(long_help) > 0))
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 1c3c3cd..12de6d0 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -131,7 +131,7 @@
     if (m_completion_type_mask)
     {
         std::string completion_str (input.GetArgumentAtIndex (cursor_index), cursor_char_position);
-        CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
+        CommandCompletions::InvokeCommonCompletionCallbacks (GetCommandInterpreter(),
                                                              m_completion_type_mask,
                                                              completion_str.c_str(),
                                                              match_start_point,
diff --git a/lldb/source/Interpreter/OptionGroupArchitecture.cpp b/lldb/source/Interpreter/OptionGroupArchitecture.cpp
index 3a45409..063466a 100644
--- a/lldb/source/Interpreter/OptionGroupArchitecture.cpp
+++ b/lldb/source/Interpreter/OptionGroupArchitecture.cpp
@@ -57,9 +57,9 @@
 
 
 Error
-OptionGroupArchitecture::SetOptionValue (CommandInterpreter &interpreter,
-                                 uint32_t option_idx,
-                                 const char *option_arg)
+OptionGroupArchitecture::SetOptionValue(uint32_t option_idx,
+                                        const char *option_arg,
+                                        ExecutionContext *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -79,7 +79,8 @@
 }
 
 void
-OptionGroupArchitecture::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupArchitecture::OptionParsingStarting(
+                                            ExecutionContext *execution_context)
 {
     m_arch_str.clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupBoolean.cpp b/lldb/source/Interpreter/OptionGroupBoolean.cpp
index 6bd2743..f21c3ad 100644
--- a/lldb/source/Interpreter/OptionGroupBoolean.cpp
+++ b/lldb/source/Interpreter/OptionGroupBoolean.cpp
@@ -43,9 +43,9 @@
 }
 
 Error
-OptionGroupBoolean::SetOptionValue (CommandInterpreter &interpreter,
-                                    uint32_t option_idx,
-                                    const char *option_arg)
+OptionGroupBoolean::SetOptionValue(uint32_t option_idx,
+                                   const char *option_arg,
+                                   ExecutionContext *execution_context)
 {
     Error error;
     if (m_option_definition.option_has_arg == OptionParser::eNoArgument)
@@ -62,7 +62,7 @@
 }
 
 void
-OptionGroupBoolean::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupBoolean::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_value.Clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupFile.cpp b/lldb/source/Interpreter/OptionGroupFile.cpp
index a4b5640..1f82e579 100644
--- a/lldb/source/Interpreter/OptionGroupFile.cpp
+++ b/lldb/source/Interpreter/OptionGroupFile.cpp
@@ -43,16 +43,16 @@
 }
 
 Error
-OptionGroupFile::SetOptionValue (CommandInterpreter &interpreter,
-                                 uint32_t option_idx,
-                                 const char *option_arg)
+OptionGroupFile::SetOptionValue(uint32_t option_idx,
+                                const char *option_arg,
+                                ExecutionContext *execution_context)
 {
     Error error (m_file.SetValueFromString (option_arg));
     return error;
 }
 
 void
-OptionGroupFile::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupFile::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_file.Clear();
 }
@@ -84,16 +84,16 @@
 }
 
 Error
-OptionGroupFileList::SetOptionValue (CommandInterpreter &interpreter,
-                                     uint32_t option_idx,
-                                     const char *option_arg)
+OptionGroupFileList::SetOptionValue(uint32_t option_idx,
+                                    const char *option_arg,
+                                    ExecutionContext *execution_context)
 {
     Error error (m_file_list.SetValueFromString (option_arg));
     return error;
 }
 
 void
-OptionGroupFileList::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupFileList::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_file_list.Clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp
index 3ca216a..1a1e060 100644
--- a/lldb/source/Interpreter/OptionGroupFormat.cpp
+++ b/lldb/source/Interpreter/OptionGroupFormat.cpp
@@ -66,9 +66,9 @@
 }
 
 Error
-OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter,
-                                   uint32_t option_idx,
-                                   const char *option_arg)
+OptionGroupFormat::SetOptionValue(uint32_t option_idx,
+                                  const char *option_arg,
+                                  ExecutionContext *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -123,7 +123,9 @@
                 Format format = eFormatDefault;
                 uint32_t byte_size = 0;
                 
-                while (ParserGDBFormatLetter (interpreter, gdb_format_cstr[0], format, byte_size))
+                while (ParserGDBFormatLetter (execution_context,
+                                              gdb_format_cstr[0], format,
+                                              byte_size))
                 {
                     ++gdb_format_cstr;
                 }
@@ -143,7 +145,8 @@
                 // Anything that wasn't set correctly should be set to the
                 // previous default
                 if (format == eFormatInvalid)
-                    ParserGDBFormatLetter (interpreter, m_prev_gdb_format, format, byte_size);
+                    ParserGDBFormatLetter (execution_context, m_prev_gdb_format,
+                                           format, byte_size);
                 
                 const bool byte_size_enabled = m_byte_size.GetDefaultValue() < UINT64_MAX;
                 const bool count_enabled = m_count.GetDefaultValue() < UINT64_MAX;
@@ -151,7 +154,7 @@
                 {
                     // Byte size is enabled
                     if (byte_size == 0)
-                        ParserGDBFormatLetter (interpreter, m_prev_gdb_size, format, byte_size);
+                        ParserGDBFormatLetter (execution_context, m_prev_gdb_size, format, byte_size);
                 }
                 else
                 {
@@ -205,7 +208,9 @@
 }
 
 bool
-OptionGroupFormat::ParserGDBFormatLetter (CommandInterpreter &interpreter, char format_letter, Format &format, uint32_t &byte_size)
+OptionGroupFormat::ParserGDBFormatLetter(ExecutionContext *execution_context,
+                                         char format_letter, Format &format,
+                                         uint32_t &byte_size)
 {
     m_has_gdb_format = true;
     switch (format_letter)
@@ -218,10 +223,10 @@
         case 'f': format = eFormatFloat;        m_prev_gdb_format = format_letter; return true;
         case 'a': format = eFormatAddressInfo;
         {
-            ExecutionContext exe_ctx(interpreter.GetExecutionContext());
-            Target *target = exe_ctx.GetTargetPtr();
-            if (target)
-                byte_size = target->GetArchitecture().GetAddressByteSize();
+            TargetSP target_sp = execution_context ?
+                execution_context->GetTargetSP() : TargetSP();
+            if (target_sp)
+                byte_size = target_sp->GetArchitecture().GetAddressByteSize();
             m_prev_gdb_format = format_letter;
             return true;
         }
@@ -258,7 +263,7 @@
 }
 
 void
-OptionGroupFormat::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupFormat::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_format.Clear();
     m_byte_size.Clear();
diff --git a/lldb/source/Interpreter/OptionGroupOutputFile.cpp b/lldb/source/Interpreter/OptionGroupOutputFile.cpp
index e95cd35..857d21e 100644
--- a/lldb/source/Interpreter/OptionGroupOutputFile.cpp
+++ b/lldb/source/Interpreter/OptionGroupOutputFile.cpp
@@ -52,9 +52,9 @@
 }
 
 Error
-OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
-                                       uint32_t option_idx,
-                                       const char *option_arg)
+OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
+                                      const char *option_arg,
+                                      ExecutionContext *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -78,7 +78,8 @@
 }
 
 void
-OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupOutputFile::OptionParsingStarting(
+                                            ExecutionContext *execution_context)
 {
     m_file.Clear();
     m_append.Clear();
diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp
index 6fa06d1..f5ea857 100644
--- a/lldb/source/Interpreter/OptionGroupPlatform.cpp
+++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp
@@ -70,7 +70,7 @@
 }
 
 void
-OptionGroupPlatform::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupPlatform::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_platform_name.clear();
     m_sdk_sysroot.Clear();
@@ -107,9 +107,9 @@
 
 
 Error
-OptionGroupPlatform::SetOptionValue (CommandInterpreter &interpreter,
-                                     uint32_t option_idx,
-                                     const char *option_arg)
+OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
+                                    const char *option_arg,
+                                    ExecutionContext *execution_context)
 {
     Error error;
     if (!m_include_platform_option)
diff --git a/lldb/source/Interpreter/OptionGroupString.cpp b/lldb/source/Interpreter/OptionGroupString.cpp
index e0291b1..1f45844 100644
--- a/lldb/source/Interpreter/OptionGroupString.cpp
+++ b/lldb/source/Interpreter/OptionGroupString.cpp
@@ -44,16 +44,16 @@
 }
 
 Error
-OptionGroupString::SetOptionValue (CommandInterpreter &interpreter,
-                                   uint32_t option_idx,
-                                   const char *option_arg)
+OptionGroupString::SetOptionValue(uint32_t option_idx,
+                                  const char *option_arg,
+                                  ExecutionContext *execution_context)
 {
     Error error (m_value.SetValueFromString (option_arg));
     return error;
 }
 
 void
-OptionGroupString::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupString::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_value.Clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupUInt64.cpp b/lldb/source/Interpreter/OptionGroupUInt64.cpp
index a922ab2..5cc0d5d 100644
--- a/lldb/source/Interpreter/OptionGroupUInt64.cpp
+++ b/lldb/source/Interpreter/OptionGroupUInt64.cpp
@@ -44,16 +44,16 @@
 }
 
 Error
-OptionGroupUInt64::SetOptionValue (CommandInterpreter &interpreter,
-                                   uint32_t option_idx,
-                                   const char *option_arg)
+OptionGroupUInt64::SetOptionValue(uint32_t option_idx,
+                                   const char *option_arg,
+                                  ExecutionContext *execution_context)
 {
     Error error (m_value.SetValueFromString (option_arg));
     return error;
 }
 
 void
-OptionGroupUInt64::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupUInt64::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_value.Clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupUUID.cpp b/lldb/source/Interpreter/OptionGroupUUID.cpp
index 609967a..0873dba 100644
--- a/lldb/source/Interpreter/OptionGroupUUID.cpp
+++ b/lldb/source/Interpreter/OptionGroupUUID.cpp
@@ -46,9 +46,9 @@
 }
 
 Error
-OptionGroupUUID::SetOptionValue (CommandInterpreter &interpreter,
-                                 uint32_t option_idx,
-                                 const char *option_arg)
+OptionGroupUUID::SetOptionValue(uint32_t option_idx,
+                                const char *option_arg,
+                                ExecutionContext *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -70,7 +70,7 @@
 }
 
 void
-OptionGroupUUID::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupUUID::OptionParsingStarting(ExecutionContext *execution_context)
 {
     m_uuid.Clear();
 }
diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
index c30a978..718ddc7 100644
--- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
+++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
@@ -63,9 +63,10 @@
 
 
 Error
-OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
-                                               uint32_t option_idx,
-                                               const char *option_arg)
+OptionGroupValueObjectDisplay::SetOptionValue(uint32_t option_idx,
+                                              const char *option_arg,
+                                              ExecutionContext
+                                              *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -138,7 +139,8 @@
 }
 
 void
-OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupValueObjectDisplay::OptionParsingStarting(ExecutionContext
+                                                     *execution_context)
 {
     // If these defaults change, be sure to modify AnyOptionWasSet().
     show_types        = false;
@@ -153,10 +155,11 @@
     be_raw            = false;
     ignore_cap        = false;
     run_validator     = false;
-    
-    Target *target = interpreter.GetExecutionContext().GetTargetPtr();
-    if (target != nullptr)
-        use_dynamic = target->GetPreferDynamicValue();
+
+    TargetSP target_sp =
+        execution_context ? execution_context->GetTargetSP() : TargetSP();
+    if (target_sp)
+        use_dynamic = target_sp->GetPreferDynamicValue();
     else
     {
         // If we don't have any targets, then dynamic values won't do us much good.
diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp
index 092d60a..6ee71aed 100644
--- a/lldb/source/Interpreter/OptionGroupVariable.cpp
+++ b/lldb/source/Interpreter/OptionGroupVariable.cpp
@@ -68,9 +68,9 @@
 }
 
 Error
-OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
-                                     uint32_t option_idx, 
-                                     const char *option_arg)
+OptionGroupVariable::SetOptionValue(uint32_t option_idx,
+                                    const char *option_arg,
+                                    ExecutionContext *execution_context)
 {
     Error error;
     if (!include_frame_options)
@@ -101,7 +101,7 @@
 }
 
 void
-OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupVariable::OptionParsingStarting(ExecutionContext *execution_context)
 {
     show_args     = true;   // Frame option only
     show_locals   = true;   // Frame option only
diff --git a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
index c6f4b8f..82d0fa9 100644
--- a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
+++ b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
@@ -68,9 +68,9 @@
 }
 
 Error
-OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
-                                       uint32_t option_idx, 
-                                       const char *option_arg)
+OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
+                                      const char *option_arg,
+                                      ExecutionContext *execution_context)
 {
     Error error;
     const int short_option = g_option_table[option_idx].short_option;
@@ -100,7 +100,8 @@
 }
 
 void
-OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
+OptionGroupWatchpoint::OptionParsingStarting(ExecutionContext
+                                             *execution_context)
 {
     watch_type_specified = false;
     watch_type = eWatchInvalid;
diff --git a/lldb/source/Interpreter/OptionValueArch.cpp b/lldb/source/Interpreter/OptionValueArch.cpp
index 0e1ca07..06973f8 100644
--- a/lldb/source/Interpreter/OptionValueArch.cpp
+++ b/lldb/source/Interpreter/OptionValueArch.cpp
@@ -17,6 +17,7 @@
 #include "lldb/DataFormatters/FormatManager.h"
 #include "lldb/Interpreter/Args.h"
 #include "lldb/Interpreter/CommandCompletions.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 
 using namespace lldb;
 using namespace lldb_private;
diff --git a/lldb/source/Interpreter/OptionValueFileSpec.cpp b/lldb/source/Interpreter/OptionValueFileSpec.cpp
index 3a282f1..2b0af02 100644
--- a/lldb/source/Interpreter/OptionValueFileSpec.cpp
+++ b/lldb/source/Interpreter/OptionValueFileSpec.cpp
@@ -17,6 +17,7 @@
 #include "lldb/DataFormatters/FormatManager.h"
 #include "lldb/Interpreter/Args.h"
 #include "lldb/Interpreter/CommandCompletions.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 
 using namespace lldb;
 using namespace lldb_private;
diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp
index 70f532e..a868b25 100644
--- a/lldb/source/Interpreter/Options.cpp
+++ b/lldb/source/Interpreter/Options.cpp
@@ -31,8 +31,7 @@
 //-------------------------------------------------------------------------
 // Options
 //-------------------------------------------------------------------------
-Options::Options (CommandInterpreter &interpreter) :
-    m_interpreter (interpreter),
+Options::Options () :
     m_getopt_table ()
 {
     BuildValidOptionSets();
@@ -43,17 +42,17 @@
 }
 
 void
-Options::NotifyOptionParsingStarting ()
+Options::NotifyOptionParsingStarting(ExecutionContext *execution_context)
 {
     m_seen_options.clear();
     // Let the subclass reset its option values
-    OptionParsingStarting ();
+    OptionParsingStarting(execution_context);
 }
 
 Error
-Options::NotifyOptionParsingFinished ()
+Options::NotifyOptionParsingFinished(ExecutionContext *execution_context)
 {
-    return OptionParsingFinished ();
+    return OptionParsingFinished(execution_context);
 }
 
 void
@@ -475,11 +474,11 @@
 Options::GenerateOptionUsage
 (
     Stream &strm,
-    CommandObject *cmd
+    CommandObject *cmd,
+    uint32_t screen_width
 )
 {
     const bool only_print_args = cmd->IsDashDashCommand();
-    const uint32_t screen_width = m_interpreter.GetDebugger().GetTerminalWidth();
 
     const OptionDefinition *opt_defs = GetDefinitions();
     const uint32_t save_indent_level = strm.GetIndentLevel();
@@ -760,6 +759,7 @@
     int char_pos,
     int match_start_point,
     int max_return_elements,
+    CommandInterpreter &interpreter,
     bool &word_complete,
     lldb_private::StringList &matches
 )
@@ -882,6 +882,7 @@
                                                 i,
                                                 match_start_point,
                                                 max_return_elements,
+                                                interpreter,
                                                 word_complete,
                                                 matches);
                 return true;
@@ -912,6 +913,7 @@
     int opt_element_index,
     int match_start_point,
     int max_return_elements,
+    CommandInterpreter &interpreter,
     bool &word_complete,
     lldb_private::StringList &matches
 )
@@ -982,7 +984,7 @@
                 if (module_name)
                 {
                     FileSpec module_spec(module_name, false);
-                    lldb::TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
+                    lldb::TargetSP target_sp = interpreter.GetDebugger().GetSelectedTarget();
                     // Search filters require a target...
                     if (target_sp)
                         filter_ap.reset (new SearchFilterByModule (target_sp, module_spec));
@@ -992,7 +994,7 @@
         }
     }
 
-    return CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
+    return CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
                                                                 completion_mask,
                                                                 input.GetArgumentAtIndex (opt_arg_pos),
                                                                 match_start_point,
@@ -1056,7 +1058,8 @@
 
 Error
 OptionGroupOptions::SetOptionValue (uint32_t option_idx,  
-                                    const char *option_value)
+                                    const char *option_value,
+                                    ExecutionContext *execution_context)
 {
     // After calling OptionGroupOptions::Append(...), you must finalize the groups
     // by calling OptionGroupOptions::Finlize()
@@ -1065,9 +1068,9 @@
     Error error;
     if (option_idx < m_option_infos.size())
     {
-        error = m_option_infos[option_idx].option_group->SetOptionValue (m_interpreter, 
-                                                                         m_option_infos[option_idx].option_index,
-                                                                         option_value);
+        error = m_option_infos[option_idx].option_group->SetOptionValue (m_option_infos[option_idx].option_index,
+                                                                         option_value,
+                                                                         execution_context);
         
     }
     else
@@ -1078,7 +1081,7 @@
 }
 
 void
-OptionGroupOptions::OptionParsingStarting ()
+OptionGroupOptions::OptionParsingStarting (ExecutionContext *execution_context)
 {
     std::set<OptionGroup*> group_set;
     OptionInfos::iterator pos, end = m_option_infos.end();
@@ -1087,13 +1090,13 @@
         OptionGroup* group = pos->option_group;
         if (group_set.find(group) == group_set.end())
         {
-            group->OptionParsingStarting (m_interpreter);
+            group->OptionParsingStarting(execution_context);
             group_set.insert(group);
         }
     }
 }
 Error
-OptionGroupOptions::OptionParsingFinished ()
+OptionGroupOptions::OptionParsingFinished (ExecutionContext *execution_context)
 {
     std::set<OptionGroup*> group_set;
     Error error;
@@ -1103,7 +1106,7 @@
         OptionGroup* group = pos->option_group;
         if (group_set.find(group) == group_set.end())
         {
-            error = group->OptionParsingFinished (m_interpreter);
+            error = group->OptionParsingFinished (execution_context);
             group_set.insert(group);
             if (error.Fail())
                 return error;