From e1cfbc79420fee0b71bad62f8d413b68a0eca91e Mon Sep 17 00:00:00 2001 From: Todd Fiala Date: Thu, 11 Aug 2016 23:51:28 +0000 Subject: [PATCH] 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/include/lldb/Interpreter/Args.h | 14 +- .../lldb/Interpreter/OptionGroupArchitecture.h | 8 +- lldb/include/lldb/Interpreter/OptionGroupBoolean.h | 8 +- lldb/include/lldb/Interpreter/OptionGroupFile.h | 16 +-- lldb/include/lldb/Interpreter/OptionGroupFormat.h | 10 +- .../lldb/Interpreter/OptionGroupOutputFile.h | 8 +- .../include/lldb/Interpreter/OptionGroupPlatform.h | 8 +- lldb/include/lldb/Interpreter/OptionGroupString.h | 8 +- lldb/include/lldb/Interpreter/OptionGroupUInt64.h | 8 +- lldb/include/lldb/Interpreter/OptionGroupUUID.h | 8 +- .../Interpreter/OptionGroupValueObjectDisplay.h | 8 +- .../include/lldb/Interpreter/OptionGroupVariable.h | 8 +- .../lldb/Interpreter/OptionGroupWatchpoint.h | 8 +- lldb/include/lldb/Interpreter/Options.h | 53 ++++---- lldb/include/lldb/Target/Platform.h | 24 ++-- lldb/include/lldb/Target/Process.h | 11 +- lldb/source/Commands/CommandObjectArgs.cpp | 11 +- lldb/source/Commands/CommandObjectArgs.h | 5 +- lldb/source/Commands/CommandObjectBreakpoint.cpp | 79 ++++++------ .../Commands/CommandObjectBreakpointCommand.cpp | 24 ++-- lldb/source/Commands/CommandObjectBugreport.cpp | 2 +- lldb/source/Commands/CommandObjectCommands.cpp | 80 ++++++------ lldb/source/Commands/CommandObjectDisassemble.cpp | 58 ++++++--- lldb/source/Commands/CommandObjectDisassemble.h | 9 +- lldb/source/Commands/CommandObjectExpression.cpp | 25 ++-- lldb/source/Commands/CommandObjectExpression.h | 8 +- lldb/source/Commands/CommandObjectFrame.cpp | 24 ++-- lldb/source/Commands/CommandObjectHelp.cpp | 2 +- lldb/source/Commands/CommandObjectHelp.h | 9 +- lldb/source/Commands/CommandObjectLog.cpp | 15 ++- lldb/source/Commands/CommandObjectMemory.cpp | 30 ++--- lldb/source/Commands/CommandObjectPlatform.cpp | 97 ++++++++------ lldb/source/Commands/CommandObjectPlugin.cpp | 4 +- lldb/source/Commands/CommandObjectProcess.cpp | 87 +++++++------ lldb/source/Commands/CommandObjectRegister.cpp | 10 +- lldb/source/Commands/CommandObjectSettings.cpp | 32 ++--- lldb/source/Commands/CommandObjectSource.cpp | 32 +++-- lldb/source/Commands/CommandObjectTarget.cpp | 104 ++++++++------- lldb/source/Commands/CommandObjectThread.cpp | 110 ++++++++-------- lldb/source/Commands/CommandObjectType.cpp | 142 ++++++++++++--------- lldb/source/Commands/CommandObjectWatchpoint.cpp | 43 ++++--- .../Commands/CommandObjectWatchpointCommand.cpp | 11 +- lldb/source/Expression/REPL.cpp | 8 +- lldb/source/Interpreter/Args.cpp | 45 ++++++- lldb/source/Interpreter/CommandAlias.cpp | 5 +- lldb/source/Interpreter/CommandObject.cpp | 25 +++- .../Interpreter/CommandObjectRegexCommand.cpp | 2 +- .../source/Interpreter/OptionGroupArchitecture.cpp | 9 +- lldb/source/Interpreter/OptionGroupBoolean.cpp | 8 +- lldb/source/Interpreter/OptionGroupFile.cpp | 16 +-- lldb/source/Interpreter/OptionGroupFormat.cpp | 29 +++-- lldb/source/Interpreter/OptionGroupOutputFile.cpp | 9 +- lldb/source/Interpreter/OptionGroupPlatform.cpp | 8 +- lldb/source/Interpreter/OptionGroupString.cpp | 8 +- lldb/source/Interpreter/OptionGroupUInt64.cpp | 8 +- lldb/source/Interpreter/OptionGroupUUID.cpp | 8 +- .../Interpreter/OptionGroupValueObjectDisplay.cpp | 19 +-- lldb/source/Interpreter/OptionGroupVariable.cpp | 8 +- lldb/source/Interpreter/OptionGroupWatchpoint.cpp | 9 +- lldb/source/Interpreter/OptionValueArch.cpp | 1 + lldb/source/Interpreter/OptionValueFileSpec.cpp | 1 + lldb/source/Interpreter/Options.cpp | 39 +++--- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 11 +- .../RenderScriptRuntime/RenderScriptRuntime.cpp | 27 ++-- .../Plugins/Platform/POSIX/PlatformPOSIX.cpp | 2 +- .../Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp | 2 +- .../Process/gdb-remote/ProcessGDBRemote.cpp | 2 +- lldb/source/Target/Platform.cpp | 26 ++-- lldb/source/Target/Process.cpp | 14 +- 69 files changed, 915 insertions(+), 695 deletions(-) diff --git a/lldb/include/lldb/Interpreter/Args.h b/lldb/include/lldb/Interpreter/Args.h index bd54d5d..6570ca1 100644 --- a/lldb/include/lldb/Interpreter/Args.h +++ b/lldb/include/lldb/Interpreter/Args.h @@ -314,10 +314,22 @@ public: /// get processed start at the second argument. The first argument /// is assumed to be the command and will not be touched. /// + /// param[in] platform_sp + /// The platform used for option validation. This is necessary + /// because an empty execution_context is not enough to get us + /// to a reasonable platform. If the platform isn't given, + /// we'll try to get it from the execution context. If we can't + /// get it from the execution context, we'll skip validation. + /// + /// param[in] require_validation + /// When true, it will fail option parsing if validation could + /// not occur due to not having a platform. + /// /// @see class Options //------------------------------------------------------------------ Error - ParseOptions (Options &options); + ParseOptions (Options &options, ExecutionContext *execution_context, + lldb::PlatformSP platform_sp, bool require_validation); size_t FindArgumentIndexForOption (Option *long_options, int long_options_index); diff --git a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h index 5ee6085..272365f 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h +++ b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h @@ -37,12 +37,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; bool GetArchitecture (Platform *platform, ArchSpec &arch); diff --git a/lldb/include/lldb/Interpreter/OptionGroupBoolean.h b/lldb/include/lldb/Interpreter/OptionGroupBoolean.h index 881a1bd..ed83326 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupBoolean.h +++ b/lldb/include/lldb/Interpreter/OptionGroupBoolean.h @@ -51,12 +51,12 @@ namespace lldb_private { } Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; OptionValueBoolean & GetOptionValue () diff --git a/lldb/include/lldb/Interpreter/OptionGroupFile.h b/lldb/include/lldb/Interpreter/OptionGroupFile.h index 9e35dd4..5b63b84 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupFile.h +++ b/lldb/include/lldb/Interpreter/OptionGroupFile.h @@ -50,12 +50,12 @@ public: } Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; OptionValueFileSpec & GetOptionValue () @@ -105,12 +105,12 @@ public: } Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; OptionValueFileSpecList & GetOptionValue () diff --git a/lldb/include/lldb/Interpreter/OptionGroupFormat.h b/lldb/include/lldb/Interpreter/OptionGroupFormat.h index 9a96cc5..36f5254 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupFormat.h +++ b/lldb/include/lldb/Interpreter/OptionGroupFormat.h @@ -46,12 +46,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; lldb::Format GetFormat () const @@ -111,7 +111,7 @@ public: protected: bool - ParserGDBFormatLetter (CommandInterpreter &interpreter, + ParserGDBFormatLetter (ExecutionContext *execution_context, char format_letter, lldb::Format &format, uint32_t &byte_size); diff --git a/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h b/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h index e608371..a29f224 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h +++ b/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h @@ -37,12 +37,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; const OptionValueFileSpec & GetFile () diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h index 6888023..089cb83 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h +++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h @@ -47,12 +47,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; lldb::PlatformSP CreatePlatformWithOptions (CommandInterpreter &interpreter, diff --git a/lldb/include/lldb/Interpreter/OptionGroupString.h b/lldb/include/lldb/Interpreter/OptionGroupString.h index 6f46bdb..e63fcf0 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupString.h +++ b/lldb/include/lldb/Interpreter/OptionGroupString.h @@ -49,12 +49,12 @@ namespace lldb_private { } Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; OptionValueString & GetOptionValue () diff --git a/lldb/include/lldb/Interpreter/OptionGroupUInt64.h b/lldb/include/lldb/Interpreter/OptionGroupUInt64.h index b03c1ff..0bf24c5 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupUInt64.h +++ b/lldb/include/lldb/Interpreter/OptionGroupUInt64.h @@ -50,12 +50,12 @@ namespace lldb_private { } Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; OptionValueUInt64 & GetOptionValue () diff --git a/lldb/include/lldb/Interpreter/OptionGroupUUID.h b/lldb/include/lldb/Interpreter/OptionGroupUUID.h index 6495699..bee647e 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupUUID.h +++ b/lldb/include/lldb/Interpreter/OptionGroupUUID.h @@ -37,12 +37,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; const OptionValueUUID & GetOptionValue () const diff --git a/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h b/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h index 86e4c16..0f52829 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h +++ b/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h @@ -37,12 +37,12 @@ public: GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_value) override; + SetOptionValue(uint32_t option_idx, + const char *option_value, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; bool AnyOptionWasSet () const diff --git a/lldb/include/lldb/Interpreter/OptionGroupVariable.h b/lldb/include/lldb/Interpreter/OptionGroupVariable.h index fd338f1..1b4ce0c 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupVariable.h +++ b/lldb/include/lldb/Interpreter/OptionGroupVariable.h @@ -37,12 +37,12 @@ namespace lldb_private { GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_arg) override; + SetOptionValue(uint32_t option_idx, + const char *option_arg, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; bool include_frame_options:1, show_args:1, // Frame option only (include_frame_options == true) diff --git a/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h b/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h index ddc4393..c00c717 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h +++ b/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h @@ -39,12 +39,12 @@ namespace lldb_private { GetDefinitions() override; Error - SetOptionValue(CommandInterpreter &interpreter, - uint32_t option_idx, - const char *option_arg) override; + SetOptionValue(uint32_t option_idx, + const char *option_arg, + ExecutionContext *execution_context) override; void - OptionParsingStarting(CommandInterpreter &interpreter) override; + OptionParsingStarting(ExecutionContext *execution_context) override; // Note: // eWatchRead == LLDB_WATCH_TYPE_READ; and diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index bac2630..7e376a7 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -117,7 +117,7 @@ namespace lldb_private { class Options { public: - Options (CommandInterpreter &interpreter); + Options (); virtual ~Options (); @@ -160,7 +160,8 @@ public: void GenerateOptionUsage (Stream &strm, - CommandObject *cmd); + CommandObject *cmd, + uint32_t screen_width); bool SupportsLongOption (const char *long_option); @@ -180,10 +181,10 @@ public: // Option::OptionParsingStarting() like they did before. This was error // prone and subclasses shouldn't have to do it. void - NotifyOptionParsingStarting (); + NotifyOptionParsingStarting (ExecutionContext *execution_context); Error - NotifyOptionParsingFinished (); + NotifyOptionParsingFinished (ExecutionContext *execution_context); //------------------------------------------------------------------ /// Set the value of an option. @@ -196,12 +197,17 @@ public: /// The argument value for the option that the user entered, or /// nullptr if there is no argument for the current option. /// + /// @param[in] execution_context + /// The execution context to use for evaluating the option. + /// May be nullptr if the option is to be evaluated outside any + /// particular context. /// /// @see Args::ParseOptions (Options&) /// @see man getopt_long_only //------------------------------------------------------------------ virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg) = 0; + SetOptionValue (uint32_t option_idx, const char *option_arg, + ExecutionContext *execution_context) = 0; //------------------------------------------------------------------ /// Handles the generic bits of figuring out whether we are in an @@ -245,6 +251,7 @@ public: int char_pos, int match_start_point, int max_return_elements, + CommandInterpreter &interpreter, bool &word_complete, lldb_private::StringList &matches); @@ -276,6 +283,9 @@ public: /// See CommandObject::HandleCompletions for a description of /// how these work. /// + /// @param[in] interpreter + /// The command interpreter in which we're doing completion. + /// /// @param[out] word_complete /// \btrue if this is a complete option value (a space will /// be inserted after the completion.) \bfalse otherwise. @@ -298,21 +308,15 @@ public: int opt_element_index, int match_start_point, int max_return_elements, + CommandInterpreter &interpreter, bool &word_complete, StringList &matches); - CommandInterpreter& - GetInterpreter() - { - return m_interpreter; - } - protected: // This is a set of options expressed as indexes into the options table for this Option. typedef std::set OptionSet; typedef std::vector OptionSetVector; - CommandInterpreter &m_interpreter; std::vector