diff options
32 files changed, 625 insertions, 328 deletions
diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index 4bbef181..8e12d2f 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -56,7 +56,7 @@ namespace lldb_private { /// } /// /// virtual Error -/// SetOptionValue (int option_idx, int option_val, const char *option_arg) +/// SetOptionValue (uint32_t option_idx, int option_val, const char *option_arg) /// { /// Error error; /// switch (option_val) @@ -142,15 +142,13 @@ public: bool VerifyOptions (CommandReturnObject &result); - // Verify that the options given are in the options table and can be used together, but there may be - // some required options that are missing (used to verify options that get folded into command aliases). + // Verify that the options given are in the options table and can + // be used together, but there may be some required options that are + // missing (used to verify options that get folded into command aliases). bool VerifyPartialOptions (CommandReturnObject &result); -// void -// BuildAliasOptions (OptionArgVector *option_arg_vector, Args args); - void OutputFormattedUsageText (Stream &strm, const char *text, @@ -160,19 +158,22 @@ public: GenerateOptionUsage (Stream &strm, CommandObject *cmd); - // The following two pure virtual functions must be defined by every class that inherits from - // this class. + // The following two pure virtual functions must be defined by every + // class that inherits from this class. virtual const OptionDefinition* GetDefinitions () { return NULL; } // Call this prior to parsing any options. This call will call the - // subclass ResetOptionValues() and will avoid the need for all - // ResetOptionValues() function instances from having to call the - // Option::ResetOptionValues() like they did before. This was error + // subclass OptionParsingStarting() and will avoid the need for all + // OptionParsingStarting() function instances from having to call the + // Option::OptionParsingStarting() like they did before. This was error // prone and subclasses shouldn't have to do it. void - Reset (); + NotifyOptionParsingStarting (); + + Error + NotifyOptionParsingFinished (); //------------------------------------------------------------------ /// Set the value of an option. @@ -190,11 +191,11 @@ public: /// @see man getopt_long //------------------------------------------------------------------ virtual Error - SetOptionValue (int option_idx, const char *option_arg) = 0; + SetOptionValue (uint32_t option_idx, const char *option_arg) = 0; //------------------------------------------------------------------ - /// Handles the generic bits of figuring out whether we are in an option, and if so completing - /// it. + /// Handles the generic bits of figuring out whether we are in an + /// option, and if so completing it. /// /// @param[in] input /// The command line parsed into words @@ -207,20 +208,22 @@ public: /// /// @param[in] match_start_point /// @param[in] match_return_elements - /// See CommandObject::HandleCompletions for a description of how these work. + /// See CommandObject::HandleCompletions for a description of + /// how these work. /// /// @param[in] interpreter /// The interpreter that's doing the completing. /// /// @param[out] word_complete - /// \btrue if this is a complete option value (a space will be inserted after the - /// completion.) \bfalse otherwise. + /// \btrue if this is a complete option value (a space will be + /// inserted after the completion.) \b false otherwise. /// /// @param[out] matches /// The array of matches returned. /// - /// FIXME: This is the wrong return value, since we also need to make a distinction between - /// total number of matches, and the window the user wants returned. + /// FIXME: This is the wrong return value, since we also need to + /// make a distinction between total number of matches, and the + /// window the user wants returned. /// /// @return /// \btrue if we were in an option, \bfalse otherwise. @@ -236,8 +239,8 @@ public: lldb_private::StringList &matches); //------------------------------------------------------------------ - /// Handles the generic bits of figuring out whether we are in an option, and if so completing - /// it. + /// Handles the generic bits of figuring out whether we are in an + /// option, and if so completing it. /// /// @param[in] interpreter /// The command interpreter doing the completion. @@ -255,21 +258,24 @@ public: /// The results of the options parse of \a input. /// /// @param[in] opt_element_index - /// The position in \a opt_element_vector of the word in \a input containing the cursor. + /// The position in \a opt_element_vector of the word in \a + /// input containing the cursor. /// /// @param[in] match_start_point /// @param[in] match_return_elements - /// See CommandObject::HandleCompletions for a description of how these work. + /// See CommandObject::HandleCompletions for a description of + /// how these work. /// /// @param[out] word_complete - /// \btrue if this is a complete option value (a space will be inserted after the - /// completion.) \bfalse otherwise. + /// \btrue if this is a complete option value (a space will + /// be inserted after the completion.) \bfalse otherwise. /// /// @param[out] matches /// The array of matches returned. /// - /// FIXME: This is the wrong return value, since we also need to make a distinction between - /// total number of matches, and the window the user wants returned. + /// FIXME: This is the wrong return value, since we also need to + /// make a distinction between total number of matches, and the + /// window the user wants returned. /// /// @return /// \btrue if we were in an option, \bfalse otherwise. @@ -321,9 +327,104 @@ protected: // option parse. Each subclass must override this function and revert // all option settings to default values. virtual void - ResetOptionValues () = 0; + OptionParsingStarting () = 0; + + virtual Error + OptionParsingFinished () + { + // If subclasses need to know when the options are done being parsed + // they can implement this function to do extra checking + Error error; + return error; + } }; + class OptionGroup + { + public: + OptionGroup () + { + } + + virtual + ~OptionGroup () + { + } + + virtual uint32_t + GetNumDefinitions () = 0; + + virtual const OptionDefinition* + GetDefinitions () = 0; + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value) = 0; + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter) = 0; + + virtual Error + OptionParsingFinished (CommandInterpreter &interpreter) + { + // If subclasses need to know when the options are done being parsed + // they can implement this function to do extra checking + Error error; + return error; + } + }; + + class OptionGroupOptions : public Options + { + public: + + OptionGroupOptions (CommandInterpreter &interpreter) : + Options (interpreter), + m_option_defs (), + m_option_groups (), + m_did_finalize (false) + { + } + + virtual + ~OptionGroupOptions () + { + } + + void + Append (OptionGroup* group); + + void + Append (OptionGroup* group, uint32_t usage_mask); + + void + Finalize (); + + virtual Error + SetOptionValue (uint32_t option_idx, + const char *option_arg); + + virtual void + OptionParsingStarting (); + + virtual Error + OptionParsingFinished (); + + const OptionDefinition* + GetDefinitions () + { + assert (m_did_finalize); + return &m_option_defs[0]; + } + typedef std::vector<OptionGroup*> OptionGroupsType; + + std::vector<OptionDefinition> m_option_defs; + OptionGroupsType m_option_groups; + bool m_did_finalize; + }; + + } // namespace lldb_private #endif // liblldb_Options_h_ diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 98612ff..add53cc 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -725,8 +725,8 @@ public: ProcessLaunchCommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } ~ProcessLaunchCommandOptions () @@ -734,10 +734,10 @@ public: } Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues () + OptionParsingStarting () { launch_info.Clear(); } diff --git a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme index 3380f79..043dfd3 100644 --- a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme +++ b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <Scheme - version = "1.3"> + version = "1.5"> <BuildAction parallelizeBuildables = "NO" buildImplicitDependencies = "YES"> @@ -196,4 +196,7 @@ buildConfiguration = "Release" revealArchiveInOrganizer = "YES"> </ArchiveAction> + <InstallAction + buildConfiguration = "Debug"> + </InstallAction> </Scheme> diff --git a/lldb/source/Commands/CommandObjectArgs.cpp b/lldb/source/Commands/CommandObjectArgs.cpp index 0ed4a06..09363d7 100644 --- a/lldb/source/Commands/CommandObjectArgs.cpp +++ b/lldb/source/Commands/CommandObjectArgs.cpp @@ -40,7 +40,7 @@ CommandObjectArgs::CommandOptions::CommandOptions (CommandInterpreter &interpret Options(interpreter) { // Keep only one place to reset the values to their defaults - ResetOptionValues(); + OptionParsingStarting(); } @@ -49,7 +49,7 @@ CommandObjectArgs::CommandOptions::~CommandOptions () } Error -CommandObjectArgs::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectArgs::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; @@ -66,7 +66,7 @@ CommandObjectArgs::CommandOptions::SetOptionValue (int option_idx, const char *o } void -CommandObjectArgs::CommandOptions::ResetOptionValues () +CommandObjectArgs::CommandOptions::OptionParsingStarting () { } diff --git a/lldb/source/Commands/CommandObjectArgs.h b/lldb/source/Commands/CommandObjectArgs.h index b6a7f32..a3c365d 100644 --- a/lldb/source/Commands/CommandObjectArgs.h +++ b/lldb/source/Commands/CommandObjectArgs.h @@ -34,10 +34,10 @@ namespace lldb_private { ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index d5a4345..f3a90fe 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -134,7 +134,7 @@ CommandObjectBreakpointSet::CommandOptions::GetDefinitions () } Error -CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectBreakpointSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -233,7 +233,7 @@ CommandObjectBreakpointSet::CommandOptions::SetOptionValue (int option_idx, cons } void -CommandObjectBreakpointSet::CommandOptions::ResetOptionValues () +CommandObjectBreakpointSet::CommandOptions::OptionParsingStarting () { m_filename.clear(); m_line_num = 0; @@ -675,7 +675,7 @@ CommandObjectBreakpointList::CommandOptions::GetDefinitions () } Error -CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectBreakpointList::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -703,7 +703,7 @@ CommandObjectBreakpointList::CommandOptions::SetOptionValue (int option_idx, con } void -CommandObjectBreakpointList::CommandOptions::ResetOptionValues () +CommandObjectBreakpointList::CommandOptions::OptionParsingStarting () { m_level = lldb::eDescriptionLevelBrief; m_internal = false; @@ -1077,7 +1077,7 @@ CommandObjectBreakpointClear::CommandOptions::GetDefinitions () } Error -CommandObjectBreakpointClear::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectBreakpointClear::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -1101,7 +1101,7 @@ CommandObjectBreakpointClear::CommandOptions::SetOptionValue (int option_idx, co } void -CommandObjectBreakpointClear::CommandOptions::ResetOptionValues () +CommandObjectBreakpointClear::CommandOptions::OptionParsingStarting () { m_filename.clear(); m_line_num = 0; @@ -1394,7 +1394,7 @@ CommandObjectBreakpointModify::CommandOptions::GetDefinitions () } Error -CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectBreakpointModify::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -1480,7 +1480,7 @@ CommandObjectBreakpointModify::CommandOptions::SetOptionValue (int option_idx, c } void -CommandObjectBreakpointModify::CommandOptions::ResetOptionValues () +CommandObjectBreakpointModify::CommandOptions::OptionParsingStarting () { m_ignore_count = 0; m_thread_id = LLDB_INVALID_THREAD_ID; diff --git a/lldb/source/Commands/CommandObjectBreakpoint.h b/lldb/source/Commands/CommandObjectBreakpoint.h index c624dc5..d8382a7 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.h +++ b/lldb/source/Commands/CommandObjectBreakpoint.h @@ -82,10 +82,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); @@ -148,10 +148,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); @@ -249,10 +249,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition * GetDefinitions (); @@ -309,10 +309,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index f481515..a188baebd 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -82,7 +82,7 @@ CommandObjectBreakpointCommandAdd::CommandOptions::GetDefinitions () Error CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue ( - int option_idx, + uint32_t option_idx, const char *option_arg ) { @@ -133,7 +133,7 @@ CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue } void -CommandObjectBreakpointCommandAdd::CommandOptions::ResetOptionValues () +CommandObjectBreakpointCommandAdd::CommandOptions::OptionParsingStarting () { m_use_commands = true; m_use_script_language = false; diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.h b/lldb/source/Commands/CommandObjectBreakpointCommand.h index 5cfa848..38f958b 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.h +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.h @@ -101,10 +101,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 8f8dd96..e0871e0 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -43,7 +43,7 @@ private: ~CommandOptions (){} virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -70,7 +70,7 @@ private: } void - ResetOptionValues () + OptionParsingStarting () { m_stop_on_error = true; m_stop_on_continue = true; @@ -360,7 +360,7 @@ public: if (options) { // See if any options were specified as part of the alias; if so, handle them appropriately - options->Reset (); + options->NotifyOptionParsingStarting (); Args tmp_args (raw_command_string.c_str()); args.Unshift ("dummy_arg"); args.ParseAliasOptions (*options, result, option_arg_vector, raw_command_string); @@ -491,7 +491,7 @@ public: options = sub_cmd_obj->GetOptions(); else options = cmd_obj->GetOptions(); - options->Reset (); + options->NotifyOptionParsingStarting (); std::string empty_string; args.Unshift ("dummy_arg"); args.ParseAliasOptions (*options, result, option_arg_vector, empty_string); diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index dea7640..f54bc9e 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -44,7 +44,7 @@ CommandObjectDisassemble::CommandOptions::CommandOptions (CommandInterpreter &in plugin_name (), arch() { - ResetOptionValues(); + OptionParsingStarting(); } CommandObjectDisassemble::CommandOptions::~CommandOptions () @@ -52,7 +52,7 @@ CommandObjectDisassemble::CommandOptions::~CommandOptions () } Error -CommandObjectDisassemble::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectDisassemble::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; @@ -140,7 +140,7 @@ CommandObjectDisassemble::CommandOptions::SetOptionValue (int option_idx, const } void -CommandObjectDisassemble::CommandOptions::ResetOptionValues () +CommandObjectDisassemble::CommandOptions::OptionParsingStarting () { show_mixed = false; show_bytes = false; diff --git a/lldb/source/Commands/CommandObjectDisassemble.h b/lldb/source/Commands/CommandObjectDisassemble.h index ac354a8..2182810 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.h +++ b/lldb/source/Commands/CommandObjectDisassemble.h @@ -36,10 +36,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index c96b247..7b9f01c 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -41,7 +41,7 @@ CommandObjectExpression::CommandOptions::CommandOptions (CommandInterpreter &int Options(interpreter) { // Keep only one place to reset the values to their defaults - ResetOptionValues(); + OptionParsingStarting(); } @@ -50,7 +50,7 @@ CommandObjectExpression::CommandOptions::~CommandOptions () } Error -CommandObjectExpression::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectExpression::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; @@ -93,7 +93,7 @@ CommandObjectExpression::CommandOptions::SetOptionValue (int option_idx, const c } void -CommandObjectExpression::CommandOptions::ResetOptionValues () +CommandObjectExpression::CommandOptions::OptionParsingStarting () { //language.Clear(); debug = false; @@ -297,7 +297,7 @@ CommandObjectExpression::ExecuteRawCommandString { m_exe_ctx = m_interpreter.GetExecutionContext(); - m_options.Reset(); + m_options.NotifyOptionParsingStarting(); const char * expr = NULL; @@ -361,6 +361,14 @@ CommandObjectExpression::ExecuteRawCommandString Args args (command, end_options - command); if (!ParseOptions (args, result)) return false; + + Error error (m_options.NotifyOptionParsingFinished()); + if (error.Fail()) + { + result.AppendError (error.AsCString()); + result.SetStatus (eReturnStatusFailed); + return false; + } } } diff --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h index fcf308a..6eff72c 100644 --- a/lldb/source/Commands/CommandObjectExpression.h +++ b/lldb/source/Commands/CommandObjectExpression.h @@ -35,10 +35,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectFile.cpp b/lldb/source/Commands/CommandObjectFile.cpp index 1177f5a..372baf9 100644 --- a/lldb/source/Commands/CommandObjectFile.cpp +++ b/lldb/source/Commands/CommandObjectFile.cpp @@ -25,41 +25,51 @@ using namespace lldb; using namespace lldb_private; -CommandObjectFile::CommandOptions::CommandOptions(CommandInterpreter &interpreter) : - Options (interpreter), - m_arch () // Breakpoint info defaults to brief descriptions +FileOptionGroup::FileOptionGroup() : + m_arch (), + m_arch_str () { } -CommandObjectFile::CommandOptions::~CommandOptions () +FileOptionGroup::~FileOptionGroup () { } -OptionDefinition -CommandObjectFile::CommandOptions::g_option_table[] = +OptionDefinition g_file_option_table[] = { - { LLDB_OPT_SET_1, false, "arch", 'a', required_argument, NULL, 0, eArgTypeArchitecture, "Specify the architecture to be used when the process is launched."}, - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } + { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."}, }; +const uint32_t k_num_file_options = sizeof(g_file_option_table)/sizeof(OptionDefinition); + +uint32_t +FileOptionGroup::GetNumDefinitions () +{ + return k_num_file_options; +} const OptionDefinition * -CommandObjectFile::CommandOptions::GetDefinitions () +FileOptionGroup::GetDefinitions () { - return g_option_table; + return g_file_option_table; } Error -CommandObjectFile::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_arg) { Error error; - char short_option = (char) m_getopt_table[option_idx].val; + char short_option = (char) g_file_option_table[option_idx].short_option; switch (short_option) { case 'a': { - PlatformSP platform_sp (m_interpreter.GetPlatform (false)); - ArchSpec option_arch (option_arg, platform_sp.get()); + // Save the arch value in case we specify a platform after specifying the arch + m_arch_str.assign (option_arg); + // Check to see if we already have a platform? + m_arch_platform_sp = interpreter.GetPlatform (false); + ArchSpec option_arch (option_arg, m_arch_platform_sp.get()); if (option_arch.IsValid()) m_arch = option_arch; else @@ -76,11 +86,30 @@ CommandObjectFile::CommandOptions::SetOptionValue (int option_idx, const char *o } void -CommandObjectFile::CommandOptions::ResetOptionValues () +FileOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter) { m_arch.Clear(); } +Error +FileOptionGroup::OptionParsingFinished (CommandInterpreter &interpreter) +{ + Error error; + if (m_arch.IsValid()) + { + PlatformSP curr_platform_sp (interpreter.GetPlatform (false)); + if (curr_platform_sp.get() != m_arch_platform_sp.get()) + { + ArchSpec option_arch (m_arch_str.c_str(), curr_platform_sp.get()); + if (option_arch.IsValid()) + m_arch = option_arch; + else + error.SetErrorStringWithFormat ("invalid arch '%s' for platform '%s'", m_arch_str.c_str(), curr_platform_sp->GetName()); + } + } + return error; +} + //------------------------------------------------------------------------- // CommandObjectFile //------------------------------------------------------------------------- @@ -90,7 +119,9 @@ CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) : "file", "Set the file to be used as the main executable by the debugger.", NULL), - m_options (interpreter) + m_option_group (interpreter), + m_file_options (), + m_platform_options(true) // Do include the "--platform" option in the platform settings by passing true { CommandArgumentEntry arg; CommandArgumentData file_arg; @@ -104,6 +135,10 @@ CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) : // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg); + + m_option_group.Append (&m_file_options); + m_option_group.Append (&m_platform_options); + m_option_group.Finalize(); } CommandObjectFile::~CommandObjectFile () @@ -113,7 +148,7 @@ CommandObjectFile::~CommandObjectFile () Options * CommandObjectFile::GetOptions () { - return &m_options; + return &m_option_group; } bool @@ -140,7 +175,7 @@ CommandObjectFile::Execute TargetSP target_sp; Debugger &debugger = m_interpreter.GetDebugger(); - Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_options.m_arch, true, target_sp); + Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_file_options.m_arch, true, target_sp); if (target_sp) { diff --git a/lldb/source/Commands/CommandObjectFile.h b/lldb/source/Commands/CommandObjectFile.h index bbbacdb..1af8896 100644 --- a/lldb/source/Commands/CommandObjectFile.h +++ b/lldb/source/Commands/CommandObjectFile.h @@ -12,11 +12,13 @@ // C Includes // C++ Includes +#include <vector> // Other libraries and framework includes // Project includes #include "lldb/Interpreter/Options.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Interpreter/CommandObject.h" +#include "CommandObjectPlatform.h" namespace lldb_private { @@ -24,6 +26,38 @@ namespace lldb_private { // CommandObjectFile //------------------------------------------------------------------------- + class FileOptionGroup : public OptionGroup + { + public: + + FileOptionGroup (); + + virtual + ~FileOptionGroup (); + + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + virtual Error + OptionParsingFinished (CommandInterpreter &interpreter); + + ArchSpec m_arch; + lldb::PlatformSP m_arch_platform_sp; // The platform that was used to resolve m_arch + std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture + }; + class CommandObjectFile : public CommandObject { public: @@ -40,32 +74,6 @@ public: virtual Options * GetOptions (); - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter); - - virtual - ~CommandOptions (); - - virtual Error - SetOptionValue (int option_idx, const char *option_arg); - - void - ResetOptionValues (); - - const OptionDefinition* - GetDefinitions (); - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - ArchSpec m_arch; - }; virtual int HandleArgumentCompletion (Args &input, @@ -79,8 +87,9 @@ public: private: - CommandOptions m_options; - + OptionGroupOptions m_option_group; + FileOptionGroup m_file_options; + PlatformOptionGroup m_platform_options; }; } // namespace lldb_private diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 57286ac..51299c2 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -102,7 +102,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues (); + OptionParsingStarting (); } virtual @@ -111,7 +111,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; bool success = false; @@ -133,7 +133,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { relative_frame_offset = INT32_MIN; } @@ -293,7 +293,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues (); + OptionParsingStarting (); } virtual @@ -302,7 +302,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; bool success; @@ -350,7 +350,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { use_objc = false; use_regex = false; diff --git a/lldb/source/Commands/CommandObjectImage.cpp b/lldb/source/Commands/CommandObjectImage.cpp index ca109d5..ae1612e 100644 --- a/lldb/source/Commands/CommandObjectImage.cpp +++ b/lldb/source/Commands/CommandObjectImage.cpp @@ -734,7 +734,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -764,7 +764,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_sort_order = eSortOrderNone; } @@ -1155,7 +1155,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { char short_option = (char) m_getopt_table[option_idx].val; uint32_t width = 0; @@ -1167,7 +1167,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_format_array.clear(); } @@ -1365,7 +1365,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues(); + OptionParsingStarting(); } virtual @@ -1374,7 +1374,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; @@ -1441,7 +1441,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_type = eLookupTypeInvalid; m_str.clear(); diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index b10e8ec..e38b618 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -183,7 +183,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -207,7 +207,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { log_file.clear(); log_options = 0; diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 7993f54..bc08d44 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -39,7 +39,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues(); + OptionParsingStarting(); } virtual @@ -48,7 +48,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -162,7 +162,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_format = eFormatBytesWithASCII; m_byte_size = 0; @@ -438,7 +438,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues(); + OptionParsingStarting(); } virtual @@ -447,7 +447,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -491,7 +491,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_format = eFormatBytes; m_byte_size = 1; diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 730a1b3..46a53c7 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -27,24 +27,134 @@ using namespace lldb; using namespace lldb_private; + +PlatformSP +PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter, + const char *platform_name, + bool select, + Error& error) +{ + if (platform_name && platform_name[0]) + { + if (platform_sp) + { + error.SetErrorString ("platform can't be set more than once in a command"); + return PlatformSP(); + } + + platform_sp = Platform::Create (platform_name, error); + + if (platform_sp) + { + interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select); + if (os_version_major != UINT32_MAX) + { + platform_sp->SetOSVersion (os_version_major, + os_version_minor, + os_version_update); + } + } + } + else + { + error.SetErrorString ("invalid platform name"); + platform_sp.reset(); + } + return platform_sp; +} + +void +PlatformOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter) +{ + platform_sp.reset(); + os_version_major = UINT32_MAX; + os_version_minor = UINT32_MAX; + os_version_update = UINT32_MAX; +} + +static OptionDefinition +g_option_table[] = +{ + { LLDB_OPT_SET_ALL, false, "platform" , 'p', required_argument, NULL, 0, eArgTypeNone, "Specify name of the platform to use for this target, creating the platform if necessary."}, + { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." } +}; + +static const uint32_t k_option_table_size = sizeof(g_option_table)/sizeof (OptionDefinition); + +const OptionDefinition* +PlatformOptionGroup::GetDefinitions () +{ + if (m_include_platform_option) + return g_option_table; + return g_option_table + 1; +} + +uint32_t +PlatformOptionGroup::GetNumDefinitions () +{ + if (m_include_platform_option) + return k_option_table_size; + return k_option_table_size - 1; +} + + +Error +PlatformOptionGroup::SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_arg) +{ + Error error; + if (!m_include_platform_option) + --option_idx; + + char short_option = (char) g_option_table[option_idx].short_option; + + switch (short_option) + { + case 'p': + CreatePlatformWithOptions (interpreter, option_arg, true, error); + break; + + case 'v': + if (Args::StringToVersion (option_arg, os_version_major, os_version_minor, os_version_update) == option_arg) + { + error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); + } + else + { + if (platform_sp) + platform_sp->SetOSVersion (os_version_major, os_version_minor, os_version_update); + } + break; + + default: + error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); + break; + } + return error; +} + //---------------------------------------------------------------------- // "platform create <platform-name>" //---------------------------------------------------------------------- -class CommandObjectPlatformCreate : public CommandObject +class CommandObjectPlatformSelect : public CommandObject { public: - CommandObjectPlatformCreate (CommandInterpreter &interpreter) : + CommandObjectPlatformSelect (CommandInterpreter &interpreter) : CommandObject (interpreter, - "platform create", - "Create a platform instance by name and select it as the current platform.", - "platform create <platform-name>", + "platform select", + "Create a platform if needed and select it as the current platform.", + "platform select <platform-name>", 0), - m_options (interpreter) + m_option_group (interpreter), + m_platform_options (false) // Don't include the "--platform" option by passing false { + m_option_group.Append (&m_platform_options); + m_option_group.Finalize(); } virtual - ~CommandObjectPlatformCreate () + ~CommandObjectPlatformSelect () { } @@ -54,20 +164,13 @@ public: Error error; if (args.GetArgumentCount() == 1) { - PlatformSP platform_sp (Platform::Create (args.GetArgumentAtIndex (0), error)); - + const bool select = true; + PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, + args.GetArgumentAtIndex (0), + select, + error)); if (platform_sp) - { - m_interpreter.GetDebugger().GetPlatformList().Append (platform_sp, true); - if (m_options.os_version_major != UINT32_MAX) - { - platform_sp->SetOSVersion (m_options.os_version_major, - m_options.os_version_minor, - m_options.os_version_update); - } - platform_sp->GetStatus (result.GetOutputStream()); - } } else { @@ -80,86 +183,12 @@ public: virtual Options * GetOptions () { - return &m_options; + return &m_option_group; } protected: - - class CommandOptions : public Options - { - public: - - CommandOptions (CommandInterpreter &interpreter) : - Options (interpreter), - os_version_major (UINT32_MAX), - os_version_minor (UINT32_MAX), - os_version_update (UINT32_MAX) - { - } - - virtual - ~CommandOptions () - { - } - - virtual Error - SetOptionValue (int option_idx, const char *option_arg) - { - Error error; - char short_option = (char) m_getopt_table[option_idx].val; - - switch (short_option) - { - case 'v': - if (Args::StringToVersion (option_arg, - os_version_major, - os_version_minor, - os_version_update) == option_arg) - { - error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg); - } - break; - - default: - error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); - break; - } - - return error; - } - - void - ResetOptionValues () - { - os_version_major = UINT32_MAX; - os_version_minor = UINT32_MAX; - os_version_update = UINT32_MAX; - } - - const OptionDefinition* - GetDefinitions () - { - return g_option_table; - } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - - uint32_t os_version_major; - uint32_t os_version_minor; - uint32_t os_version_update; - }; - CommandOptions m_options; -}; - -OptionDefinition -CommandObjectPlatformCreate::CommandOptions::g_option_table[] = -{ - { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }, - { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } + OptionGroupOptions m_option_group; + PlatformOptionGroup m_platform_options; }; //---------------------------------------------------------------------- @@ -256,37 +285,6 @@ public: } }; - -//---------------------------------------------------------------------- -// "platform select <platform-name>" -//---------------------------------------------------------------------- -class CommandObjectPlatformSelect : public CommandObject -{ -public: - CommandObjectPlatformSelect (CommandInterpreter &interpreter) : - CommandObject (interpreter, - "platform select", - "Select a platform by name to be the currently selected platform.", - "platform select <platform-name>", - 0) - { - } - - virtual - ~CommandObjectPlatformSelect () - { - } - - virtual bool - Execute (Args& args, CommandReturnObject &result) - { - result.AppendError ("command not implemented\n"); - result.SetStatus (eReturnStatusFailed); - return result.Succeeded(); - } -}; - - //---------------------------------------------------------------------- // "platform connect <connect-url>" //---------------------------------------------------------------------- @@ -683,7 +681,7 @@ protected: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -773,7 +771,7 @@ protected: } void - ResetOptionValues () + OptionParsingStarting () { match_info.Clear(); show_args = false; @@ -956,11 +954,10 @@ CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) : CommandObjectMultiword (interpreter, "platform", "A set of commands to manage and create platforms.", - "platform [connect|create|disconnect|info|list|status|select] ...") + "platform [connect|disconnect|info|list|status|select] ...") { - LoadSubCommand ("create", CommandObjectSP (new CommandObjectPlatformCreate (interpreter))); - LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter))); LoadSubCommand ("select", CommandObjectSP (new CommandObjectPlatformSelect (interpreter))); + LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter))); LoadSubCommand ("status", CommandObjectSP (new CommandObjectPlatformStatus (interpreter))); LoadSubCommand ("connect", CommandObjectSP (new CommandObjectPlatformConnect (interpreter))); LoadSubCommand ("disconnect", CommandObjectSP (new CommandObjectPlatformDisconnect (interpreter))); diff --git a/lldb/source/Commands/CommandObjectPlatform.h b/lldb/source/Commands/CommandObjectPlatform.h index 994052e..255fc3b 100644 --- a/lldb/source/Commands/CommandObjectPlatform.h +++ b/lldb/source/Commands/CommandObjectPlatform.h @@ -15,6 +15,7 @@ // Other libraries and framework includes // Project includes #include "lldb/Interpreter/CommandObjectMultiword.h" +#include "lldb/Interpreter/Options.h" namespace lldb_private { @@ -25,21 +26,74 @@ namespace lldb_private { class CommandObjectPlatform : public CommandObjectMultiword { public: - //------------------------------------------------------------------ - // Constructors and Destructors - //------------------------------------------------------------------ CommandObjectPlatform(CommandInterpreter &interpreter); virtual ~CommandObjectPlatform(); -private: - //------------------------------------------------------------------ - // For CommandObjectPlatform only - //------------------------------------------------------------------ + private: DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatform); }; + +//------------------------------------------------------------------------- +// PlatformOptionGroup +// +// Make platform options available to to any other command in case they +// need them. The "file" command needs them, and by exposing them we can +// reuse the platform command options for any command, we can keep things +// consistent. +//------------------------------------------------------------------------- +class PlatformOptionGroup : public OptionGroup +{ +public: + + PlatformOptionGroup (bool include_platform_option) : + m_include_platform_option (include_platform_option), + platform_sp (), + os_version_major (UINT32_MAX), + os_version_minor (UINT32_MAX), + os_version_update (UINT32_MAX) + { + } + + virtual + ~PlatformOptionGroup () + { + } + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions (); + + virtual Error + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value); + + lldb::PlatformSP + CreatePlatformWithOptions (CommandInterpreter &interpreter, + const char *platform_name, + bool select, + Error& error); + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter); + + // Instance variables to hold the values for command options. + + lldb::PlatformSP platform_sp; + uint32_t os_version_major; + uint32_t os_version_minor; + uint32_t os_version_update; +protected: + bool m_include_platform_option; +}; + + + } // namespace lldb_private #endif // liblldb_CommandObjectPlatform_h_ diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 1fc573b..aed04bd 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -43,8 +43,8 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } ~CommandOptions () @@ -52,7 +52,7 @@ public: } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -80,7 +80,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { stop_at_entry = false; in_new_tty = false; @@ -423,8 +423,8 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } ~CommandOptions () @@ -432,7 +432,7 @@ public: } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -467,7 +467,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { pid = LLDB_INVALID_PROCESS_ID; name.clear(); @@ -973,8 +973,8 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } ~CommandOptions () @@ -982,7 +982,7 @@ public: } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -1001,7 +1001,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { plugin_name.clear(); } @@ -1559,7 +1559,7 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options (interpreter) { - ResetOptionValues (); + OptionParsingStarting (); } ~CommandOptions () @@ -1567,7 +1567,7 @@ public: } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -1591,7 +1591,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { stop.clear(); notify.clear(); diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 2607854..d3c8d63 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -159,7 +159,7 @@ protected: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - ResetOptionValues(); + OptionParsingStarting(); } virtual @@ -168,7 +168,7 @@ protected: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -186,7 +186,7 @@ protected: } void - ResetOptionValues () + OptionParsingStarting () { m_format = eFormatBytes; } diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index b5cf326..02a3287 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -263,7 +263,7 @@ CommandObjectSettingsSet::CommandOptions::GetDefinitions () } Error -CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) +CommandObjectSettingsSet::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -285,7 +285,7 @@ CommandObjectSettingsSet::CommandOptions::SetOptionValue (int option_idx, const } void -CommandObjectSettingsSet::CommandOptions::ResetOptionValues () +CommandObjectSettingsSet::CommandOptions::OptionParsingStarting () { m_override = true; m_reset = false; diff --git a/lldb/source/Commands/CommandObjectSettings.h b/lldb/source/Commands/CommandObjectSettings.h index 170b7f2..13f781f 100644 --- a/lldb/source/Commands/CommandObjectSettings.h +++ b/lldb/source/Commands/CommandObjectSettings.h @@ -65,10 +65,10 @@ public: ~CommandOptions (); virtual Error - SetOptionValue (int option_idx, const char *option_arg); + SetOptionValue (uint32_t option_idx, const char *option_arg); void - ResetOptionValues (); + OptionParsingStarting (); const OptionDefinition* GetDefinitions (); diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index 29b17dc..4cca075 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -47,7 +47,7 @@ class CommandObjectSourceInfo : public CommandObject } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; const char short_option = g_option_table[option_idx].short_option; @@ -72,7 +72,7 @@ class CommandObjectSourceInfo : public CommandObject } void - ResetOptionValues () + OptionParsingStarting () { file_spec.Clear(); file_name.clear(); @@ -159,7 +159,7 @@ class CommandObjectSourceList : public CommandObject } Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; const char short_option = g_option_table[option_idx].short_option; @@ -197,7 +197,7 @@ class CommandObjectSourceList : public CommandObject } void - ResetOptionValues () + OptionParsingStarting () { file_spec.Clear(); file_name.clear(); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 7686620..5a90bfb 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -508,7 +508,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -587,7 +587,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_class_name.clear(); m_function_name.clear(); diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index f321000..fd90720 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -252,8 +252,8 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options(interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } virtual @@ -262,7 +262,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -298,7 +298,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_count = -1; m_start = 0; @@ -490,8 +490,8 @@ public: CommandOptions (CommandInterpreter &interpreter) : Options (interpreter) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } virtual @@ -500,7 +500,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -542,7 +542,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_avoid_no_debug = true; m_run_mode = eOnlyDuringStepping; @@ -981,8 +981,8 @@ public: m_thread_idx(LLDB_INVALID_THREAD_ID), m_frame_idx(LLDB_INVALID_FRAME_ID) { - // Keep default values of all options in one place: ResetOptionValues () - ResetOptionValues (); + // Keep default values of all options in one place: OptionParsingStarting () + OptionParsingStarting (); } virtual @@ -991,7 +991,7 @@ public: } virtual Error - SetOptionValue (int option_idx, const char *option_arg) + SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; @@ -1040,7 +1040,7 @@ public: } void - ResetOptionValues () + OptionParsingStarting () { m_thread_idx = LLDB_INVALID_THREAD_ID; m_frame_idx = 0; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 16c68ec..baf4fcb 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -177,7 +177,7 @@ CommandObject::ParseOptions if (options != NULL) { Error error; - options->Reset(); + options->NotifyOptionParsingStarting(); // ParseOptions calls getopt_long, 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. @@ -187,7 +187,15 @@ CommandObject::ParseOptions // The "dummy_string" will have already been removed by ParseOptions, // so no need to remove it. - if (error.Fail() || !options->VerifyOptions (result)) + if (error.Success()) + error = options->NotifyOptionParsingFinished(); + + if (error.Success()) + { + if (options->VerifyOptions (result)) + return true; + } + else { const char *error_cstr = error.AsCString(); if (error_cstr) @@ -200,10 +208,9 @@ CommandObject::ParseOptions // No error string, output the usage information into result options->GenerateOptionUsage (result.GetErrorStream(), this); } - // Set the return status to failed (this was an error). - result.SetStatus (eReturnStatusFailed); - return false; } + result.SetStatus (eReturnStatusFailed); + return false; } return true; } diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 3c14cc0..8f1e10a 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -41,11 +41,17 @@ Options::~Options () } void -Options::Reset () +Options::NotifyOptionParsingStarting () { m_seen_options.clear(); // Let the subclass reset its option values - ResetOptionValues (); + OptionParsingStarting (); +} + +Error +Options::NotifyOptionParsingFinished () +{ + return OptionParsingFinished (); } void @@ -885,3 +891,80 @@ Options::HandleOptionArgumentCompletion matches); } + + + + +void +OptionGroupOptions::Append (OptionGroup* group) +{ + m_option_groups.push_back (group); + const OptionDefinition* group_option_defs = group->GetDefinitions (); + const uint32_t group_option_count = group->GetNumDefinitions(); + for (uint32_t i=0; i<group_option_count; ++i) + m_option_defs.push_back (group_option_defs[i]); +} + +void +OptionGroupOptions::Append (OptionGroup* group, uint32_t usage_mask) +{ + m_option_groups.push_back (group); + const OptionDefinition* group_option_defs = group->GetDefinitions (); + const uint32_t group_option_count = group->GetNumDefinitions(); + for (uint32_t i=0; i<group_option_count; ++i) + { + m_option_defs.push_back (group_option_defs[i]); + m_option_defs.back().usage_mask = usage_mask; + } +} + +void +OptionGroupOptions::Finalize () +{ + m_did_finalize = true; + OptionDefinition empty_option_def = { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }; + m_option_defs.push_back (empty_option_def); +} + +Error +OptionGroupOptions::SetOptionValue (uint32_t option_idx, + const char *option_value) +{ + // After calling OptionGroupOptions::Append(...), you must finalize the groups + // by calling OptionGroupOptions::Finlize() + assert (m_did_finalize); + + uint32_t curr_idx = 0; + OptionGroupsType::iterator pos, end = m_option_groups.end(); + for (pos = m_option_groups.begin(); pos != end; ++pos) + { + const uint32_t num_group_definitions = (*pos)->GetNumDefinitions(); + if (option_idx < curr_idx + num_group_definitions) + return (*pos)->SetOptionValue (m_interpreter, option_idx - curr_idx, option_value); + curr_idx += num_group_definitions; + } + Error error; + error.SetErrorString ("invalid option index"); // Shouldn't happen... + return error; +} + +void +OptionGroupOptions::OptionParsingStarting () +{ + OptionGroupsType::iterator pos, end = m_option_groups.end(); + for (pos = m_option_groups.begin(); pos != end; ++pos) + (*pos)->OptionParsingStarting (m_interpreter); +} +Error +OptionGroupOptions::OptionParsingFinished () +{ + Error error; + OptionGroupsType::iterator pos, end = m_option_groups.end(); + for (pos = m_option_groups.begin(); pos != end; ++pos) + { + error = (*pos)->OptionParsingFinished (m_interpreter); + if (error.Fail()) + return error; + } + return error; +} diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index c33dd18..26d84b9 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -346,7 +346,7 @@ ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (posix_spawn_file_actions } Error -ProcessLaunchCommandOptions::SetOptionValue (int option_idx, const char *option_arg) +ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) { Error error; char short_option = (char) m_getopt_table[option_idx].val; |