From e1cfbc79420fee0b71bad62f8d413b68a0eca91e Mon Sep 17 00:00:00 2001 From: Todd Fiala Date: Thu, 11 Aug 2016 23:51:28 +0000 Subject: 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 --- lldb/source/Interpreter/OptionGroupFormat.cpp | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'lldb/source/Interpreter/OptionGroupFormat.cpp') diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp index 3ca216afee0..1a1e060f7e6 100644 --- a/lldb/source/Interpreter/OptionGroupFormat.cpp +++ b/lldb/source/Interpreter/OptionGroupFormat.cpp @@ -66,9 +66,9 @@ OptionGroupFormat::GetDefinitions () } 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 @@ OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, 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 @@ OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, // 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 @@ OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, { // 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 @@ OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, } 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 @@ OptionGroupFormat::ParserGDBFormatLetter (CommandInterpreter &interpreter, char 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 @@ OptionGroupFormat::ParserGDBFormatLetter (CommandInterpreter &interpreter, char } void -OptionGroupFormat::OptionParsingStarting (CommandInterpreter &interpreter) +OptionGroupFormat::OptionParsingStarting(ExecutionContext *execution_context) { m_format.Clear(); m_byte_size.Clear(); -- cgit v1.2.3