Index: lldb/include/lldb/Interpreter/Options.h =================================================================== --- lldb/include/lldb/Interpreter/Options.h +++ lldb/include/lldb/Interpreter/Options.h @@ -155,7 +155,7 @@ void GenerateOptionUsage(Stream &strm, CommandObject *cmd, uint32_t screen_width); - bool SupportsLongOption(const char *long_option); + bool SupportsLongOption(llvm::StringRef long_option); // The following two pure virtual functions must be defined by every // class that inherits from this class. Index: lldb/include/lldb/lldb-private-types.h =================================================================== --- lldb/include/lldb/lldb-private-types.h +++ lldb/include/lldb/lldb-private-types.h @@ -104,22 +104,51 @@ }; struct OptionDefinition { - uint32_t usage_mask; // Used to mark options that can be used together. If (1 - // << n & usage_mask) != 0 - // then this option belongs to option set n. - bool required; // This option is required (in the current usage level) - const char *long_option; // Full name for this option. - int short_option; // Single character for this option. - int option_has_arg; // no_argument, required_argument or optional_argument - OptionValidator *validator; // If non-NULL, option is valid iff - // |validator->IsValid()|, otherwise always valid. - OptionEnumValueElement *enum_values; // If non-NULL an array of enum values. - uint32_t completion_type; // Cookie the option class can use to do define the - // argument completion. - lldb::CommandArgumentType argument_type; // Type of argument this option takes - const char *usage_text; // Full text explaining what this options does and - // what (if any) argument to - // pass it. + OptionDefinition() {} + + constexpr OptionDefinition(uint32_t mask, bool required, + llvm::StringRef long_opt, int short_opt, + int has_arg, OptionValidator *validator, + OptionEnumValueElement *enum_values, + uint32_t completion_type, + lldb::CommandArgumentType arg_type, + llvm::StringRef usage) + : usage_mask(mask), required(required), long_option(long_opt), + short_option(short_opt), option_has_arg(has_arg), validator(validator), + enum_values(enum_values), completion_type(completion_type), + argument_type(arg_type), usage_text(usage_text) {} + + // Used to mark options that can be used together. If + // (1 << n & usage_mask) != 0 then this option belongs to option set n. + uint32_t usage_mask = 0; + + // This option is required (in the current usage level) + bool required = false; + + // Full name for this option. + llvm::StringRef long_option; + + // Single character for this option. + int short_option = 0; + + // no_argument, required_argument or optional_argument + int option_has_arg = 0; + + // If non-NULL, option is valid iff |validator->IsValid()|, otherwise always + // valid. + OptionValidator *validator = nullptr; + + // If non-NULL an array of enum values. + OptionEnumValueElement *enum_values = nullptr; + + // Cookie the option class can use to do define the argument completion. + uint32_t completion_type = 0; + + // Type of argument this option takes + lldb::CommandArgumentType argument_type = lldb::eArgTypeNone; + + // Full text explaining what this options does and what argument(s) it takes. + llvm::StringRef usage_text; }; typedef struct type128 { uint64_t x[2]; } type128; Index: lldb/source/Commands/CommandObjectSettings.cpp =================================================================== --- lldb/source/Commands/CommandObjectSettings.cpp +++ lldb/source/Commands/CommandObjectSettings.cpp @@ -27,9 +27,11 @@ // CommandObjectSettingsSet //------------------------------------------------------------------------- -static OptionDefinition g_settings_set_options[] = { +using L = llvm::StringLiteral; + +static constexpr OptionDefinition g_settings_set_options[] = { // clang-format off - { LLDB_OPT_SET_2, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Apply the new value to the global default value." } + { LLDB_OPT_SET_2, false, L("global"), 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, L("Apply the new value to the global default value.") } // clang-format on }; Index: lldb/source/Host/common/OptionParser.cpp =================================================================== --- lldb/source/Host/common/OptionParser.cpp +++ lldb/source/Host/common/OptionParser.cpp @@ -11,6 +11,9 @@ #include "lldb/Host/HostGetOpt.h" #include "lldb/lldb-private-types.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/StringSaver.h" + #include using namespace lldb_private; @@ -31,11 +34,14 @@ int OptionParser::Parse(int argc, char *const argv[], llvm::StringRef optstring, const Option *longopts, int *longindex) { std::vector