From 1f0f5b5b9eeaea93126583b40070091baf3bc92d Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Thu, 22 Sep 2016 20:22:55 +0000 Subject: [PATCH] Convert option tables to ArrayRefs. This change is very mechanical. All it does is change the signature of `Options::GetDefinitions()` and `OptionGroup:: GetDefinitions()` to return an `ArrayRef` instead of a `const OptionDefinition *`. In the case of the former, it deletes the sentinel entry from every table, and in the case of the latter, it removes the `GetNumDefinitions()` method from the interface. These are no longer necessary as `ArrayRef` carries its own length. In the former case, iteration was done by using a sentinel entry, so there was no knowledge of length. Because of this the individual option tables were allowed to be defined below the corresponding class (after all, only a pointer was needed). Now, however, the length must be known at compile time to construct the `ArrayRef`, and as a result it is necessary to move every option table before its corresponding class. This results in this CL looking very big, but in terms of substance there is not much here. Differential revision: https://reviews.llvm.org/D24834 llvm-svn: 282188 --- .../lldb/Interpreter/OptionGroupArchitecture.h | 4 +- lldb/include/lldb/Interpreter/OptionGroupBoolean.h | 6 +- lldb/include/lldb/Interpreter/OptionGroupFile.h | 12 +- lldb/include/lldb/Interpreter/OptionGroupFormat.h | 4 +- .../lldb/Interpreter/OptionGroupOutputFile.h | 4 +- .../include/lldb/Interpreter/OptionGroupPlatform.h | 4 +- lldb/include/lldb/Interpreter/OptionGroupString.h | 6 +- lldb/include/lldb/Interpreter/OptionGroupUInt64.h | 6 +- lldb/include/lldb/Interpreter/OptionGroupUUID.h | 4 +- .../Interpreter/OptionGroupValueObjectDisplay.h | 4 +- .../include/lldb/Interpreter/OptionGroupVariable.h | 4 +- .../lldb/Interpreter/OptionGroupWatchpoint.h | 4 +- lldb/include/lldb/Interpreter/Options.h | 14 +- lldb/include/lldb/Target/Platform.h | 12 +- lldb/include/lldb/Target/Process.h | 6 +- lldb/source/Commands/CommandObjectArgs.cpp | 18 +- lldb/source/Commands/CommandObjectArgs.h | 6 +- lldb/source/Commands/CommandObjectBreakpoint.cpp | 380 ++++++++++----------- .../Commands/CommandObjectBreakpointCommand.cpp | 80 ++--- lldb/source/Commands/CommandObjectCommands.cpp | 176 +++++----- lldb/source/Commands/CommandObjectDisassemble.cpp | 59 ++-- lldb/source/Commands/CommandObjectDisassemble.h | 2 +- lldb/source/Commands/CommandObjectExpression.cpp | 14 +- lldb/source/Commands/CommandObjectExpression.h | 4 +- lldb/source/Commands/CommandObjectFrame.cpp | 45 ++- lldb/source/Commands/CommandObjectHelp.cpp | 8 +- lldb/source/Commands/CommandObjectHelp.h | 6 +- lldb/source/Commands/CommandObjectLog.cpp | 39 +-- lldb/source/Commands/CommandObjectMemory.cpp | 22 +- lldb/source/Commands/CommandObjectPlatform.cpp | 165 ++++----- lldb/source/Commands/CommandObjectProcess.cpp | 152 ++++----- lldb/source/Commands/CommandObjectRegister.cpp | 34 +- lldb/source/Commands/CommandObjectSettings.cpp | 21 +- lldb/source/Commands/CommandObjectSource.cpp | 68 ++-- lldb/source/Commands/CommandObjectTarget.cpp | 201 +++++------ lldb/source/Commands/CommandObjectThread.cpp | 210 ++++++------ lldb/source/Commands/CommandObjectType.cpp | 298 +++++++--------- lldb/source/Commands/CommandObjectWatchpoint.cpp | 89 +++-- .../Commands/CommandObjectWatchpointCommand.cpp | 56 ++- lldb/source/Interpreter/Args.cpp | 14 +- .../source/Interpreter/OptionGroupArchitecture.cpp | 6 +- lldb/source/Interpreter/OptionGroupFormat.cpp | 13 +- lldb/source/Interpreter/OptionGroupOutputFile.cpp | 6 +- lldb/source/Interpreter/OptionGroupPlatform.cpp | 13 +- lldb/source/Interpreter/OptionGroupUUID.cpp | 6 +- .../Interpreter/OptionGroupValueObjectDisplay.cpp | 12 +- lldb/source/Interpreter/OptionGroupVariable.cpp | 20 +- lldb/source/Interpreter/OptionGroupWatchpoint.cpp | 6 +- lldb/source/Interpreter/Options.cpp | 184 +++++----- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 17 +- .../RenderScriptRuntime/RenderScriptRuntime.cpp | 57 ++-- .../DarwinLog/StructuredDataDarwinLog.cpp | 204 ++++++----- lldb/source/Target/Platform.cpp | 20 +- lldb/source/Target/Process.cpp | 8 +- 54 files changed, 1246 insertions(+), 1587 deletions(-) diff --git a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h index ffdcc1c..8e28b9a 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h +++ b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h @@ -29,9 +29,7 @@ public: ~OptionGroupArchitecture() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupBoolean.h b/lldb/include/lldb/Interpreter/OptionGroupBoolean.h index c028a3d..24648a9 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupBoolean.h +++ b/lldb/include/lldb/Interpreter/OptionGroupBoolean.h @@ -34,10 +34,8 @@ public: ~OptionGroupBoolean() override; - uint32_t GetNumDefinitions() override { return 1; } - - const OptionDefinition *GetDefinitions() override { - return &m_option_definition; + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(&m_option_definition, 1); } Error SetOptionValue(uint32_t option_idx, const char *option_value, diff --git a/lldb/include/lldb/Interpreter/OptionGroupFile.h b/lldb/include/lldb/Interpreter/OptionGroupFile.h index 440dc3b..ed112b1 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupFile.h +++ b/lldb/include/lldb/Interpreter/OptionGroupFile.h @@ -33,10 +33,8 @@ public: ~OptionGroupFile() override; - uint32_t GetNumDefinitions() override { return 1; } - - const OptionDefinition *GetDefinitions() override { - return &m_option_definition; + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(&m_option_definition, 1); } Error SetOptionValue(uint32_t option_idx, const char *option_value, @@ -67,10 +65,8 @@ public: ~OptionGroupFileList() override; - uint32_t GetNumDefinitions() override { return 1; } - - const OptionDefinition *GetDefinitions() override { - return &m_option_definition; + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(&m_option_definition, 1); } Error SetOptionValue(uint32_t option_idx, const char *option_value, diff --git a/lldb/include/lldb/Interpreter/OptionGroupFormat.h b/lldb/include/lldb/Interpreter/OptionGroupFormat.h index fb958a3..a387ca5 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupFormat.h +++ b/lldb/include/lldb/Interpreter/OptionGroupFormat.h @@ -41,9 +41,7 @@ public: ~OptionGroupFormat() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h b/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h index 1daedec..51384d0 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h +++ b/lldb/include/lldb/Interpreter/OptionGroupOutputFile.h @@ -29,9 +29,7 @@ public: ~OptionGroupOutputFile() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h index d1223bf..467b778 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h +++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h @@ -34,9 +34,7 @@ public: ~OptionGroupPlatform() override = default; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupString.h b/lldb/include/lldb/Interpreter/OptionGroupString.h index ce1b358..7cc1b15 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupString.h +++ b/lldb/include/lldb/Interpreter/OptionGroupString.h @@ -31,10 +31,8 @@ public: ~OptionGroupString() override; - uint32_t GetNumDefinitions() override { return 1; } - - const OptionDefinition *GetDefinitions() override { - return &m_option_definition; + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(&m_option_definition, 1); } Error SetOptionValue(uint32_t option_idx, const char *option_value, diff --git a/lldb/include/lldb/Interpreter/OptionGroupUInt64.h b/lldb/include/lldb/Interpreter/OptionGroupUInt64.h index 988ea13..2683310 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupUInt64.h +++ b/lldb/include/lldb/Interpreter/OptionGroupUInt64.h @@ -32,10 +32,8 @@ public: ~OptionGroupUInt64() override; - uint32_t GetNumDefinitions() override { return 1; } - - const OptionDefinition *GetDefinitions() override { - return &m_option_definition; + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(&m_option_definition, 1); } Error SetOptionValue(uint32_t option_idx, const char *option_value, diff --git a/lldb/include/lldb/Interpreter/OptionGroupUUID.h b/lldb/include/lldb/Interpreter/OptionGroupUUID.h index 9faacdd..a2f319e 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupUUID.h +++ b/lldb/include/lldb/Interpreter/OptionGroupUUID.h @@ -29,9 +29,7 @@ public: ~OptionGroupUUID() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h b/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h index 66988a6..fa9a993 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h +++ b/lldb/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h @@ -29,9 +29,7 @@ public: ~OptionGroupValueObjectDisplay() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupVariable.h b/lldb/include/lldb/Interpreter/OptionGroupVariable.h index ecb4e0f..23f2a04 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupVariable.h +++ b/lldb/include/lldb/Interpreter/OptionGroupVariable.h @@ -29,9 +29,7 @@ public: ~OptionGroupVariable() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h b/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h index 63ccffd..803fefd 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h +++ b/lldb/include/lldb/Interpreter/OptionGroupWatchpoint.h @@ -30,9 +30,7 @@ public: static bool IsWatchSizeSupported(uint32_t watch_size); - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override; diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index f57dde5..7e19708 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -21,6 +21,8 @@ #include "lldb/lldb-defines.h" #include "lldb/lldb-private.h" +#include "llvm/ADT/ArrayRef.h" + namespace lldb_private { static inline bool isprint8(int ch) { @@ -158,7 +160,9 @@ public: // The following two pure virtual functions must be defined by every // class that inherits from this class. - virtual const OptionDefinition *GetDefinitions() { return nullptr; } + virtual llvm::ArrayRef GetDefinitions() { + return llvm::ArrayRef(); + } // Call this prior to parsing any options. This call will call the // subclass OptionParsingStarting() and will avoid the need for all @@ -335,9 +339,7 @@ public: virtual ~OptionGroup() = default; - virtual uint32_t GetNumDefinitions() = 0; - - virtual const OptionDefinition *GetDefinitions() = 0; + virtual llvm::ArrayRef GetDefinitions() = 0; virtual Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) = 0; @@ -406,9 +408,9 @@ public: Error OptionParsingFinished(ExecutionContext *execution_context) override; - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { assert(m_did_finalize); - return &m_option_defs[0]; + return m_option_defs; } const OptionGroup *GetGroupWithOption(char short_opt); diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index b6ba615..cb12a9d9 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -1094,9 +1094,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override; - const lldb_private::OptionDefinition *GetDefinitions() override; - - uint32_t GetNumDefinitions() override; + llvm::ArrayRef GetDefinitions() override; // Options table: Required for subclasses of Options. @@ -1125,9 +1123,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override; - uint32_t GetNumDefinitions() override; - - const lldb_private::OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; // Options table: Required for subclasses of Options. @@ -1154,9 +1150,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override; - uint32_t GetNumDefinitions() override; - - const lldb_private::OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; // Options table: Required for subclasses of Options. diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index b112249..908438c 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -293,11 +293,7 @@ public: disable_aslr = eLazyBoolCalculate; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override; // Instance variables to hold the values for command options. diff --git a/lldb/source/Commands/CommandObjectArgs.cpp b/lldb/source/Commands/CommandObjectArgs.cpp index eec83b7..6cd7529 100644 --- a/lldb/source/Commands/CommandObjectArgs.cpp +++ b/lldb/source/Commands/CommandObjectArgs.cpp @@ -37,6 +37,12 @@ using namespace lldb_private; // calling functions. // +static OptionDefinition g_arg_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose debug logging of the expression parsing and evaluation." }, + // clang-format on +}; + CommandObjectArgs::CommandOptions::CommandOptions( CommandInterpreter &interpreter) : Options() { @@ -61,8 +67,9 @@ Error CommandObjectArgs::CommandOptions::SetOptionValue( void CommandObjectArgs::CommandOptions::OptionParsingStarting( ExecutionContext *execution_context) {} -const OptionDefinition *CommandObjectArgs::CommandOptions::GetDefinitions() { - return g_option_table; +llvm::ArrayRef +CommandObjectArgs::CommandOptions::GetDefinitions() { + return g_arg_options; } CommandObjectArgs::CommandObjectArgs(CommandInterpreter &interpreter) @@ -228,10 +235,3 @@ bool CommandObjectArgs::DoExecute(Args &args, CommandReturnObject &result) { return result.Succeeded(); } - -OptionDefinition CommandObjectArgs::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose debug logging of the expression parsing and evaluation."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; diff --git a/lldb/source/Commands/CommandObjectArgs.h b/lldb/source/Commands/CommandObjectArgs.h index 2a154a3..9817c53 100644 --- a/lldb/source/Commands/CommandObjectArgs.h +++ b/lldb/source/Commands/CommandObjectArgs.h @@ -32,11 +32,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override; - const OptionDefinition *GetDefinitions() override; - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override; }; CommandObjectArgs(CommandInterpreter &interpreter); diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index 72e7e12..b68203c 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -45,6 +45,96 @@ static void AddBreakpointDescription(Stream *s, Breakpoint *bp, s->EOL(); } +// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to +// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. +#define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2) +#define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10) +#define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) +#define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) +#define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) +#define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) + +static OptionDefinition g_breakpoint_set_options[] = { + // clang-format off + { LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " + "multiple times to specify multiple shared libraries." }, + { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, + { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The breakpoint is deleted the first time it causes a stop." }, + { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, + { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this " + "argument." }, + { LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints." }, + { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by " + "this argument." }, + { LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " + "lldb only looks for files that are #included if they use the standard include " + "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " + "#included, set target.inline-breakpoint-strategy to \"always\"." }, + { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint." }, + + // Comment out this option for the moment, as we don't actually use it, but will in the future. + // This way users won't see it, but the infrastructure is left in place. + // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "", + // "Set the breakpoint by source location at this particular column."}, + + { LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " + "a particular binary, then the address will be converted to a \"file\" " + "address, so that the breakpoint will track that binary+offset no matter where " + "the binary eventually loads. Alternately, if you also specify the module - " + "with the -s option - then the address will be treated as a file address in " + "that module, and resolved accordingly. Again, this will allow lldb to track " + "that offset on subsequent reloads. The module need not have been loaded at " + "the time you specify this breakpoint, and will get resolved when the module " + "is loaded." }, + { LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " + "one breakpoint for multiple names" }, + { LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " + "functions. Can be repeated multiple times." }, + { LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " + "namespaces and all arguments, and for Objective C this means a full function " + "prototype with class and selector. Can be repeated multiple times to make " + "one breakpoint for multiple names." }, + { LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " + "make one breakpoint for multiple Selectors." }, + { LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " + "make one breakpoint for multiple methods." }, + { LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " + "the function name(s)." }, + { LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " + "ignored). Can be repeated multiple times to make one breakpoint for multiple " + "symbols." }, + { LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " + "against the source text in a source file or files specified with the -f " + "option. The -f option can be specified more than once. If no source files " + "are specified, uses the current \"default source file\". If you want to " + "match against all source files, pass the \"--all-files\" option." }, + { LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches." }, + { LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " + "options, on throw but not catch.)" }, + { LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW." }, + { LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH." }, + + // Don't add this option till it actually does something useful... + // { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, + // "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, + + { LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " + "(note: currently only implemented for setting breakpoints on identifiers). " + "If not set the target.language setting is used." }, + { LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " + "If not set the target.skip-prologue setting is used." }, + { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, " + "which prime new targets." }, + { LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint." }, + { LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " + "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries." }, + { LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " + "setting is used." }, + // clang-format on +}; + //------------------------------------------------------------------------- // CommandObjectBreakpointSet //------------------------------------------------------------------------- @@ -365,11 +455,9 @@ public: m_source_regex_func_names.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_set_options; + } // Instance variables to hold the values for command options. @@ -705,101 +793,26 @@ private: CommandOptions m_options; }; -// If an additional option set beyond LLDB_OPTION_SET_10 is added, make sure to -// update the numbers passed to LLDB_OPT_SET_FROM_TO(...) appropriately. -#define LLDB_OPT_FILE (LLDB_OPT_SET_FROM_TO(1, 9) & ~LLDB_OPT_SET_2) -#define LLDB_OPT_NOT_10 (LLDB_OPT_SET_FROM_TO(1, 10) & ~LLDB_OPT_SET_10) -#define LLDB_OPT_SKIP_PROLOGUE (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) -#define LLDB_OPT_OFFSET_APPLIES (LLDB_OPT_SET_1 | LLDB_OPT_SET_FROM_TO(3, 8)) -#define LLDB_OPT_MOVE_TO_NEAREST_CODE (LLDB_OPT_SET_1 | LLDB_OPT_SET_9) -#define LLDB_OPT_EXPR_LANGUAGE (LLDB_OPT_SET_FROM_TO(3, 8)) - -OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_NOT_10, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the breakpoint only in this shared library. Can repeat this option " - "multiple times to specify multiple shared libraries."}, - {LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, - {LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The breakpoint is deleted the first time it causes a stop." }, - {LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, - {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose indeX matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this " - "argument."}, - {LLDB_OPT_SET_ALL, false, "hardware", 'H', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Require the breakpoint to use hardware breakpoints."}, - {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by " - "this argument."}, - {LLDB_OPT_FILE, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file in which to set this breakpoint. Note, by default " - "lldb only looks for files that are #included if they use the standard include " - "file extensions. To set breakpoints on .c/.cpp/.m/.mm files that are " - "#included, set target.inline-breakpoint-strategy to \"always\"."}, - {LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number on which to set this breakpoint."}, - - // Comment out this option for the moment, as we don't actually use it, but will in the future. - // This way users won't see it, but the infrastructure is left in place. - // { 0, false, "column", 'C', OptionParser::eRequiredArgument, nullptr, "", - // "Set the breakpoint by source location at this particular column."}, - - {LLDB_OPT_SET_2, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Set the breakpoint at the specified address. If the address maps uniquely to " - "a particular binary, then the address will be converted to a \"file\" " - "address, so that the breakpoint will track that binary+offset no matter where " - "the binary eventually loads. Alternately, if you also specify the module - " - "with the -s option - then the address will be treated as a file address in " - "that module, and resolved accordingly. Again, this will allow lldb to track " - "that offset on subsequent reloads. The module need not have been loaded at " - "the time you specify this breakpoint, and will get resolved when the module " - "is loaded."}, - {LLDB_OPT_SET_3, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function name. Can be repeated multiple times to make " - "one breakpoint for multiple names"}, - {LLDB_OPT_SET_9, false, "source-regexp-function", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "When used with '-p' limits the source regex to source contained in the named " - "functions. Can be repeated multiple times."}, - {LLDB_OPT_SET_4, true, "fullname", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFullName, "Set the breakpoint by fully qualified function names. For C++ this means " - "namespaces and all arguments, and for Objective C this means a full function " - "prototype with class and selector. Can be repeated multiple times to make " - "one breakpoint for multiple names."}, - {LLDB_OPT_SET_5, true, "selector", 'S', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSelector, "Set the breakpoint by ObjC selector name. Can be repeated multiple times to " - "make one breakpoint for multiple Selectors."}, - {LLDB_OPT_SET_6, true, "method", 'M', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeMethod, "Set the breakpoint by C++ method names. Can be repeated multiple times to " - "make one breakpoint for multiple methods."}, - {LLDB_OPT_SET_7, true, "func-regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by function name, evaluating a regular-expression to find " - "the function name(s)."}, - {LLDB_OPT_SET_8, true, "basename", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the breakpoint by function basename (C++ namespaces and arguments will be " - "ignored). Can be repeated multiple times to make one breakpoint for multiple " - "symbols."}, - {LLDB_OPT_SET_9, true, "source-pattern-regexp", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Set the breakpoint by specifying a regular expression which is matched " - "against the source text in a source file or files specified with the -f " - "option. The -f option can be specified more than once. If no source files " - "are specified, uses the current \"default source file\". If you want to " - "match against all source files, pass the \"--all-files\" option."}, - {LLDB_OPT_SET_9, false, "all-files", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "All files are searched for source pattern matches."}, - {LLDB_OPT_SET_10, true, "language-exception", 'E', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Set the breakpoint on exceptions thrown by the specified language (without " - "options, on throw but not catch.)"}, - {LLDB_OPT_SET_10, false, "on-throw", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception throW."}, - {LLDB_OPT_SET_10, false, "on-catch", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set the breakpoint on exception catcH."}, - -// Don't add this option till it actually does something useful... -// { LLDB_OPT_SET_10, false, "exception-typename", 'O', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeTypeName, -// "The breakpoint will only stop if an exception Object of this type is thrown. Can be repeated multiple times to stop for multiple object types" }, - - {LLDB_OPT_EXPR_LANGUAGE, false, "language", 'L', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specifies the Language to use when interpreting the breakpoint's expression " - "(note: currently only implemented for setting breakpoints on identifiers). " - "If not set the target.language setting is used."}, - {LLDB_OPT_SKIP_PROLOGUE, false, "skip-prologue", 'K', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "sKip the prologue if the breakpoint is at the beginning of a function. " - "If not set the target.skip-prologue setting is used."}, - {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, " - "which prime new targets."}, - {LLDB_OPT_SET_ALL, false, "breakpoint-name", 'N', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBreakpointName, "Adds this to the list of names for this breakpoint."}, - {LLDB_OPT_OFFSET_APPLIES, false, "address-slide", 'R', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "Add the specified offset to whatever address(es) the breakpoint resolves to. " - "At present this applies the offset directly as given, and doesn't try to align it to instruction boundaries."}, - {LLDB_OPT_MOVE_TO_NEAREST_CODE, false, "move-to-nearest-code", 'm', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Move breakpoints to nearest code. If not set the target.move-to-nearest-code " - "setting is used."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointModify //------------------------------------------------------------------------- + +#pragma mark Modify::CommandOptions +static OptionDefinition g_breakpoint_modify_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping." }, + { LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop." }, + { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument." }, + { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument." }, + { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true." }, + { LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint." }, + { LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint." }, + { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, + // clang-format on +}; + #pragma mark Modify class CommandObjectBreakpointModify : public CommandObjectParsed { @@ -948,11 +961,9 @@ public: m_use_dummy = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_modify_options; + } // Instance variables to hold the values for command options. @@ -1057,24 +1068,6 @@ private: CommandOptions m_options; }; -#pragma mark Modify::CommandOptions -OptionDefinition - CommandObjectBreakpointModify::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this breakpoint is skipped before stopping."}, - {LLDB_OPT_SET_ALL, false, "one-shot", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "The breakpoint is deleted the first time it stop causes a stop."}, - {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The breakpoint stops only for the thread whose index matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The breakpoint stops only for the thread whose TID matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The breakpoint stops only for the thread whose thread name matches this argument."}, - {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The breakpoint stops only for threads in the queue whose name is given by this argument."}, - {LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The breakpoint stops only if this condition expression evaluates to true."}, - {LLDB_OPT_SET_1, false, "enable", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable the breakpoint."}, - {LLDB_OPT_SET_2, false, "disable", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disable the breakpoint."}, - {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointEnable //------------------------------------------------------------------------- @@ -1282,6 +1275,20 @@ protected: //------------------------------------------------------------------------- // CommandObjectBreakpointList //------------------------------------------------------------------------- + +#pragma mark List::CommandOptions +static OptionDefinition g_breakpoint_list_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, + { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)." }, + // FIXME: We need to add an "internal" command, and then add this sort of thing to it. + // But I need to see it for now, and don't want to wait. + { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations." }, + { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, + { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, + // clang-format on +}; + #pragma mark List class CommandObjectBreakpointList : public CommandObjectParsed { @@ -1355,11 +1362,9 @@ public: m_use_dummy = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_list_options; + } // Instance variables to hold the values for command options. @@ -1430,24 +1435,18 @@ private: CommandOptions m_options; }; -#pragma mark List::CommandOptions -OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show debugger internal breakpoints" }, - {LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the breakpoint (no location info)."}, - // FIXME: We need to add an "internal" command, and then add this sort of thing to it. - // But I need to see it for now, and don't want to wait. - {LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the breakpoint and its locations."}, - {LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the breakpoint (for debugging debugger bugs)."}, - {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "List Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointClear //------------------------------------------------------------------------- +#pragma mark Clear::CommandOptions + +static OptionDefinition g_breakpoint_clear_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file." }, + { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line." } + // clang-format on +}; + #pragma mark Clear class CommandObjectBreakpointClear : public CommandObjectParsed { @@ -1502,11 +1501,9 @@ public: m_line_num = 0; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_clear_options; + } // Instance variables to hold the values for command options. @@ -1597,20 +1594,16 @@ private: CommandOptions m_options; }; -#pragma mark Clear::CommandOptions - -OptionDefinition - CommandObjectBreakpointClear::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the breakpoint by source location in this particular file."}, - {LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specify the breakpoint by source location at this particular line."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointDelete //------------------------------------------------------------------------- +static OptionDefinition g_breakpoint_delete_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation." }, + { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, + // clang-format on +}; + #pragma mark Delete class CommandObjectBreakpointDelete : public CommandObjectParsed { @@ -1667,11 +1660,9 @@ public: m_force = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_delete_options; + } // Instance variables to hold the values for command options. bool m_use_dummy; @@ -1758,15 +1749,6 @@ private: CommandOptions m_options; }; -OptionDefinition - CommandObjectBreakpointDelete::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "force", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete all breakpoints without querying for confirmation."}, - {LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointName //------------------------------------------------------------------------- @@ -1786,11 +1768,7 @@ public: ~BreakpointNameOptionGroup() override = default; - uint32_t GetNumDefinitions() override { - return sizeof(g_breakpoint_name_options) / sizeof(OptionDefinition); - } - - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { return g_breakpoint_name_options; } @@ -2099,7 +2077,14 @@ public: //------------------------------------------------------------------------- // CommandObjectBreakpointRead //------------------------------------------------------------------------- -#pragma mark Restore +#pragma mark Modify::CommandOptions +static OptionDefinition g_breakpoint_read_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints." }, + // clang-format on +}; + +#pragma mark Read class CommandObjectBreakpointRead : public CommandObjectParsed { public: @@ -2149,11 +2134,9 @@ public: m_filename.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_read_options; + } // Instance variables to hold the values for command options. @@ -2186,19 +2169,17 @@ private: CommandOptions m_options; }; -#pragma mark Modify::CommandOptions -OptionDefinition CommandObjectBreakpointRead::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file from which to read the breakpoints."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointWrite //------------------------------------------------------------------------- -#pragma mark Save +#pragma mark Write::CommandOptions +static OptionDefinition g_breakpoint_write_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints." }, + // clang-format on +}; + +#pragma mark Write class CommandObjectBreakpointWrite : public CommandObjectParsed { public: CommandObjectBreakpointWrite(CommandInterpreter &interpreter) @@ -2248,11 +2229,9 @@ public: m_filename.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_write_options; + } // Instance variables to hold the values for command options. @@ -2295,15 +2274,6 @@ private: CommandOptions m_options; }; -#pragma mark Modify::CommandOptions -OptionDefinition - CommandObjectBreakpointWrite::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eDiskFileCompletion, eArgTypeFilename, "The file into which to write the breakpoints."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectMultiwordBreakpoint //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index 1850494..90e6b23 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -33,6 +33,29 @@ using namespace lldb_private; // CommandObjectBreakpointCommandAdd //------------------------------------------------------------------------- +// FIXME: "script-type" needs to have its contents determined dynamically, so +// somebody can add a new scripting +// language to lldb and have it pickable here without having to change this +// enumeration by hand and rebuild lldb proper. + +static OptionEnumValueElement g_script_option_enumeration[4] = { + {eScriptLanguageNone, "command", + "Commands are in the lldb command interpreter language"}, + {eScriptLanguagePython, "python", "Commands are in the Python language."}, + {eSortOrderByName, "default-script", + "Commands are in the default scripting language."}, + {0, nullptr, nullptr}}; + +static OptionDefinition g_breakpoint_add_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, + { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether breakpoint command execution should terminate on error." }, + { LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used." }, + { LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate." }, + { LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, + // clang-format on +}; + class CommandObjectBreakpointCommandAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { public: @@ -278,7 +301,7 @@ are no syntax errors may indicate that a function was declared but never called. case 's': m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum( - option_arg, g_option_table[option_idx].enum_values, + option_arg, g_breakpoint_add_options[option_idx].enum_values, eScriptLanguageNone, error); if (m_script_language == eScriptLanguagePython || @@ -325,11 +348,9 @@ are no syntax errors may indicate that a function was declared but never called. m_use_dummy = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_add_options; + } // Instance variables to hold the values for command options. @@ -454,35 +475,16 @@ private: const char *CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.\n"; -// FIXME: "script-type" needs to have its contents determined dynamically, so -// somebody can add a new scripting -// language to lldb and have it pickable here without having to change this -// enumeration by hand and rebuild lldb proper. - -static OptionEnumValueElement g_script_option_enumeration[4] = { - {eScriptLanguageNone, "command", - "Commands are in the lldb command interpreter language"}, - {eScriptLanguagePython, "python", "Commands are in the Python language."}, - {eSortOrderByName, "default-script", - "Commands are in the default scripting language."}, - {0, nullptr, nullptr}}; - -OptionDefinition - CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, - {LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether breakpoint command execution should terminate on error." }, - {LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, - {LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, - {LLDB_OPT_SET_ALL, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Sets Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointCommandDelete //------------------------------------------------------------------------- +static OptionDefinition g_breakpoint_delete_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete commands from Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets." }, + // clang-format on +}; + class CommandObjectBreakpointCommandDelete : public CommandObjectParsed { public: CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter) @@ -538,11 +540,9 @@ public: m_use_dummy = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_breakpoint_delete_options; + } // Instance variables to hold the values for command options. bool m_use_dummy; @@ -611,14 +611,6 @@ private: CommandOptions m_options; }; -OptionDefinition - CommandObjectBreakpointCommandDelete::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "dummy-breakpoints", 'D', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete commands from Dummy breakpoints - i.e. breakpoints set before a file is provided, which prime new targets."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectBreakpointCommandList //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index f4f3afb..74f0362 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -36,6 +36,15 @@ using namespace lldb_private; // CommandObjectCommandsSource //------------------------------------------------------------------------- +static OptionDefinition g_history_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "How many history commands to print." }, + { LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)." }, + { LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands." }, + { LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Clears the current command history." }, + // clang-format on +}; + class CommandObjectCommandsHistory : public CommandObjectParsed { public: CommandObjectCommandsHistory(CommandInterpreter &interpreter) @@ -98,11 +107,9 @@ protected: m_clear.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_history_options; + } // Instance variables to hold the values for command options. @@ -180,21 +187,18 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectCommandsHistory::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "How many history commands to print."}, - {LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)."}, - {LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands."}, - {LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Clears the current command history."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectCommandsSource //------------------------------------------------------------------------- +static OptionDefinition g_source_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on error." }, + { LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on continue." }, + { LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true don't echo commands while executing." }, + // clang-format on +}; + class CommandObjectCommandsSource : public CommandObjectParsed { public: CommandObjectCommandsSource(CommandInterpreter &interpreter) @@ -285,11 +289,9 @@ protected: m_stop_on_continue.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_source_options; + } // Instance variables to hold the values for command options. @@ -340,21 +342,18 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectCommandsSource::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on error."}, - {LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on continue."}, - {LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true don't echo commands while executing."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectCommandsAlias //------------------------------------------------------------------------- // CommandObjectCommandsAlias //------------------------------------------------------------------------- +static OptionDefinition g_alias_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Help text for this command" }, + { LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Long help text for this command" }, + // clang-format on +}; + static const char *g_python_command_instructions = "Enter your Python command(s). Type 'DONE' to end.\n" "You must define a Python function with this signature:\n" @@ -368,15 +367,15 @@ protected: ~CommandOptions() override = default; - uint32_t GetNumDefinitions() override { return 3; } - - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_alias_options; + } Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { case 'h': @@ -403,9 +402,6 @@ protected: m_long_help.Clear(); } - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; OptionValueString m_help; OptionValueString m_long_help; }; @@ -810,15 +806,6 @@ protected: } }; -OptionDefinition CommandObjectCommandsAlias::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Help text for this command"}, - {LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Long help text for this command"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectCommandsUnalias //------------------------------------------------------------------------- // CommandObjectCommandsUnalias @@ -966,6 +953,14 @@ protected: //------------------------------------------------------------------------- // CommandObjectCommandsAddRegex //------------------------------------------------------------------------- + +static OptionDefinition g_regex_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "The help text to display for this command." }, + { LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A syntax string showing the typical usage syntax." }, + // clang-format on +}; + #pragma mark CommandObjectCommandsAddRegex class CommandObjectCommandsAddRegex : public CommandObjectParsed, @@ -1248,11 +1243,9 @@ private: m_syntax.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_regex_options; + } const char *GetHelp() { return (m_help.empty() ? nullptr : m_help.c_str()); @@ -1274,15 +1267,6 @@ private: CommandOptions m_options; }; -OptionDefinition - CommandObjectCommandsAddRegex::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "The help text to display for this command."}, - {LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A syntax string showing the typical usage syntax."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - class CommandObjectPythonFunction : public CommandObjectRaw { public: CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name, @@ -1447,6 +1431,12 @@ private: // CommandObjectCommandsScriptImport //------------------------------------------------------------------------- +OptionDefinition g_script_import_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not." }, + // clang-format on +}; + class CommandObjectCommandsScriptImport : public CommandObjectParsed { public: CommandObjectCommandsScriptImport(CommandInterpreter &interpreter) @@ -1517,11 +1507,9 @@ protected: m_allow_reload = true; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_script_import_options; + } // Instance variables to hold the values for command options. @@ -1578,18 +1566,28 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectCommandsScriptAdd //------------------------------------------------------------------------- +static OptionEnumValueElement g_script_synchro_type[] = { + {eScriptedCommandSynchronicitySynchronous, "synchronous", + "Run synchronous"}, + {eScriptedCommandSynchronicityAsynchronous, "asynchronous", + "Run asynchronous"}, + {eScriptedCommandSynchronicityCurrentValue, "current", + "Do not alter current setting"}, + {0, nullptr, nullptr}}; + +static OptionDefinition g_script_add_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name." }, + { LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name." }, + { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "The help text to display for this command." }, + { LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system." }, + // clang-format on +}; + class CommandObjectCommandsScriptAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { public: @@ -1647,7 +1645,7 @@ protected: case 's': m_synchronicity = (ScriptedCommandSynchronicity)Args::StringToOptionEnum( - option_arg, g_option_table[option_idx].enum_values, 0, error); + option_arg, GetDefinitions()[option_idx].enum_values, 0, error); if (!error.Success()) error.SetErrorStringWithFormat( "unrecognized value for synchronicity '%s'", option_arg); @@ -1668,11 +1666,9 @@ protected: m_synchronicity = eScriptedCommandSynchronicitySynchronous; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_script_add_options; + } // Instance variables to hold the values for command options. @@ -1816,26 +1812,6 @@ protected: ScriptedCommandSynchronicity m_synchronicity; }; -static OptionEnumValueElement g_script_synchro_type[] = { - {eScriptedCommandSynchronicitySynchronous, "synchronous", - "Run synchronous"}, - {eScriptedCommandSynchronicityAsynchronous, "asynchronous", - "Run asynchronous"}, - {eScriptedCommandSynchronicityCurrentValue, "current", - "Do not alter current setting"}, - {0, nullptr, nullptr}}; - -OptionDefinition - CommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name."}, - {LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name."}, - {LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "The help text to display for this command."}, - {LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectCommandsScriptList //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index 8dbcc3e..ff8b782 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -34,6 +34,33 @@ using namespace lldb; using namespace lldb_private; +static OptionDefinition g_disassemble_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "bytes", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show opcode bytes when disassembling." }, + { LLDB_OPT_SET_ALL, false, "context", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNumLines, "Number of context lines of source to show." }, + { LLDB_OPT_SET_ALL, false, "mixed", 'm', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable mixed source and assembly display." }, + { LLDB_OPT_SET_ALL, false, "raw", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print raw disassembly with no symbol information." }, + { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the disassembler plugin you want to use." }, + { LLDB_OPT_SET_ALL, false, "flavor", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeDisassemblyFlavor, "Name of the disassembly flavor you want to use. " + "Currently the only valid options are default, and for Intel " + "architectures, att and intel." }, + { LLDB_OPT_SET_ALL, false, "arch", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeArchitecture, "Specify the architecture to use from cross disassembly." }, + { LLDB_OPT_SET_1 | + LLDB_OPT_SET_2, true, "start-address", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Address at which to start disassembling." }, + { LLDB_OPT_SET_1, false, "end-address", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Address at which to end disassembling." }, + { LLDB_OPT_SET_2 | + LLDB_OPT_SET_3 | + LLDB_OPT_SET_4 | + LLDB_OPT_SET_5, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNumLines, "Number of instructions to display." }, + { LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name." }, + { LLDB_OPT_SET_4, false, "frame", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble from the start of the current frame's function." }, + { LLDB_OPT_SET_5, false, "pc", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble around the current pc." }, + { LLDB_OPT_SET_6, false, "line", 'l', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble the current frame's current source line instructions if there is debug line " + "table information, else disassemble around the pc." }, + { LLDB_OPT_SET_7, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Disassemble function containing this address." }, + // clang-format on +}; + CommandObjectDisassemble::CommandOptions::CommandOptions() : Options(), num_lines_context(0), num_instructions(0), func_name(), current_function(false), start_addr(), end_addr(), at_pc(false), @@ -207,39 +234,11 @@ Error CommandObjectDisassemble::CommandOptions::OptionParsingFinished( return Error(); } -const OptionDefinition * +llvm::ArrayRef CommandObjectDisassemble::CommandOptions::GetDefinitions() { - return g_option_table; + return g_disassemble_options; } -OptionDefinition CommandObjectDisassemble::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "bytes", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show opcode bytes when disassembling."}, - {LLDB_OPT_SET_ALL, false, "context", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNumLines, "Number of context lines of source to show."}, - {LLDB_OPT_SET_ALL, false, "mixed", 'm', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable mixed source and assembly display."}, - {LLDB_OPT_SET_ALL, false, "raw", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print raw disassembly with no symbol information."}, - {LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the disassembler plugin you want to use."}, - {LLDB_OPT_SET_ALL, false, "flavor", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeDisassemblyFlavor, "Name of the disassembly flavor you want to use. " - "Currently the only valid options are default, and for Intel " - "architectures, att and intel."}, - {LLDB_OPT_SET_ALL, false, "arch", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeArchitecture, "Specify the architecture to use from cross disassembly."}, - {LLDB_OPT_SET_1 | - LLDB_OPT_SET_2, true, "start-address", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Address at which to start disassembling."}, - {LLDB_OPT_SET_1, false, "end-address", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Address at which to end disassembling."}, - {LLDB_OPT_SET_2 | - LLDB_OPT_SET_3 | - LLDB_OPT_SET_4 | - LLDB_OPT_SET_5, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNumLines, "Number of instructions to display."}, - {LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name."}, - {LLDB_OPT_SET_4, false, "frame", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble from the start of the current frame's function."}, - {LLDB_OPT_SET_5, false, "pc", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble around the current pc."}, - {LLDB_OPT_SET_6, false, "line", 'l', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Disassemble the current frame's current source line instructions if there is debug line " - "table information, else disassemble around the pc."}, - {LLDB_OPT_SET_7, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Disassemble function containing this address."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectDisassemble //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectDisassemble.h b/lldb/source/Commands/CommandObjectDisassemble.h index a4d132a..c60f70a 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.h +++ b/lldb/source/Commands/CommandObjectDisassemble.h @@ -37,7 +37,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override; - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; const char *GetPluginName() { return (plugin_name.empty() ? nullptr : plugin_name.c_str()); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index cc1fdf4..b2b1ed3 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -49,7 +49,7 @@ static OptionEnumValueElement g_description_verbosity_type[] = { "Show the full output, including persistent variable's name and type"}, {0, nullptr, nullptr}}; -OptionDefinition CommandObjectExpression::CommandOptions::g_option_table[] = { +static OptionDefinition g_expression_options[] = { // clang-format off {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "all-threads", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Should we run all threads if the execution doesn't complete on one thread."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "ignore-breakpoints", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Ignore breakpoint hits while running expressions"}, @@ -69,17 +69,13 @@ OptionDefinition CommandObjectExpression::CommandOptions::g_option_table[] = { // clang-format on }; -uint32_t CommandObjectExpression::CommandOptions::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} - Error CommandObjectExpression::CommandOptions::SetOptionValue( uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) { Error error; auto option_strref = llvm::StringRef::withNullAsEmpty(option_arg); - const int short_option = g_option_table[option_idx].short_option; + const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { case 'l': @@ -151,7 +147,7 @@ Error CommandObjectExpression::CommandOptions::SetOptionValue( } m_verbosity = (LanguageRuntimeDescriptionDisplayVerbosity)Args::StringToOptionEnum( - option_arg, g_option_table[option_idx].enum_values, 0, error); + option_arg, GetDefinitions()[option_idx].enum_values, 0, error); if (!error.Success()) error.SetErrorStringWithFormat( "unrecognized value for description-verbosity '%s'", option_arg); @@ -210,9 +206,9 @@ void CommandObjectExpression::CommandOptions::OptionParsingStarting( allow_jit = true; } -const OptionDefinition * +llvm::ArrayRef CommandObjectExpression::CommandOptions::GetDefinitions() { - return g_option_table; + return g_expression_options; } CommandObjectExpression::CommandObjectExpression( diff --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h index 5b8173f..01593ae 100644 --- a/lldb/source/Commands/CommandObjectExpression.h +++ b/lldb/source/Commands/CommandObjectExpression.h @@ -32,9 +32,7 @@ public: ~CommandOptions() override; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override; + llvm::ArrayRef GetDefinitions() override; Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override; diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 0c28bd0..af954ec 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -61,6 +61,14 @@ using namespace lldb_private; // CommandObjectFrameDiagnose //------------------------------------------------------------------------- +static OptionDefinition g_frame_diag_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "register", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegisterName, "A register to diagnose." }, + { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "An address to diagnose." }, + { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "An optional offset. Requires --register." } + // clang-format on +}; + class CommandObjectFrameDiagnose : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -115,10 +123,9 @@ public: offset.reset(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_frame_diag_options; + } // Options. llvm::Optional address; @@ -215,16 +222,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectFrameDiagnose::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "register", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegisterName, "A register to diagnose."}, - {LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddress, "An address to diagnose."}, - {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "An optional offset. Requires --register."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectFrameInfo //------------------------------------------------------------------------- @@ -257,6 +254,12 @@ protected: // CommandObjectFrameSelect //------------------------------------------------------------------------- +static OptionDefinition g_frame_select_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "A relative frame index offset from the current frame index." }, + // clang-format on +}; + class CommandObjectFrameSelect : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -292,11 +295,10 @@ public: relative_frame_offset = INT32_MIN; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. + llvm::ArrayRef GetDefinitions() override { + return g_frame_select_options; + } - static OptionDefinition g_option_table[]; int32_t relative_frame_offset; }; @@ -420,13 +422,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectFrameSelect::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectFrameVariable //---------------------------------------------------------------------- // List images with associated information diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp index 8e91888..aa611ce 100644 --- a/lldb/source/Commands/CommandObjectHelp.cpp +++ b/lldb/source/Commands/CommandObjectHelp.cpp @@ -66,15 +66,19 @@ CommandObjectHelp::CommandObjectHelp(CommandInterpreter &interpreter) CommandObjectHelp::~CommandObjectHelp() = default; -OptionDefinition CommandObjectHelp::CommandOptions::g_option_table[] = { +static OptionDefinition g_help_options[] = { // clang-format off {LLDB_OPT_SET_ALL, false, "hide-aliases", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Hide aliases in the command list."}, {LLDB_OPT_SET_ALL, false, "hide-user-commands", 'u', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Hide user-defined commands from the list."}, {LLDB_OPT_SET_ALL, false, "show-hidden-commands", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Include commands prefixed with an underscore."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} // clang-format on }; +llvm::ArrayRef +CommandObjectHelp::CommandOptions::GetDefinitions() { + return g_help_options; +} + bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) { CommandObject::CommandMap::iterator pos; CommandObject *cmd_obj; diff --git a/lldb/source/Commands/CommandObjectHelp.h b/lldb/source/Commands/CommandObjectHelp.h index 827eb57..df1c0ab 100644 --- a/lldb/source/Commands/CommandObjectHelp.h +++ b/lldb/source/Commands/CommandObjectHelp.h @@ -75,11 +75,7 @@ public: m_show_hidden = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override; // Instance variables to hold the values for command options. diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 8513444..29b937f 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -36,6 +36,21 @@ using namespace lldb; using namespace lldb_private; +static OptionDefinition g_log_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Set the destination file to log to." }, + { LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines." }, + { LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose logging." }, + { LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable debug logging." }, + { LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id." }, + { LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with a timestamp." }, + { LLDB_OPT_SET_1, false, "pid-tid", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with the process and thread ID that generates the log line." }, + { LLDB_OPT_SET_1, false, "thread-name",'n', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with the thread name for the thread that generates the log line." }, + { LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append a stack backtrace to each log line." }, + { LLDB_OPT_SET_1, false, "append", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to the log file instead of overwriting." }, + // clang-format on +}; + class CommandObjectLogEnable : public CommandObjectParsed { public: //------------------------------------------------------------------ @@ -151,11 +166,9 @@ public: log_options = 0; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_log_options; + } // Instance variables to hold the values for command options. @@ -191,22 +204,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectLogEnable::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Set the destination file to log to."}, - {LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable thread safe logging to avoid interweaved log lines."}, - {LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose logging."}, - {LLDB_OPT_SET_1, false, "debug", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable debug logging."}, - {LLDB_OPT_SET_1, false, "sequence", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with an increasing integer sequence id."}, - {LLDB_OPT_SET_1, false, "timestamp", 'T', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with a timestamp."}, - {LLDB_OPT_SET_1, false, "pid-tid", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with the process and thread ID that generates the log line."}, - {LLDB_OPT_SET_1, false, "thread-name",'n', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Prepend all log lines with the thread name for the thread that generates the log line."}, - {LLDB_OPT_SET_1, false, "stack", 'S', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append a stack backtrace to each log line."}, - {LLDB_OPT_SET_1, false, "append", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Append to the log file instead of overwriting."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - class CommandObjectLogDisable : public CommandObjectParsed { public: //------------------------------------------------------------------ diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 9a2180c..4be666e 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -48,7 +48,7 @@ using namespace lldb; using namespace lldb_private; -static OptionDefinition g_option_table[] = { +static OptionDefinition g_read_memory_options[] = { // clang-format off {LLDB_OPT_SET_1, false, "num-per-line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNumberPerLine, "The number of items per line to display." }, {LLDB_OPT_SET_2, false, "binary", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If true, memory will be saved as binary. If false, the memory is saved save as an ASCII dump that " @@ -69,16 +69,14 @@ public: ~OptionGroupReadMemory() override = default; - uint32_t GetNumDefinitions() override { - return sizeof(g_option_table) / sizeof(OptionDefinition); + llvm::ArrayRef GetDefinitions() override { + return g_read_memory_options; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = g_read_memory_options[option_idx].short_option; switch (short_option) { case 'l': @@ -906,11 +904,7 @@ public: ~OptionGroupFindMemory() override = default; - uint32_t GetNumDefinitions() override { - return sizeof(g_memory_find_option_table) / sizeof(OptionDefinition); - } - - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { return g_memory_find_option_table; } @@ -1206,11 +1200,7 @@ public: ~OptionGroupWriteMemory() override = default; - uint32_t GetNumDefinitions() override { - return sizeof(g_memory_write_option_table) / sizeof(OptionDefinition); - } - - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { return g_memory_write_option_table; } diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 295f4c7..db3e2ab 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -144,11 +144,7 @@ public: m_permissions = 0; } - uint32_t GetNumDefinitions() override { - return llvm::array_lengthof(g_permissions_options); - } - - const lldb_private::OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { return g_permissions_options; } @@ -621,6 +617,14 @@ public: //---------------------------------------------------------------------- // "platform fread" //---------------------------------------------------------------------- + +static OptionDefinition g_platform_fread_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading." }, + { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Number of bytes to read from the file." }, + // clang-format on +}; + class CommandObjectPlatformFRead : public CommandObjectParsed { public: CommandObjectPlatformFRead(CommandInterpreter &interpreter) @@ -693,11 +697,9 @@ protected: m_count = 1; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_platform_fread_options; + } // Instance variables to hold the values for command options. @@ -708,18 +710,17 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectPlatformFRead::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading."}, - {LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Number of bytes to read from the file."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //---------------------------------------------------------------------- // "platform fwrite" //---------------------------------------------------------------------- + +static OptionDefinition g_platform_fwrite_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading." }, + { LLDB_OPT_SET_1, false, "data", 'd', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Text to write to the file." }, + // clang-format on +}; + class CommandObjectPlatformFWrite : public CommandObjectParsed { public: CommandObjectPlatformFWrite(CommandInterpreter &interpreter) @@ -789,11 +790,9 @@ protected: m_data.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_platform_fwrite_options; + } // Instance variables to hold the values for command options. @@ -804,15 +803,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectPlatformFWrite::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading."}, - {LLDB_OPT_SET_1, false, "data", 'd', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Text to write to the file."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - class CommandObjectPlatformFile : public CommandObjectMultiword { public: //------------------------------------------------------------------ @@ -1117,6 +1107,28 @@ protected: //---------------------------------------------------------------------- // "platform process list" //---------------------------------------------------------------------- + +OptionDefinition g_platform_process_list_option_array[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "List the process info for a specific process ID." }, + { LLDB_OPT_SET_2, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that match a string." }, + { LLDB_OPT_SET_3, true, "ends-with", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that end with a string." }, + { LLDB_OPT_SET_4, true, "starts-with", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that start with a string." }, + { LLDB_OPT_SET_5, true, "contains", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that contain a string." }, + { LLDB_OPT_SET_6, true, "regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Find processes with executable basenames that match a regular expression." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "parent", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "Find processes that have a matching parent process ID." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "uid", 'u', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching user ID." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "euid", 'U', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective user ID." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "gid", 'g', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching group ID." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "egid", 'G', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective group ID." }, + { LLDB_OPT_SET_FROM_TO(2, 6), false, "arch", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeArchitecture, "Find processes that have a matching architecture." }, + { LLDB_OPT_SET_FROM_TO(1, 6), false, "show-args", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show process arguments instead of the process executable basename." }, + { LLDB_OPT_SET_FROM_TO(1, 6), false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose output." }, + // clang-format on +}; +llvm::MutableArrayRef + g_platform_process_list_options(g_platform_process_list_option_array); + class CommandObjectPlatformProcessList : public CommandObjectParsed { public: CommandObjectPlatformProcessList(CommandInterpreter &interpreter) @@ -1244,13 +1256,13 @@ protected: std::call_once(g_once_flag, []() { PosixPlatformCommandOptionValidator *posix_validator = new PosixPlatformCommandOptionValidator(); - for (size_t i = 0; g_option_table[i].short_option != 0; ++i) { - switch (g_option_table[i].short_option) { + for (auto &Option : g_platform_process_list_options) { + switch (Option.short_option) { case 'u': case 'U': case 'g': case 'G': - g_option_table[i].validator = posix_validator; + Option.validator = posix_validator; break; default: break; @@ -1382,11 +1394,9 @@ protected: verbose = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_platform_process_list_options; + } // Instance variables to hold the values for command options. @@ -1398,27 +1408,6 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectPlatformProcessList::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "List the process info for a specific process ID."}, - {LLDB_OPT_SET_2, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that match a string."}, - {LLDB_OPT_SET_3, true, "ends-with", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that end with a string."}, - {LLDB_OPT_SET_4, true, "starts-with", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that start with a string."}, - {LLDB_OPT_SET_5, true, "contains", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that contain a string."}, - {LLDB_OPT_SET_6, true, "regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Find processes with executable basenames that match a regular expression."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "parent", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "Find processes that have a matching parent process ID."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "uid", 'u', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching user ID."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "euid", 'U', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective user ID."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "gid", 'g', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching group ID."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "egid", 'G', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective group ID."}, - {LLDB_OPT_SET_FROM_TO(2, 6), false, "arch", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeArchitecture, "Find processes that have a matching architecture."}, - {LLDB_OPT_SET_FROM_TO(1, 6), false, "show-args", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show process arguments instead of the process executable basename."}, - {LLDB_OPT_SET_FROM_TO(1, 6), false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose output."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //---------------------------------------------------------------------- // "platform process info" //---------------------------------------------------------------------- @@ -1509,6 +1498,15 @@ protected: } }; +static OptionDefinition g_platform_process_attach_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use." }, + { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "The process ID of an existing process to attach to." }, + { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "The name of the process to attach to." }, + { LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Wait for the process with to launch." }, + // clang-format on +}; + class CommandObjectPlatformProcessAttach : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -1561,7 +1559,9 @@ public: attach_info.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_platform_process_attach_options; + } bool HandleOptionArgumentCompletion( Args &input, int cursor_index, int char_pos, @@ -1574,8 +1574,7 @@ public: // We are only completing the name option for now... - const OptionDefinition *opt_defs = GetDefinitions(); - if (opt_defs[opt_defs_index].short_option == 'n') { + if (GetDefinitions()[opt_defs_index].short_option == 'n') { // Are we in the name? // Look to see if there is a -P argument provided, and if so use that @@ -1654,17 +1653,6 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectPlatformProcessAttach::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, - {LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "The process ID of an existing process to attach to."}, - {LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "The name of the process to attach to."}, - {LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Wait for the process with to launch."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - class CommandObjectPlatformProcess : public CommandObjectMultiword { public: //------------------------------------------------------------------ @@ -1699,6 +1687,12 @@ private: //---------------------------------------------------------------------- // "platform shell" //---------------------------------------------------------------------- +static OptionDefinition g_platform_shell_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "timeout", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command." }, + // clang-format on +}; + class CommandObjectPlatformShell : public CommandObjectRaw { public: class CommandOptions : public Options { @@ -1707,15 +1701,15 @@ public: ~CommandOptions() override = default; - virtual uint32_t GetNumDefinitions() { return 1; } - - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_platform_shell_options; + } Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override { Error error; - const char short_option = (char)g_option_table[option_idx].short_option; + const char short_option = (char)GetDefinitions()[option_idx].short_option; switch (short_option) { case 't': { @@ -1737,9 +1731,6 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override {} - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; uint32_t timeout; }; @@ -1841,14 +1832,6 @@ public: CommandOptions m_options; }; -OptionDefinition CommandObjectPlatformShell::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "timeout", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //---------------------------------------------------------------------- // "platform install" - install a target to a remote end //---------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 26e7602..582e898 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -312,6 +312,18 @@ protected: //------------------------------------------------------------------------- // CommandObjectProcessAttach //------------------------------------------------------------------------- + +static OptionDefinition g_process_attach_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "continue", 'c', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Immediately continue the process once attached." }, + { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use." }, + { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "The process ID of an existing process to attach to." }, + { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "The name of the process to attach to." }, + { LLDB_OPT_SET_2, false, "include-existing", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Include existing processes when doing attach -w." }, + { LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Wait for the process with to launch." }, + // clang-format on +}; + #pragma mark CommandObjectProcessAttach class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach { public: @@ -373,7 +385,9 @@ public: attach_info.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_process_attach_options; + } bool HandleOptionArgumentCompletion( Args &input, int cursor_index, int char_pos, @@ -386,8 +400,7 @@ public: // We are only completing the name option for now... - const OptionDefinition *opt_defs = GetDefinitions(); - if (opt_defs[opt_defs_index].short_option == 'n') { + if (GetDefinitions()[opt_defs_index].short_option == 'n') { // Are we in the name? // Look to see if there is a -P argument provided, and if so use that @@ -421,10 +434,6 @@ public: return false; } - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. ProcessAttachInfo attach_info; @@ -559,22 +568,16 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectProcessAttach::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "continue", 'c', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Immediately continue the process once attached."}, - {LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, - {LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "The process ID of an existing process to attach to."}, - {LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "The name of the process to attach to."}, - {LLDB_OPT_SET_2, false, "include-existing", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Include existing processes when doing attach -w."}, - {LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Wait for the process with to launch."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectProcessContinue //------------------------------------------------------------------------- + +static OptionDefinition g_process_continue_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "ignore-count",'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Ignore crossings of the breakpoint (if it exists) for the currently selected thread." } + // clang-format on +}; + #pragma mark CommandObjectProcessContinue class CommandObjectProcessContinue : public CommandObjectParsed { @@ -627,11 +630,9 @@ protected: m_ignore = 0; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_process_continue_options; + } uint32_t m_ignore; }; @@ -735,17 +736,15 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectProcessContinue::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "ignore-count",'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Ignore crossings of the breakpoint (if it exists) for the currently selected thread."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectProcessDetach //------------------------------------------------------------------------- +static OptionDefinition g_process_detach_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "keep-stopped", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the process should be kept stopped on detach (if possible)." }, + // clang-format on +}; + #pragma mark CommandObjectProcessDetach class CommandObjectProcessDetach : public CommandObjectParsed { @@ -789,11 +788,9 @@ public: m_keep_stopped = eLazyBoolCalculate; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_process_detach_options; + } // Instance variables to hold the values for command options. LazyBool m_keep_stopped; @@ -838,17 +835,16 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectProcessDetach::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "keep-stopped", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the process should be kept stopped on detach (if possible)."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectProcessConnect //------------------------------------------------------------------------- + +static OptionDefinition g_process_connect_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use." }, + // clang-format on +}; + #pragma mark CommandObjectProcessConnect class CommandObjectProcessConnect : public CommandObjectParsed { @@ -885,11 +881,9 @@ public: plugin_name.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_process_connect_options; + } // Instance variables to hold the values for command options. @@ -947,14 +941,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectProcessConnect::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectProcessPlugin //------------------------------------------------------------------------- @@ -981,6 +967,13 @@ public: //------------------------------------------------------------------------- // CommandObjectProcessLoad //------------------------------------------------------------------------- + +static OptionDefinition g_process_load_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "install", 'i', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypePath, "Install the shared library to the target. If specified without an argument then the library will installed in the current working directory." }, + // clang-format on +}; + #pragma mark CommandObjectProcessLoad class CommandObjectProcessLoad : public CommandObjectParsed { @@ -1018,10 +1011,9 @@ public: install_path.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_process_load_options; + } // Instance variables to hold the values for command options. bool do_install; @@ -1085,13 +1077,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectProcessLoad::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "install", 'i', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypePath, "Install the shared library to the target. If specified without an argument then the library will installed in the current working directory."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectProcessUnload //------------------------------------------------------------------------- @@ -1380,6 +1365,15 @@ public: //------------------------------------------------------------------------- // CommandObjectProcessHandle //------------------------------------------------------------------------- + +static OptionDefinition g_process_handle_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "stop", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the process should be stopped if the signal is received." }, + { LLDB_OPT_SET_1, false, "notify", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the debugger should notify the user if the signal is received." }, + { LLDB_OPT_SET_1, false, "pass", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process." } + // clang-format on +}; + #pragma mark CommandObjectProcessHandle class CommandObjectProcessHandle : public CommandObjectParsed { @@ -1419,11 +1413,9 @@ public: pass.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_process_handle_options; + } // Instance variables to hold the values for command options. @@ -1631,16 +1623,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectProcessHandle::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "stop", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the process should be stopped if the signal is received."}, - {LLDB_OPT_SET_1, false, "notify", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the debugger should notify the user if the signal is received."}, - {LLDB_OPT_SET_1, false, "pass", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectMultiwordProcess //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 47a079d..8ee6c65 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -38,6 +38,15 @@ using namespace lldb_private; //---------------------------------------------------------------------- // "register read" //---------------------------------------------------------------------- + +static OptionDefinition g_register_read_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "alternate", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display register names using the alternate register name if there is one." }, + { LLDB_OPT_SET_1, false, "set", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Specify which register sets to dump by index." }, + { LLDB_OPT_SET_2, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show all register sets." }, + // clang-format on +}; + class CommandObjectRegisterRead : public CommandObjectParsed { public: CommandObjectRegisterRead(CommandInterpreter &interpreter) @@ -241,9 +250,9 @@ protected: ~CommandOptions() override = default; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_register_read_options; + } void OptionParsingStarting(ExecutionContext *execution_context) override { set_indexes.Clear(); @@ -254,7 +263,7 @@ protected: Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { case 's': { OptionValueSP value_sp(OptionValueUInt64::Create(option_value, error)); @@ -286,10 +295,6 @@ protected: return error; } - // Options table: Required for subclasses of Options. - - static const OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. OptionValueArray set_indexes; OptionValueBoolean dump_all_sets; @@ -301,19 +306,6 @@ protected: CommandOptions m_command_options; }; -const OptionDefinition - CommandObjectRegisterRead::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "alternate", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display register names using the alternate register name if there is one."}, - {LLDB_OPT_SET_1, false, "set", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Specify which register sets to dump by index."}, - {LLDB_OPT_SET_2, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show all register sets."}, - // clang-format on -}; - -uint32_t CommandObjectRegisterRead::CommandOptions::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} - //---------------------------------------------------------------------- // "register write" //---------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 4d545d7..f1420a2 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -27,6 +27,12 @@ using namespace lldb_private; // CommandObjectSettingsSet //------------------------------------------------------------------------- +static 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." } + // clang-format on +}; + class CommandObjectSettingsSet : public CommandObjectRaw { public: CommandObjectSettingsSet(CommandInterpreter &interpreter) @@ -118,11 +124,9 @@ insert-before or insert-after."); m_global = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_settings_set_options; + } // Instance variables to hold the values for command options. @@ -242,13 +246,6 @@ private: CommandOptions m_options; }; -OptionDefinition CommandObjectSettingsSet::CommandOptions::g_option_table[] = { - // 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."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectSettingsShow -- Show current values //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index 237b340..c03c724 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -40,6 +40,18 @@ using namespace lldb_private; // CommandObjectSourceInfo - debug line entries dumping command //---------------------------------------------------------------------- +static OptionDefinition g_source_info_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of line entries to display." }, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source in the given module or shared library (can be specified more than once)." }, + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source." }, + { LLDB_OPT_SET_1, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to start the displaying lines." }, + { LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to stop displaying lines." }, + { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display." }, + { LLDB_OPT_SET_3, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup the address and display the source information for the corresponding file and line." }, + // clang-format on +}; + class CommandObjectSourceInfo : public CommandObjectParsed { class CommandOptions : public Options { public: @@ -50,7 +62,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed { Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { case 'l': start_line = StringConvert::ToUInt32(option_arg, 0); @@ -108,9 +120,9 @@ class CommandObjectSourceInfo : public CommandObjectParsed { modules.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_source_info_options; + } // Instance variables to hold the values for command options. FileSpec file_spec; @@ -649,24 +661,24 @@ protected: ModuleList m_module_list; }; -OptionDefinition CommandObjectSourceInfo::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of line entries to display."}, - {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source in the given module or shared library (can be specified more than once)."}, - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source."}, - {LLDB_OPT_SET_1, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to start the displaying lines."}, - {LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to stop displaying lines."}, - {LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display."}, - {LLDB_OPT_SET_3, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup the address and display the source information for the corresponding file and line."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectSourceList //------------------------------------------------------------------------- // CommandObjectSourceList //------------------------------------------------------------------------- +static OptionDefinition g_source_list_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of source lines to display." }, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source file in the given shared library." }, + { LLDB_OPT_SET_ALL, false, "show-breakpoints", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show the line table locations from the debug information that indicate valid places to set source level breakpoints." }, + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source." }, + { LLDB_OPT_SET_1, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to start the display source." }, + { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display." }, + { LLDB_OPT_SET_3, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup the address and display the source information for the corresponding file and line." }, + { LLDB_OPT_SET_4, false, "reverse", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Reverse the listing to look backwards from the last displayed block of source." }, + // clang-format on +}; + class CommandObjectSourceList : public CommandObjectParsed { class CommandOptions : public Options { public: @@ -677,7 +689,7 @@ class CommandObjectSourceList : public CommandObjectParsed { Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = GetDefinitions()[option_idx].short_option; switch (short_option) { case 'l': start_line = StringConvert::ToUInt32(option_arg, 0); @@ -736,9 +748,9 @@ class CommandObjectSourceList : public CommandObjectParsed { modules.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_source_list_options; + } // Instance variables to hold the values for command options. FileSpec file_spec; @@ -1306,20 +1318,6 @@ protected: std::string m_reverse_name; }; -OptionDefinition CommandObjectSourceList::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "The number of source lines to display."}, - {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source file in the given shared library."}, - {LLDB_OPT_SET_ALL, false, "show-breakpoints", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show the line table locations from the debug information that indicate valid places to set source level breakpoints."}, - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source."}, - {LLDB_OPT_SET_1, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "The line number at which to start the display source."}, - {LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display."}, - {LLDB_OPT_SET_3, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup the address and display the source information for the corresponding file and line."}, - {LLDB_OPT_SET_4, false, "reverse", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Reverse the listing to look backwards from the last displayed block of source."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectMultiwordSource //------------------------------------------------------------------------- // CommandObjectMultiwordSource diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 321341c..407aeac 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1940,6 +1940,19 @@ protected: #pragma mark CommandObjectTargetModulesDumpSymtab +static OptionEnumValueElement g_sort_option_enumeration[4] = { + {eSortOrderNone, "none", + "No sorting, use the original symbol table order."}, + {eSortOrderByAddress, "address", "Sort output by symbol address."}, + {eSortOrderByName, "name", "Sort output by symbol name."}, + {0, nullptr, nullptr}}; + +static OptionDefinition g_target_modules_dump_symtab_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "sort", 's', OptionParser::eRequiredArgument, nullptr, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table." } + // clang-format on +}; + class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete { public: @@ -1967,8 +1980,8 @@ public: switch (short_option) { case 's': m_sort_order = (SortOrder)Args::StringToOptionEnum( - option_arg, g_option_table[option_idx].enum_values, eSortOrderNone, - error); + option_arg, GetDefinitions()[option_idx].enum_values, + eSortOrderNone, error); break; default: @@ -1983,10 +1996,9 @@ public: m_sort_order = eSortOrderNone; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_target_modules_dump_symtab_options; + } SortOrder m_sort_order; }; @@ -2072,21 +2084,6 @@ protected: CommandOptions m_options; }; -static OptionEnumValueElement g_sort_option_enumeration[4] = { - {eSortOrderNone, "none", - "No sorting, use the original symbol table order."}, - {eSortOrderByAddress, "address", "Sort output by symbol address."}, - {eSortOrderByName, "name", "Sort output by symbol name."}, - {0, nullptr, nullptr}}; - -OptionDefinition - CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "sort", 's', OptionParser::eRequiredArgument, nullptr, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectTargetModulesDumpSections //---------------------------------------------------------------------- @@ -2774,6 +2771,27 @@ protected: //---------------------------------------------------------------------- // List images with associated information //---------------------------------------------------------------------- + +static OptionDefinition g_target_modules_list_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Display the image at this address." }, + { LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the architecture when listing images." }, + { LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the triple when listing images." }, + { LLDB_OPT_SET_1, false, "header", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise." }, + { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)." }, + { LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the UUID when listing images." }, + { LLDB_OPT_SET_1, false, "fullpath", 'f', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image object file." }, + { LLDB_OPT_SET_1, false, "directory", 'd', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the directory with optional width for the image object file." }, + { LLDB_OPT_SET_1, false, "basename", 'b', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the basename with optional width for the image object file." }, + { LLDB_OPT_SET_1, false, "symfile", 's', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width." }, + { LLDB_OPT_SET_1, false, "symfile-unique", 'S', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file." }, + { LLDB_OPT_SET_1, false, "mod-time", 'm', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the modification time with optional width of the module." }, + { LLDB_OPT_SET_1, false, "ref-count", 'r', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache." }, + { LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the module pointer." }, + { LLDB_OPT_SET_1, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target." } + // clang-format on +}; + class CommandObjectTargetModulesList : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -2809,11 +2827,9 @@ public: m_module_addr = LLDB_INVALID_ADDRESS; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_target_modules_list_options; + } // Instance variables to hold the values for command options. typedef std::vector> FormatWidthCollection; @@ -3116,34 +3132,19 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectTargetModulesList::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Display the image at this address."}, - {LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the architecture when listing images."}, - {LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the triple when listing images."}, - {LLDB_OPT_SET_1, false, "header", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."}, - {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."}, - {LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the UUID when listing images."}, - {LLDB_OPT_SET_1, false, "fullpath", 'f', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image object file."}, - {LLDB_OPT_SET_1, false, "directory", 'd', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."}, - {LLDB_OPT_SET_1, false, "basename", 'b', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."}, - {LLDB_OPT_SET_1, false, "symfile", 's', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."}, - {LLDB_OPT_SET_1, false, "symfile-unique", 'S', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."}, - {LLDB_OPT_SET_1, false, "mod-time", 'm', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the modification time with optional width of the module."}, - {LLDB_OPT_SET_1, false, "ref-count", 'r', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."}, - {LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the module pointer."}, - {LLDB_OPT_SET_1, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectTargetModulesShowUnwind //---------------------------------------------------------------------- // Lookup unwind information in images //---------------------------------------------------------------------- +static OptionDefinition g_target_modules_show_unwind_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name." }, + { LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address" } + // clang-format on +}; + class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed { public: enum { @@ -3200,11 +3201,9 @@ public: m_addr = LLDB_INVALID_ADDRESS; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_target_modules_show_unwind_options; + } // Instance variables to hold the values for command options. @@ -3424,18 +3423,28 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."}, - {LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //---------------------------------------------------------------------- // Lookup information in images //---------------------------------------------------------------------- + +static OptionDefinition g_target_modules_lookup_options[] = { + // clang-format off + { LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules." }, + { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "When looking up an address subtract from any addresses before doing the lookup." }, + /* FIXME: re-enable regex for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ + { LLDB_OPT_SET_2 | LLDB_OPT_SET_4 | LLDB_OPT_SET_5, false, "regex", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The argument for name lookups are regular expressions." }, + { LLDB_OPT_SET_2, true, "symbol", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more target modules." }, + { LLDB_OPT_SET_3, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more target modules." }, + { LLDB_OPT_SET_3, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)." }, + { LLDB_OPT_SET_FROM_TO(3,5), false, "no-inlines", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)." }, + { LLDB_OPT_SET_4, true, "function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules." }, + { LLDB_OPT_SET_5, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules." }, + { LLDB_OPT_SET_6, true, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules." }, + { LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose lookup information." }, + { LLDB_OPT_SET_ALL, false, "all", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available." }, + // clang-format on +}; + class CommandObjectTargetModulesLookup : public CommandObjectParsed { public: enum { @@ -3543,11 +3552,10 @@ public: m_print_all = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. + llvm::ArrayRef GetDefinitions() override { + return g_target_modules_lookup_options; + } - static OptionDefinition g_option_table[]; int m_type; // Should be a eLookupTypeXXX enum after parsing options std::string m_str; // Holds name lookup FileSpec m_file; // Files for file lookups @@ -3802,27 +3810,6 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."}, - {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "When looking up an address subtract from any addresses before doing the lookup."}, - /* FIXME: re-enable regex for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ - {LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5, false, "regex", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The argument for name lookups are regular expressions."}, - {LLDB_OPT_SET_2, true, "symbol", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more target modules."}, - {LLDB_OPT_SET_3, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more target modules."}, - {LLDB_OPT_SET_3, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)."}, - {LLDB_OPT_SET_FROM_TO(3,5), false, "no-inlines", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."}, - {LLDB_OPT_SET_4, true, "function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."}, - {LLDB_OPT_SET_5, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."}, - {LLDB_OPT_SET_6, true, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."}, - {LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose lookup information."}, - {LLDB_OPT_SET_ALL, false, "all", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - #pragma mark CommandObjectMultiwordImageSearchPaths //------------------------------------------------------------------------- @@ -4326,6 +4313,22 @@ private: // CommandObjectTargetStopHookAdd //------------------------------------------------------------------------- +static OptionDefinition g_target_stop_hook_add_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, + { LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the module within which the stop-hook is to be run." }, + { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The stop hook is run only for the thread whose index matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The stop hook is run only for the thread whose TID matches this argument." }, + { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The stop hook is run only for the thread whose thread name matches this argument." }, + { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The stop hook is run only for threads in the queue whose name is given by this argument." }, + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the source file within which the stop-hook is to be run." }, + { LLDB_OPT_SET_1, false, "start-line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the start of the line range for which the stop-hook is to be run." }, + { LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the end of the line range for which the stop-hook is to be run." }, + { LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeClassName, "Specify the class within which the stop-hook is to be run." }, + { LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the function name within which the stop hook will be run." }, + // clang-format on +}; + class CommandObjectTargetStopHookAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { public: @@ -4339,7 +4342,9 @@ public: ~CommandOptions() override = default; - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_target_stop_hook_add_options; + } Error SetOptionValue(uint32_t option_idx, const char *option_arg, ExecutionContext *execution_context) override { @@ -4453,8 +4458,6 @@ public: m_one_liner.clear(); } - static OptionDefinition g_option_table[]; - std::string m_class_name; std::string m_function_name; uint32_t m_line_start; @@ -4625,24 +4628,6 @@ private: Target::StopHookSP m_stop_hook_sp; }; -OptionDefinition - CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes."}, - {LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the module within which the stop-hook is to be run."}, - {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The stop hook is run only for the thread whose index matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The stop hook is run only for the thread whose TID matches this argument."}, - {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The stop hook is run only for the thread whose thread name matches this argument."}, - {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The stop hook is run only for threads in the queue whose name is given by this argument."}, - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the source file within which the stop-hook is to be run."}, - {LLDB_OPT_SET_1, false, "start-line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the start of the line range for which the stop-hook is to be run."}, - {LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the end of the line range for which the stop-hook is to be run."}, - {LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeClassName, "Specify the class within which the stop-hook is to be run."}, - {LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the function name within which the stop hook will be run."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - #pragma mark CommandObjectTargetStopHookDelete //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 6cefa6e..fdcd4b1 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -141,6 +141,14 @@ protected: // CommandObjectThreadBacktrace //------------------------------------------------------------------------- +static OptionDefinition g_thread_backtrace_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "How many frames to display (-1 for all)" }, + { LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace" }, + { LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the extended backtrace, if available" } + // clang-format on +}; + class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads { public: class CommandOptions : public Options { @@ -201,11 +209,9 @@ public: m_extended_backtrace = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_thread_backtrace_options; + } // Instance variables to hold the values for command options. uint32_t m_count; @@ -288,18 +294,33 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectThreadBacktrace::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "How many frames to display (-1 for all)"}, - {LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"}, - {LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the extended backtrace, if available"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - enum StepScope { eStepScopeSource, eStepScopeInstruction }; +static OptionEnumValueElement g_tri_running_mode[] = { + {eOnlyThisThread, "this-thread", "Run only this thread"}, + {eAllThreads, "all-threads", "Run all threads"}, + {eOnlyDuringStepping, "while-stepping", + "Run only this thread while stepping"}, + {0, nullptr, nullptr}}; + +static OptionEnumValueElement g_duo_running_mode[] = { + {eOnlyThisThread, "this-thread", "Run only this thread"}, + {eAllThreads, "all-threads", "Run all threads"}, + {0, nullptr, nullptr}}; + +static OptionDefinition g_thread_step_scope_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information." }, + { LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information." }, + { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 1, eArgTypeCount, "How many times to perform the stepping operation - currently only supported for step-inst and next-inst." }, + { LLDB_OPT_SET_1, false, "end-linenumber", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 1, eArgTypeLineNum, "The line at which to stop stepping - defaults to the next line and only supported for step-in and step-over. You can also pass the string 'block' to step to the end of the current block. This is particularly useful in conjunction with --step-target to step through a complex calling sequence." }, + { LLDB_OPT_SET_1, false, "run-mode", 'm', OptionParser::eRequiredArgument, nullptr, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread." }, + { LLDB_OPT_SET_1, false, "step-over-regexp", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in." }, + { LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into." }, + { LLDB_OPT_SET_2, false, "python-class", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "The name of the class that will manage this step - only supported for Scripted Step." } + // clang-format on +}; + class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -358,7 +379,7 @@ public: case 'm': { OptionEnumValueElement *enum_values = - g_option_table[option_idx].enum_values; + GetDefinitions()[option_idx].enum_values; m_run_mode = (lldb::RunMode)Args::StringToOptionEnum( option_arg, enum_values, eOnlyDuringStepping, error); } break; @@ -415,11 +436,9 @@ public: m_end_line_is_block_end = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_thread_step_scope_options; + } // Instance variables to hold the values for command options. LazyBool m_step_in_avoid_no_debug; @@ -690,33 +709,6 @@ protected: CommandOptions m_options; }; -static OptionEnumValueElement g_tri_running_mode[] = { - {eOnlyThisThread, "this-thread", "Run only this thread"}, - {eAllThreads, "all-threads", "Run all threads"}, - {eOnlyDuringStepping, "while-stepping", - "Run only this thread while stepping"}, - {0, nullptr, nullptr}}; - -static OptionEnumValueElement g_duo_running_mode[] = { - {eOnlyThisThread, "this-thread", "Run only this thread"}, - {eAllThreads, "all-threads", "Run all threads"}, - {0, nullptr, nullptr}}; - -OptionDefinition CommandObjectThreadStepWithTypeAndScope::CommandOptions:: - g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information."}, - {LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information."}, - {LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 1, eArgTypeCount, "How many times to perform the stepping operation - currently only supported for step-inst and next-inst."}, - {LLDB_OPT_SET_1, false, "end-linenumber", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 1, eArgTypeLineNum, "The line at which to stop stepping - defaults to the next line and only supported for step-in and step-over. You can also pass the string 'block' to step to the end of the current block. This is particularly useful in conjunction with --step-target to step through a complex calling sequence."}, - {LLDB_OPT_SET_1, false, "run-mode", 'm', OptionParser::eRequiredArgument, nullptr, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."}, - {LLDB_OPT_SET_1, false, "step-over-regexp", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in."}, - {LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into."}, - {LLDB_OPT_SET_2, false, "python-class", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "The name of the class that will manage this step - only supported for Scripted Step."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectThreadContinue //------------------------------------------------------------------------- @@ -907,6 +899,15 @@ public: // CommandObjectThreadUntil //------------------------------------------------------------------------- +static OptionDefinition g_thread_until_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0" }, + { LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation" }, + { LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, nullptr, g_duo_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping this one" }, + { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Run until we reach the specified address, or leave the function - can be specified multiple times." } + // clang-format on +}; + class CommandObjectThreadUntil : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -954,7 +955,7 @@ public: break; case 'm': { OptionEnumValueElement *enum_values = - g_option_table[option_idx].enum_values; + GetDefinitions()[option_idx].enum_values; lldb::RunMode run_mode = (lldb::RunMode)Args::StringToOptionEnum( option_arg, enum_values, eOnlyDuringStepping, error); @@ -980,16 +981,14 @@ public: m_until_addrs.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_thread_until_options; + } uint32_t m_step_thread_idx; bool m_stop_others; std::vector m_until_addrs; - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. }; @@ -1224,16 +1223,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectThreadUntil::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"}, - {LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"}, - {LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, nullptr, g_duo_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping this one"}, - {LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Run until we reach the specified address, or leave the function - can be specified multiple times."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectThreadSelect //------------------------------------------------------------------------- @@ -1333,6 +1322,13 @@ protected: // CommandObjectThreadInfo //------------------------------------------------------------------------- +static OptionDefinition g_thread_info_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "json", 'j', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the thread info in JSON format." }, + { LLDB_OPT_SET_ALL, false, "stop-info", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the extended stop info in JSON format." } + // clang-format on +}; + class CommandObjectThreadInfo : public CommandObjectIterateOverThreads { public: class CommandOptions : public Options { @@ -1366,12 +1362,12 @@ public: return error; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_thread_info_options; + } bool m_json_thread; bool m_json_stopinfo; - - static OptionDefinition g_option_table[]; }; CommandObjectThreadInfo(CommandInterpreter &interpreter) @@ -1417,18 +1413,16 @@ public: CommandOptions m_options; }; -OptionDefinition CommandObjectThreadInfo::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "json", 'j', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the thread info in JSON format."}, - {LLDB_OPT_SET_ALL, false, "stop-info", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the extended stop info in JSON format."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectThreadReturn //------------------------------------------------------------------------- +static OptionDefinition g_thread_return_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Return from the innermost expression evaluation." } + // clang-format on +}; + class CommandObjectThreadReturn : public CommandObjectRaw { public: class CommandOptions : public Options { @@ -1470,14 +1464,12 @@ public: m_from_expression = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_thread_return_options; + } bool m_from_expression; - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. }; @@ -1597,17 +1589,20 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectThreadReturn::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Return from the innermost expression evaluation."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectThreadJump //------------------------------------------------------------------------- +static OptionDefinition g_thread_jump_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file to jump to." }, + { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number to jump to." }, + { LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "Jumps by a relative line offset from the current line." }, + { LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Jumps to a specific address." }, + { LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "force", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allows the PC to leave the current function." } + // clang-format on +}; + class CommandObjectThreadJump : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -1659,15 +1654,15 @@ public: return error; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_thread_jump_options; + } FileSpecList m_filenames; uint32_t m_line_num; int32_t m_line_offset; lldb::addr_t m_load_addr; bool m_force; - - static OptionDefinition g_option_table[]; }; CommandObjectThreadJump(CommandInterpreter &interpreter) @@ -1745,17 +1740,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectThreadJump::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file to jump to."}, - {LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number to jump to."}, - {LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "Jumps by a relative line offset from the current line."}, - {LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Jumps to a specific address."}, - {LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "force", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allows the PC to leave the current function."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // Next are the subcommands of CommandObjectMultiwordThreadPlan //------------------------------------------------------------------------- @@ -1764,6 +1748,13 @@ OptionDefinition CommandObjectThreadJump::CommandOptions::g_option_table[] = { // CommandObjectThreadPlanList //------------------------------------------------------------------------- +static OptionDefinition g_thread_plan_list_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display more information about the thread plans" }, + { LLDB_OPT_SET_1, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display internal as well as user thread plans" } + // clang-format on +}; + class CommandObjectThreadPlanList : public CommandObjectIterateOverThreads { public: class CommandOptions : public Options { @@ -1801,11 +1792,9 @@ public: m_internal = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_thread_plan_list_options; + } // Instance variables to hold the values for command options. bool m_verbose; @@ -1853,15 +1842,6 @@ protected: CommandOptions m_options; }; -OptionDefinition CommandObjectThreadPlanList::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display more information about the thread plans"}, - {LLDB_OPT_SET_1, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display internal as well as user thread plans"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - class CommandObjectThreadPlanDiscard : public CommandObjectParsed { public: CommandObjectThreadPlanDiscard(CommandInterpreter &interpreter) diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 0fbebb9..9df1da6 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -97,6 +97,26 @@ static bool WarnOnPotentialUnquotedUnsignedType(Args &command, return false; } +static OptionDefinition g_type_summary_add_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one." }, + { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains." }, + { LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type." }, + { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions." }, + { LLDB_OPT_SET_1, true, "inline-children", 'c', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If true, inline all child values into summary string." }, + { LLDB_OPT_SET_1, false, "omit-names", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If true, omit value names in the summary display." }, + { LLDB_OPT_SET_2, true, "summary-string", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSummaryString, "Summary string used to display text and object contents." }, + { LLDB_OPT_SET_3, false, "python-script", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command." }, + { LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type." }, + { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Input Python code to use for this type manually." }, + { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines." }, + { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "hide-empty", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Do not expand aggregate data types with no children." }, + { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "A name for this summary string." } + // clang-format on +}; + class CommandObjectTypeSummaryAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { private: @@ -111,11 +131,9 @@ private: void OptionParsingStarting(ExecutionContext *execution_context) override; - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_summary_add_options; + } // Instance variables to hold the values for command options. @@ -281,6 +299,18 @@ static const char *g_synth_addreader_instructions = " '''Optional'''\n" "class synthProvider:\n"; +static OptionDefinition g_type_synth_add_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains." }, + { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one." }, + { LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children." }, + { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children." }, + { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions." } + // clang-format on +}; + class CommandObjectTypeSynthAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { private: @@ -343,11 +373,9 @@ private: m_regex = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_synth_add_options; + } // Instance variables to hold the values for command options. @@ -502,6 +530,17 @@ public: // CommandObjectTypeFormatAdd //------------------------------------------------------------------------- +static OptionDefinition g_type_format_add_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one." }, + { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains." }, + { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions." }, + { LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Format variables as if they were of this type." } + // clang-format on +}; + class CommandObjectTypeFormatAdd : public CommandObjectParsed { private: class CommandOptions : public OptionGroup { @@ -510,9 +549,9 @@ private: ~CommandOptions() override = default; - uint32_t GetNumDefinitions() override; - - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_type_format_add_options; + } void OptionParsingStarting(ExecutionContext *execution_context) override { m_cascade = true; @@ -526,7 +565,8 @@ private: Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = + g_type_format_add_options[option_idx].short_option; bool success; switch (short_option) { @@ -561,10 +601,6 @@ private: return error; } - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. bool m_cascade; @@ -719,23 +755,14 @@ protected: } }; -OptionDefinition CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."}, - {LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."}, - {LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."}, - {LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Format variables as if they were of this type."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on +static OptionDefinition g_type_formatter_delete_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete from every category." }, + { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Delete from given category." }, + { LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Delete from given language's category." } + // clang-format on }; -uint32_t CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions() { - return sizeof(g_option_table) / sizeof(OptionDefinition); -} - class CommandObjectTypeFormatterDelete : public CommandObjectParsed { protected: class CommandOptions : public Options { @@ -774,11 +801,9 @@ protected: m_language = lldb::eLanguageTypeUnknown; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_formatter_delete_options; + } // Instance variables to hold the values for command options. @@ -872,14 +897,10 @@ protected: } }; -OptionDefinition - CommandObjectTypeFormatterDelete::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete from every category."}, - {LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Delete from given category."}, - {LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Delete from given language's category."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on +static OptionDefinition g_type_formatter_clear_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Clear every category." } + // clang-format on }; class CommandObjectTypeFormatterClear : public CommandObjectParsed { @@ -912,11 +933,9 @@ private: m_delete_all = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_formatter_clear_options; + } // Instance variables to hold the values for command options. bool m_delete_all; @@ -966,14 +985,6 @@ protected: } }; -OptionDefinition - CommandObjectTypeFormatterClear::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Clear every category."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectTypeFormatDelete //------------------------------------------------------------------------- @@ -1045,22 +1056,16 @@ class CommandObjectTypeFormatterList : public CommandObjectParsed { m_category_language.Clear(); } - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { static OptionDefinition g_option_table[] = { // clang-format off - {LLDB_OPT_SET_1, false, "category-regex", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Only show categories matching this filter."}, - {LLDB_OPT_SET_2, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Only show the category for a specific language."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} + {LLDB_OPT_SET_1, false, "category-regex", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Only show categories matching this filter."}, + {LLDB_OPT_SET_2, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Only show the category for a specific language."} // clang-format on }; - - return g_option_table; + return llvm::ArrayRef(g_option_table); } - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - // Instance variables to hold the values for command options. OptionValueString m_category_regex; @@ -1717,28 +1722,6 @@ bool CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name, } } -OptionDefinition CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."}, - {LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."}, - {LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."}, - {LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."}, - {LLDB_OPT_SET_1, true, "inline-children", 'c', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If true, inline all child values into summary string."}, - {LLDB_OPT_SET_1, false, "omit-names", 'O', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If true, omit value names in the summary display."}, - {LLDB_OPT_SET_2, true, "summary-string", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."}, - {LLDB_OPT_SET_3, false, "python-script", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."}, - {LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."}, - {LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Input Python code to use for this type manually."}, - {LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."}, - {LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "hide-empty", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Do not expand aggregate data types with no children."}, - {LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "A name for this summary string."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectTypeSummaryDelete //------------------------------------------------------------------------- @@ -1808,6 +1791,13 @@ protected: // CommandObjectTypeCategoryDefine //------------------------------------------------------------------------- +static OptionDefinition g_type_category_define_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "enabled", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If specified, this category will be created enabled." }, + { LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specify the language that this category is supported for." } + // clang-format on +}; + class CommandObjectTypeCategoryDefine : public CommandObjectParsed { class CommandOptions : public Options { public: @@ -1843,11 +1833,9 @@ class CommandObjectTypeCategoryDefine : public CommandObjectParsed { m_cate_language.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_category_define_options; + } // Instance variables to hold the values for command options. @@ -1907,19 +1895,16 @@ protected: } }; -OptionDefinition - CommandObjectTypeCategoryDefine::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "enabled", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If specified, this category will be created enabled."}, - {LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specify the language that this category is supported for."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectTypeCategoryEnable //------------------------------------------------------------------------- +static OptionDefinition g_type_category_enable_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language." }, + // clang-format on +}; + class CommandObjectTypeCategoryEnable : public CommandObjectParsed { class CommandOptions : public Options { public: @@ -1954,11 +1939,9 @@ class CommandObjectTypeCategoryEnable : public CommandObjectParsed { m_language = lldb::eLanguageTypeUnknown; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_category_enable_options; + } // Instance variables to hold the values for command options. @@ -2029,14 +2012,6 @@ protected: } }; -OptionDefinition - CommandObjectTypeCategoryEnable::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectTypeCategoryDelete //------------------------------------------------------------------------- @@ -2101,6 +2076,12 @@ protected: // CommandObjectTypeCategoryDisable //------------------------------------------------------------------------- +OptionDefinition g_type_category_disable_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language." } + // clang-format on +}; + class CommandObjectTypeCategoryDisable : public CommandObjectParsed { class CommandOptions : public Options { public: @@ -2135,11 +2116,9 @@ class CommandObjectTypeCategoryDisable : public CommandObjectParsed { m_language = lldb::eLanguageTypeUnknown; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_category_disable_options; + } // Instance variables to hold the values for command options. @@ -2205,14 +2184,6 @@ protected: } }; -OptionDefinition - CommandObjectTypeCategoryDisable::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectTypeCategoryList //------------------------------------------------------------------------- @@ -2531,21 +2502,19 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name, } } -OptionDefinition CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] = { +#endif // LLDB_DISABLE_PYTHON + +static OptionDefinition g_type_filter_add_options[] = { // clang-format off - {LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."}, - {LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."}, - {LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."}, - {LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children."}, - {LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} + { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains." }, + { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects." }, + { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one." }, + { LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view." }, + { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions." } // clang-format on }; -#endif // LLDB_DISABLE_PYTHON - class CommandObjectTypeFilterAdd : public CommandObjectParsed { private: class CommandOptions : public Options { @@ -2605,11 +2574,9 @@ private: m_regex = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_type_filter_add_options; + } // Instance variables to hold the values for command options. @@ -2791,22 +2758,16 @@ protected: } }; -OptionDefinition CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."}, - {LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."}, - {LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."}, - {LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."}, - {LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //---------------------------------------------------------------------- // "type lookup" //---------------------------------------------------------------------- +static OptionDefinition g_type_lookup_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "show-help", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display available help for types" }, + { LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Which language's types should the search scope be" } + // clang-format on +}; + class CommandObjectTypeLookup : public CommandObjectRaw { protected: // this function is allowed to do a more aggressive job at guessing languages @@ -2837,15 +2798,15 @@ protected: ~CommandOptions() override = default; - uint32_t GetNumDefinitions() override { return 3; } - - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_type_lookup_options; + } Error SetOptionValue(uint32_t option_idx, const char *option_value, ExecutionContext *execution_context) override { Error error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = g_type_lookup_options[option_idx].short_option; switch (short_option) { case 'h': @@ -2872,7 +2833,6 @@ protected: // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; bool m_show_help; lldb::LanguageType m_language; }; @@ -3052,14 +3012,6 @@ public: } }; -OptionDefinition CommandObjectTypeLookup::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "show-help", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display available help for types"}, - {LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Which language's types should the search scope be"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - template class CommandObjectFormatterInfo : public CommandObjectRaw { public: diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp index 7ff4cce..83eb1dd 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -152,6 +152,20 @@ bool CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( //------------------------------------------------------------------------- // CommandObjectWatchpointList //------------------------------------------------------------------------- + +//------------------------------------------------------------------------- +// CommandObjectWatchpointList::Options +//------------------------------------------------------------------------- +#pragma mark List::CommandOptions + +static OptionDefinition g_watchpoint_list_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the watchpoint (no location info)." }, + { LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the watchpoint and its locations." }, + { LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the watchpoint (for debugging debugger bugs)." } + // clang-format on +}; + #pragma mark List class CommandObjectWatchpointList : public CommandObjectParsed { @@ -211,11 +225,9 @@ public: m_level = lldb::eDescriptionLevelFull; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_watchpoint_list_options; + } // Instance variables to hold the values for command options. @@ -291,21 +303,6 @@ private: }; //------------------------------------------------------------------------- -// CommandObjectWatchpointList::Options -//------------------------------------------------------------------------- -#pragma mark List::CommandOptions - -OptionDefinition CommandObjectWatchpointList::CommandOptions::g_option_table[] = - { - // clang-format off - {LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the watchpoint (no location info)."}, - {LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the watchpoint and its locations."}, - {LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the watchpoint (for debugging debugger bugs)."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - -//------------------------------------------------------------------------- // CommandObjectWatchpointEnable //------------------------------------------------------------------------- #pragma mark Enable @@ -531,6 +528,13 @@ protected: // CommandObjectWatchpointIgnore //------------------------------------------------------------------------- +#pragma mark Ignore::CommandOptions +static OptionDefinition g_watchpoint_ignore_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, true, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping." } + // clang-format on +}; + class CommandObjectWatchpointIgnore : public CommandObjectParsed { public: CommandObjectWatchpointIgnore(CommandInterpreter &interpreter) @@ -582,11 +586,9 @@ public: m_ignore_count = 0; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_watchpoint_ignore_options; + } // Instance variables to hold the values for command options. @@ -644,19 +646,18 @@ private: CommandOptions m_options; }; -#pragma mark Ignore::CommandOptions - -OptionDefinition - CommandObjectWatchpointIgnore::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, true, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectWatchpointModify //------------------------------------------------------------------------- + +#pragma mark Modify::CommandOptions + +static OptionDefinition g_watchpoint_modify_options[] = { + // clang-format off + { LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true." } + // clang-format on +}; + #pragma mark Modify class CommandObjectWatchpointModify : public CommandObjectParsed { @@ -716,11 +717,9 @@ public: m_condition_passed = false; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_watchpoint_modify_options; + } // Instance variables to hold the values for command options. @@ -781,16 +780,6 @@ private: CommandOptions m_options; }; -#pragma mark Modify::CommandOptions - -OptionDefinition - CommandObjectWatchpointModify::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectWatchpointSetVariable //------------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index c67bae0..a0214ad 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -31,6 +31,28 @@ using namespace lldb_private; // CommandObjectWatchpointCommandAdd //------------------------------------------------------------------------- +// FIXME: "script-type" needs to have its contents determined dynamically, so +// somebody can add a new scripting +// language to lldb and have it pickable here without having to change this +// enumeration by hand and rebuild lldb proper. + +static OptionEnumValueElement g_script_option_enumeration[4] = { + {eScriptLanguageNone, "command", + "Commands are in the lldb command interpreter language"}, + {eScriptLanguagePython, "python", "Commands are in the Python language."}, + {eSortOrderByName, "default-script", + "Commands are in the default scripting language."}, + {0, nullptr, nullptr}}; + +static OptionDefinition g_watchpoint_command_add_options[] = { + // clang-format off + { LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line watchpoint command inline. Be sure to surround it with quotes." }, + { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether watchpoint command execution should terminate on error." }, + { LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used." }, + { LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this watchpoint. Be sure to give a module name if appropriate." } + // clang-format on +}; + class CommandObjectWatchpointCommandAdd : public CommandObjectParsed, public IOHandlerDelegateMultiline { public: @@ -309,7 +331,7 @@ are no syntax errors may indicate that a function was declared but never called. case 's': m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum( - option_arg, g_option_table[option_idx].enum_values, + option_arg, GetDefinitions()[option_idx].enum_values, eScriptLanguageNone, error); m_use_script_language = (m_script_language == eScriptLanguagePython || @@ -348,11 +370,9 @@ are no syntax errors may indicate that a function was declared but never called. m_function_name.clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; + llvm::ArrayRef GetDefinitions() override { + return g_watchpoint_command_add_options; + } // Instance variables to hold the values for command options. @@ -459,30 +479,6 @@ private: CommandOptions m_options; }; -// FIXME: "script-type" needs to have its contents determined dynamically, so -// somebody can add a new scripting -// language to lldb and have it pickable here without having to change this -// enumeration by hand and rebuild lldb proper. - -static OptionEnumValueElement g_script_option_enumeration[4] = { - {eScriptLanguageNone, "command", - "Commands are in the lldb command interpreter language"}, - {eScriptLanguagePython, "python", "Commands are in the Python language."}, - {eSortOrderByName, "default-script", - "Commands are in the default scripting language."}, - {0, nullptr, nullptr}}; - -OptionDefinition - CommandObjectWatchpointCommandAdd::CommandOptions::g_option_table[] = { - // clang-format off - {LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line watchpoint command inline. Be sure to surround it with quotes."}, - {LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether watchpoint command execution should terminate on error."}, - {LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."}, - {LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this watchpoint. Be sure to give a module name if appropriate."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } - // clang-format on -}; - //------------------------------------------------------------------------- // CommandObjectWatchpointCommandDelete //------------------------------------------------------------------------- diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 25bcac8..6408dab 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -1256,7 +1256,7 @@ void Args::ParseArgsForCompletion(Options &options, OptionParser::EnableError(false); int val; - const OptionDefinition *opt_defs = options.GetDefinitions(); + auto opt_defs = options.GetDefinitions(); // Fooey... OptionParser::Parse permutes the GetArgumentVector to move the // options to the front. @@ -1347,13 +1347,11 @@ void Args::ParseArgsForCompletion(Options &options, // See if the option takes an argument, and see if one was supplied. if (long_options_index >= 0) { int opt_defs_index = -1; - for (int i = 0;; i++) { - if (opt_defs[i].short_option == 0) - break; - else if (opt_defs[i].short_option == val) { - opt_defs_index = i; - break; - } + for (size_t i = 0; i < opt_defs.size(); i++) { + if (opt_defs[i].short_option != val) + continue; + opt_defs_index = i; + break; } const OptionDefinition *def = long_options[long_options_index].definition; diff --git a/lldb/source/Interpreter/OptionGroupArchitecture.cpp b/lldb/source/Interpreter/OptionGroupArchitecture.cpp index 2de0dd2..870afb2 100644 --- a/lldb/source/Interpreter/OptionGroupArchitecture.cpp +++ b/lldb/source/Interpreter/OptionGroupArchitecture.cpp @@ -28,11 +28,7 @@ static OptionDefinition g_option_table[] = { "Specify the architecture for the target."}, }; -uint32_t OptionGroupArchitecture::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} - -const OptionDefinition *OptionGroupArchitecture::GetDefinitions() { +llvm::ArrayRef OptionGroupArchitecture::GetDefinitions() { return g_option_table; } diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp index aa0d3cc..b0628ff 100644 --- a/lldb/source/Interpreter/OptionGroupFormat.cpp +++ b/lldb/source/Interpreter/OptionGroupFormat.cpp @@ -47,18 +47,15 @@ static OptionDefinition g_option_table[] = { "The number of total items to display."}, }; -uint32_t OptionGroupFormat::GetNumDefinitions() { +llvm::ArrayRef OptionGroupFormat::GetDefinitions() { + llvm::ArrayRef result = g_option_table; if (m_byte_size.GetDefaultValue() < UINT64_MAX) { if (m_count.GetDefaultValue() < UINT64_MAX) - return 4; + return result; else - return 3; + return result.take_front(3); } - return 2; -} - -const OptionDefinition *OptionGroupFormat::GetDefinitions() { - return g_option_table; + return result.take_front(2); } Error OptionGroupFormat::SetOptionValue(uint32_t option_idx, diff --git a/lldb/source/Interpreter/OptionGroupOutputFile.cpp b/lldb/source/Interpreter/OptionGroupOutputFile.cpp index d9eccb9..d01f7db 100644 --- a/lldb/source/Interpreter/OptionGroupOutputFile.cpp +++ b/lldb/source/Interpreter/OptionGroupOutputFile.cpp @@ -34,11 +34,7 @@ static OptionDefinition g_option_table[] = { "Append to the file specified with '--outfile '."}, }; -uint32_t OptionGroupOutputFile::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} - -const OptionDefinition *OptionGroupOutputFile::GetDefinitions() { +llvm::ArrayRef OptionGroupOutputFile::GetDefinitions() { return g_option_table; } diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp index 776bac7..7958d34 100644 --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -85,16 +85,11 @@ static OptionDefinition g_option_table[] = { "that contains a root of all " "remote system files."}}; -const OptionDefinition *OptionGroupPlatform::GetDefinitions() { +llvm::ArrayRef OptionGroupPlatform::GetDefinitions() { + llvm::ArrayRef result(g_option_table); if (m_include_platform_option) - return g_option_table; - return g_option_table + 1; -} - -uint32_t OptionGroupPlatform::GetNumDefinitions() { - if (m_include_platform_option) - return llvm::array_lengthof(g_option_table); - return llvm::array_lengthof(g_option_table) - 1; + return result; + return result.drop_front(); } Error OptionGroupPlatform::SetOptionValue(uint32_t option_idx, diff --git a/lldb/source/Interpreter/OptionGroupUUID.cpp b/lldb/source/Interpreter/OptionGroupUUID.cpp index 2f78609..778ade980 100644 --- a/lldb/source/Interpreter/OptionGroupUUID.cpp +++ b/lldb/source/Interpreter/OptionGroupUUID.cpp @@ -27,11 +27,7 @@ static OptionDefinition g_option_table[] = { nullptr, nullptr, 0, eArgTypeNone, "A module UUID value."}, }; -uint32_t OptionGroupUUID::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} - -const OptionDefinition *OptionGroupUUID::GetDefinitions() { +llvm::ArrayRef OptionGroupUUID::GetDefinitions() { return g_option_table; } diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp index e594392..70fa219 100644 --- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp +++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp @@ -19,6 +19,8 @@ #include "lldb/Target/Target.h" #include "lldb/Utility/Utils.h" +#include "llvm/ADT/ArrayRef.h" + using namespace lldb; using namespace lldb_private; @@ -67,14 +69,10 @@ static OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "element-count", 'Z', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Treat the result of the expression as if its type is an array of this " - "many values."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; - -uint32_t OptionGroupValueObjectDisplay::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} + "many values."}}; -const OptionDefinition *OptionGroupValueObjectDisplay::GetDefinitions() { +llvm::ArrayRef +OptionGroupValueObjectDisplay::GetDefinitions() { return g_option_table; } diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp index 253a2ed..f26d367 100644 --- a/lldb/source/Interpreter/OptionGroupVariable.cpp +++ b/lldb/source/Interpreter/OptionGroupVariable.cpp @@ -24,7 +24,7 @@ using namespace lldb_private; // if you add any options here, remember to update the counters in // OptionGroupVariable::GetNumDefinitions() -static OptionDefinition g_option_table[] = { +static OptionDefinition g_variable_options[] = { {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Omit function arguments."}, @@ -80,7 +80,7 @@ Error OptionGroupVariable::SetOptionValue(uint32_t option_idx, Error error; if (!include_frame_options) option_idx += 3; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = g_variable_options[option_idx].short_option; switch (short_option) { case 'r': use_regex = true; @@ -129,22 +129,14 @@ void OptionGroupVariable::OptionParsingStarting( #define NUM_FRAME_OPTS 3 -const OptionDefinition *OptionGroupVariable::GetDefinitions() { +llvm::ArrayRef OptionGroupVariable::GetDefinitions() { + llvm::ArrayRef result = g_variable_options; // Show the "--no-args", "--no-locals" and "--show-globals" // options if we are showing frame specific options if (include_frame_options) - return g_option_table; + return result; // Skip the "--no-args", "--no-locals" and "--show-globals" // options if we are not showing frame specific options (globals only) - return &g_option_table[NUM_FRAME_OPTS]; -} - -uint32_t OptionGroupVariable::GetNumDefinitions() { - // Count the "--no-args", "--no-locals" and "--show-globals" - // options if we are showing frame specific options. - if (include_frame_options) - return llvm::array_lengthof(g_option_table); - else - return llvm::array_lengthof(g_option_table) - NUM_FRAME_OPTS; + return result.drop_front(NUM_FRAME_OPTS); } diff --git a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp index 8ed9640..15f4c23 100644 --- a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp +++ b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp @@ -93,10 +93,6 @@ void OptionGroupWatchpoint::OptionParsingStarting( watch_size = 0; } -const OptionDefinition *OptionGroupWatchpoint::GetDefinitions() { +llvm::ArrayRef OptionGroupWatchpoint::GetDefinitions() { return g_option_table; } - -uint32_t OptionGroupWatchpoint::GetNumDefinitions() { - return llvm::array_lengthof(g_option_table); -} diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 91f1a5f..8b28c6d 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -164,7 +164,7 @@ void Options::BuildValidOptionSets() { if (num_options == 0) return; - const OptionDefinition *opt_defs = GetDefinitions(); + auto opt_defs = GetDefinitions(); m_required_options.resize(1); m_optional_options.resize(1); @@ -173,8 +173,8 @@ void Options::BuildValidOptionSets() { uint32_t num_option_sets = 0; - for (int i = 0; i < num_options; i++) { - uint32_t this_usage_mask = opt_defs[i].usage_mask; + for (const auto &def : opt_defs) { + uint32_t this_usage_mask = def.usage_mask; if (this_usage_mask == LLDB_OPT_SET_ALL) { if (num_option_sets == 0) num_option_sets = 1; @@ -192,52 +192,35 @@ void Options::BuildValidOptionSets() { m_required_options.resize(num_option_sets); m_optional_options.resize(num_option_sets); - for (int i = 0; i < num_options; ++i) { + for (const auto &def : opt_defs) { for (uint32_t j = 0; j < num_option_sets; j++) { - if (opt_defs[i].usage_mask & 1 << j) { - if (opt_defs[i].required) - m_required_options[j].insert(opt_defs[i].short_option); + if (def.usage_mask & 1 << j) { + if (def.required) + m_required_options[j].insert(def.short_option); else - m_optional_options[j].insert(opt_defs[i].short_option); + m_optional_options[j].insert(def.short_option); } } } } } -uint32_t Options::NumCommandOptions() { - const OptionDefinition *opt_defs = GetDefinitions(); - if (opt_defs == nullptr) - return 0; - - int i = 0; - - if (opt_defs != nullptr) { - while (opt_defs[i].long_option != nullptr) - ++i; - } - - return i; -} +uint32_t Options::NumCommandOptions() { return GetDefinitions().size(); } Option *Options::GetLongOptions() { // Check to see if this has already been done. if (m_getopt_table.empty()) { - // Check to see if there are any options. - const uint32_t num_options = NumCommandOptions(); - if (num_options == 0) + auto defs = GetDefinitions(); + if (defs.empty()) return nullptr; - uint32_t i; - const OptionDefinition *opt_defs = GetDefinitions(); - std::map option_seen; - m_getopt_table.resize(num_options + 1); - for (i = 0; i < num_options; ++i) { - const int short_opt = opt_defs[i].short_option; + m_getopt_table.resize(defs.size() + 1); + for (size_t i = 0; i < defs.size(); ++i) { + const int short_opt = defs[i].short_option; - m_getopt_table[i].definition = &opt_defs[i]; + m_getopt_table[i].definition = &defs[i]; m_getopt_table[i].flag = nullptr; m_getopt_table[i].val = short_opt; @@ -253,25 +236,25 @@ Option *Options::GetLongOptions() { "option[%u] --%s has a short option -%c that " "conflicts with option[%u] --%s, short option won't " "be used for --%s\n", - i, opt_defs[i].long_option, short_opt, pos->second, + (int)i, defs[i].long_option, short_opt, pos->second, m_getopt_table[pos->second].definition->long_option, - opt_defs[i].long_option); + defs[i].long_option); else Host::SystemLog(Host::eSystemLogError, "option[%u] --%s has a short option 0x%x that " "conflicts with option[%u] --%s, short option won't " "be used for --%s\n", - i, opt_defs[i].long_option, short_opt, pos->second, + (int)i, defs[i].long_option, short_opt, pos->second, m_getopt_table[pos->second].definition->long_option, - opt_defs[i].long_option); + defs[i].long_option); } } // getopt_long_only requires a NULL final entry in the table: - m_getopt_table[i].definition = nullptr; - m_getopt_table[i].flag = nullptr; - m_getopt_table[i].val = 0; + m_getopt_table.back().definition = nullptr; + m_getopt_table.back().flag = nullptr; + m_getopt_table.back().val = 0; } if (m_getopt_table.empty()) @@ -351,19 +334,25 @@ void Options::OutputFormattedUsageText(Stream &strm, } bool Options::SupportsLongOption(const char *long_option) { - if (long_option && long_option[0]) { - const OptionDefinition *opt_defs = GetDefinitions(); - if (opt_defs) { - const char *long_option_name = long_option; - if (long_option[0] == '-' && long_option[1] == '-') - long_option_name += 2; - - for (uint32_t i = 0; opt_defs[i].long_option; ++i) { - if (strcmp(opt_defs[i].long_option, long_option_name) == 0) - return true; - } - } + if (!long_option || !long_option[0]) + return false; + + auto opt_defs = GetDefinitions(); + if (opt_defs.empty()) + return false; + + const char *long_option_name = long_option; + if (long_option[0] == '-' && long_option[1] == '-') + long_option_name += 2; + + for (auto &def : opt_defs) { + if (!def.long_option) + continue; + + if (strcmp(def.long_option, long_option_name) == 0) + return true; } + return false; } @@ -415,7 +404,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, uint32_t screen_width) { const bool only_print_args = cmd->IsDashDashCommand(); - const OptionDefinition *opt_defs = GetDefinitions(); + auto opt_defs = GetDefinitions(); const uint32_t save_indent_level = strm.GetIndentLevel(); const char *name; @@ -465,14 +454,12 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, std::set options; std::set::const_iterator options_pos, options_end; - for (i = 0; i < num_options; ++i) { - if (opt_defs[i].usage_mask & opt_set_mask && - isprint8(opt_defs[i].short_option)) { + for (auto &def : opt_defs) { + if (def.usage_mask & opt_set_mask && isprint8(def.short_option)) { // Add current option to the end of out_stream. - if (opt_defs[i].required == true && - opt_defs[i].option_has_arg == OptionParser::eNoArgument) { - options.insert(opt_defs[i].short_option); + if (def.required && def.option_has_arg == OptionParser::eNoArgument) { + options.insert(def.short_option); } } } @@ -491,14 +478,14 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, } } - for (i = 0, options.clear(); i < num_options; ++i) { - if (opt_defs[i].usage_mask & opt_set_mask && - isprint8(opt_defs[i].short_option)) { + options.clear(); + for (auto &def : opt_defs) { + if (def.usage_mask & opt_set_mask && isprint8(def.short_option)) { // Add current option to the end of out_stream. - if (opt_defs[i].required == false && - opt_defs[i].option_has_arg == OptionParser::eNoArgument) { - options.insert(opt_defs[i].short_option); + if (def.required == false && + def.option_has_arg == OptionParser::eNoArgument) { + options.insert(def.short_option); } } } @@ -520,26 +507,21 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, // First go through and print the required options (list them up front). - for (i = 0; i < num_options; ++i) { - if (opt_defs[i].usage_mask & opt_set_mask && - isprint8(opt_defs[i].short_option)) { - if (opt_defs[i].required && - opt_defs[i].option_has_arg != OptionParser::eNoArgument) - PrintOption(opt_defs[i], eDisplayBestOption, " ", nullptr, true, - strm); + for (auto &def : opt_defs) { + if (def.usage_mask & opt_set_mask && isprint8(def.short_option)) { + if (def.required && def.option_has_arg != OptionParser::eNoArgument) + PrintOption(def, eDisplayBestOption, " ", nullptr, true, strm); } } // Now go through again, and this time only print the optional options. - for (i = 0; i < num_options; ++i) { - if (opt_defs[i].usage_mask & opt_set_mask) { + for (auto &def : opt_defs) { + if (def.usage_mask & opt_set_mask) { // Add current option to the end of out_stream. - if (!opt_defs[i].required && - opt_defs[i].option_has_arg != OptionParser::eNoArgument) - PrintOption(opt_defs[i], eDisplayBestOption, " ", nullptr, true, - strm); + if (!def.required && def.option_has_arg != OptionParser::eNoArgument) + PrintOption(def, eDisplayBestOption, " ", nullptr, true, strm); } } @@ -582,15 +564,15 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, // them alphabetically (by short_option) // when writing out detailed help for each option. - for (i = 0; i < num_options; ++i) - options_seen.insert(std::make_pair(opt_defs[i].short_option, i)); + i = 0; + for (auto &def : opt_defs) + options_seen.insert(std::make_pair(def.short_option, i++)); // Go through the unique'd and alphabetically sorted vector of options, find // the table entry for each option // and write out the detailed help information for that option. bool first_option_printed = false; - ; for (auto pos : options_seen) { i = pos.second; @@ -686,7 +668,7 @@ bool Options::HandleOptionCompletion( // an option or its argument. Otherwise we'll call HandleArgumentCompletion. // In the future we can use completion to validate options as well if we want. - const OptionDefinition *opt_defs = GetDefinitions(); + auto opt_defs = GetDefinitions(); std::string cur_opt_std_str(input.GetArgumentAtIndex(cursor_index)); cur_opt_std_str.erase(char_pos); @@ -706,16 +688,22 @@ bool Options::HandleOptionCompletion( // within the option group they belong to. char opt_str[3] = {'-', 'a', '\0'}; - for (int j = 0; opt_defs[j].short_option != 0; j++) { - opt_str[1] = opt_defs[j].short_option; + for (auto &def : opt_defs) { + if (!def.short_option) + continue; + opt_str[1] = def.short_option; matches.AppendString(opt_str); } + return true; } else if (opt_defs_index == OptionArgElement::eBareDoubleDash) { std::string full_name("--"); - for (int j = 0; opt_defs[j].short_option != 0; j++) { + for (auto &def : opt_defs) { + if (!def.short_option) + continue; + full_name.erase(full_name.begin() + 2, full_name.end()); - full_name.append(opt_defs[j].long_option); + full_name.append(def.long_option); matches.AppendString(full_name.c_str()); } return true; @@ -748,11 +736,13 @@ bool Options::HandleOptionCompletion( if (cur_opt_str && strlen(cur_opt_str) > 2 && cur_opt_str[0] == '-' && cur_opt_str[1] == '-') { - for (int j = 0; opt_defs[j].short_option != 0; j++) { - if (strstr(opt_defs[j].long_option, cur_opt_str + 2) == - opt_defs[j].long_option) { + for (auto &def : opt_defs) { + if (!def.long_option) + continue; + + if (strstr(def.long_option, cur_opt_str + 2) == def.long_option) { std::string full_name("--"); - full_name.append(opt_defs[j].long_option); + full_name.append(def.long_option); // The options definitions table has duplicates because of the // way the grouping information is stored, so only add once. bool duplicate = false; @@ -799,7 +789,7 @@ bool Options::HandleOptionArgumentCompletion( int match_start_point, int max_return_elements, CommandInterpreter &interpreter, bool &word_complete, lldb_private::StringList &matches) { - const OptionDefinition *opt_defs = GetDefinitions(); + auto opt_defs = GetDefinitions(); std::unique_ptr filter_ap; int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; @@ -882,9 +872,8 @@ bool Options::HandleOptionArgumentCompletion( } void OptionGroupOptions::Append(OptionGroup *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) { + auto group_option_defs = group->GetDefinitions(); + for (uint32_t i = 0; i < group_option_defs.size(); ++i) { m_option_infos.push_back(OptionInfo(group, i)); m_option_defs.push_back(group_option_defs[i]); } @@ -901,9 +890,8 @@ const OptionGroup *OptionGroupOptions::GetGroupWithOption(char short_opt) { void OptionGroupOptions::Append(OptionGroup *group, uint32_t src_mask, uint32_t dst_mask) { - 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) { + auto group_option_defs = group->GetDefinitions(); + for (uint32_t i = 0; i < group_option_defs.size(); ++i) { if (group_option_defs[i].usage_mask & src_mask) { m_option_infos.push_back(OptionInfo(group, i)); m_option_defs.push_back(group_option_defs[i]); @@ -914,9 +902,6 @@ void OptionGroupOptions::Append(OptionGroup *group, uint32_t src_mask, void OptionGroupOptions::Finalize() { m_did_finalize = true; - OptionDefinition empty_option_def = { - 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}; - m_option_defs.push_back(empty_option_def); } Error OptionGroupOptions::SetOptionValue(uint32_t option_idx, @@ -925,7 +910,6 @@ Error OptionGroupOptions::SetOptionValue(uint32_t option_idx, // After calling OptionGroupOptions::Append(...), you must finalize the groups // by calling OptionGroupOptions::Finlize() assert(m_did_finalize); - assert(m_option_infos.size() + 1 == m_option_defs.size()); Error error; if (option_idx < m_option_infos.size()) { error = m_option_infos[option_idx].option_group->SetOptionValue( diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 630490e..7312dfc 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -470,6 +470,11 @@ LanguageRuntime *AppleObjCRuntimeV2::CreateInstance(Process *process, return NULL; } +static OptionDefinition g_objc_classtable_dump_options[] = { + {LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Print ivar and method information in detail"}}; + class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed { public: class CommandOptions : public Options { @@ -501,10 +506,11 @@ public: m_verbose.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_objc_classtable_dump_options; + } OptionValueBoolean m_verbose; - static OptionDefinition g_option_table[]; }; CommandObjectObjC_ClassTable_Dump(CommandInterpreter &interpreter) @@ -627,13 +633,6 @@ protected: CommandOptions m_options; }; -OptionDefinition - CommandObjectObjC_ClassTable_Dump::CommandOptions::g_option_table[] = { - {LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Print ivar and method information in detail"}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; - class CommandObjectMultiwordObjC_TaggedPointer_Info : public CommandObjectParsed { public: diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index 9d751a7..1e4d846 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -3692,6 +3692,15 @@ public: } }; +static OptionDefinition g_renderscript_kernel_bp_set_options[] = { + {LLDB_OPT_SET_1, false, "coordinate", 'c', OptionParser::eRequiredArgument, + nullptr, nullptr, 0, eArgTypeValue, + "Set a breakpoint on a single invocation of the kernel with specified " + "coordinate.\n" + "Coordinate takes the form 'x[,y][,z] where x,y,z are positive " + "integers representing kernel dimensions. " + "Any unset dimensions will be defaulted to zero."}}; + class CommandObjectRenderScriptRuntimeKernelBreakpointSet : public CommandObjectParsed { public: @@ -3770,9 +3779,10 @@ public: m_coord[2] = -1; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_renderscript_kernel_bp_set_options; + } - static OptionDefinition g_option_table[]; std::array m_coord; }; @@ -3809,17 +3819,6 @@ private: CommandOptions m_options; }; -OptionDefinition CommandObjectRenderScriptRuntimeKernelBreakpointSet:: - CommandOptions::g_option_table[] = { - {LLDB_OPT_SET_1, false, "coordinate", 'c', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, - "Set a breakpoint on a single invocation of the kernel with specified " - "coordinate.\n" - "Coordinate takes the form 'x[,y][,z] where x,y,z are positive " - "integers representing kernel dimensions. " - "Any unset dimensions will be defaulted to zero."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; - class CommandObjectRenderScriptRuntimeKernelBreakpointAll : public CommandObjectParsed { public: @@ -3972,6 +3971,11 @@ public: } }; +static OptionDefinition g_renderscript_runtime_alloc_dump_options[] = { + {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, + nullptr, nullptr, 0, eArgTypeFilename, + "Print results to specified file instead of command line."}}; + class CommandObjectRenderScriptRuntimeContext : public CommandObjectMultiword { public: CommandObjectRenderScriptRuntimeContext(CommandInterpreter &interpreter) @@ -4034,9 +4038,10 @@ public: m_outfile.Clear(); } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_renderscript_runtime_alloc_dump_options; + } - static OptionDefinition g_option_table[]; FileSpec m_outfile; }; @@ -4103,12 +4108,10 @@ private: CommandOptions m_options; }; -OptionDefinition CommandObjectRenderScriptRuntimeAllocationDump:: - CommandOptions::g_option_table[] = { - {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeFilename, - "Print results to specified file instead of command line."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; +static OptionDefinition g_renderscript_runtime_alloc_list_options[] = { + {LLDB_OPT_SET_1, false, "id", 'i', OptionParser::eRequiredArgument, nullptr, + nullptr, 0, eArgTypeIndex, + "Only show details of a single allocation with specified id."}}; class CommandObjectRenderScriptRuntimeAllocationList : public CommandObjectParsed { @@ -4157,9 +4160,10 @@ public: m_id = 0; } - const OptionDefinition *GetDefinitions() override { return g_option_table; } + llvm::ArrayRef GetDefinitions() override { + return g_renderscript_runtime_alloc_list_options; + } - static OptionDefinition g_option_table[]; uint32_t m_id; }; @@ -4177,13 +4181,6 @@ private: CommandOptions m_options; }; -OptionDefinition CommandObjectRenderScriptRuntimeAllocationList:: - CommandOptions::g_option_table[] = { - {LLDB_OPT_SET_1, false, "id", 'i', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeIndex, - "Only show details of a single allocation with specified id."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; - class CommandObjectRenderScriptRuntimeAllocationLoad : public CommandObjectParsed { public: diff --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp index 0a6e324d..ff87150 100644 --- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -398,6 +398,105 @@ static void RegisterFilterOperations() { /// It is valid to run the enable command when logging is already enabled. /// This resets the logging with whatever settings are currently set. // ------------------------------------------------------------------------- + +static OptionDefinition g_enable_option_table[] = { + // Source stream include/exclude options (the first-level filter). + // This one should be made as small as possible as everything that + // goes through here must be processed by the process monitor. + {LLDB_OPT_SET_ALL, false, "any-process", 'a', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Specifies log messages from other related processes should be " + "included."}, + {LLDB_OPT_SET_ALL, false, "debug", 'd', OptionParser::eNoArgument, nullptr, + nullptr, 0, eArgTypeNone, + "Specifies debug-level log messages should be included. Specifying" + " --debug implies --info."}, + {LLDB_OPT_SET_ALL, false, "info", 'i', OptionParser::eNoArgument, nullptr, + nullptr, 0, eArgTypeNone, + "Specifies info-level log messages should be included."}, + {LLDB_OPT_SET_ALL, false, "filter", 'f', OptionParser::eRequiredArgument, + nullptr, nullptr, 0, eArgRawInput, + // There doesn't appear to be a great way for me to have these + // multi-line, formatted tables in help. This looks mostly right + // but there are extra linefeeds added at seemingly random spots, + // and indentation isn't handled properly on those lines. + "Appends a filter rule to the log message filter chain. Multiple " + "rules may be added by specifying this option multiple times, " + "once per filter rule. Filter rules are processed in the order " + "they are specified, with the --no-match-accepts setting used " + "for any message that doesn't match one of the rules.\n" + "\n" + " Filter spec format:\n" + "\n" + " --filter \"{action} {attribute} {op}\"\n" + "\n" + " {action} :=\n" + " accept |\n" + " reject\n" + "\n" + " {attribute} :=\n" + " activity | // message's most-derived activity\n" + " activity-chain | // message's {parent}:{child} activity\n" + " category | // message's category\n" + " message | // message's expanded contents\n" + " subsystem | // message's subsystem\n" + "\n" + " {op} :=\n" + " match {exact-match-text} |\n" + " regex {search-regex}\n" + "\n" + "The regex flavor used is the C++ std::regex ECMAScript format. " + "Prefer character classes like [[:digit:]] to \\d and the like, as " + "getting the backslashes escaped through properly is error-prone."}, + {LLDB_OPT_SET_ALL, false, "live-stream", 'l', + OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, + "Specify whether logging events are live-streamed or buffered. " + "True indicates live streaming, false indicates buffered. The " + "default is true (live streaming). Live streaming will deliver " + "log messages with less delay, but buffered capture mode has less " + "of an observer effect."}, + {LLDB_OPT_SET_ALL, false, "no-match-accepts", 'n', + OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, + "Specify whether a log message that doesn't match any filter rule " + "is accepted or rejected, where true indicates accept. The " + "default is true."}, + {LLDB_OPT_SET_ALL, false, "echo-to-stderr", 'e', + OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, + "Specify whether os_log()/NSLog() messages are echoed to the " + "target program's stderr. When DarwinLog is enabled, we shut off " + "the mirroring of os_log()/NSLog() to the program's stderr. " + "Setting this flag to true will restore the stderr mirroring." + "The default is false."}, + {LLDB_OPT_SET_ALL, false, "broadcast-events", 'b', + OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, + "Specify if the plugin should broadcast events. Broadcasting " + "log events is a requirement for displaying the log entries in " + "LLDB command-line. It is also required if LLDB clients want to " + "process log events. The default is true."}, + // Message formatting options + {LLDB_OPT_SET_ALL, false, "timestamp-relative", 'r', + OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + "Include timestamp in the message header when printing a log " + "message. The timestamp is relative to the first displayed " + "message."}, + {LLDB_OPT_SET_ALL, false, "subsystem", 's', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Include the subsystem in the the message header when displaying " + "a log message."}, + {LLDB_OPT_SET_ALL, false, "category", 'c', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Include the category in the the message header when displaying " + "a log message."}, + {LLDB_OPT_SET_ALL, false, "activity-chain", 'C', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Include the activity parent-child chain in the the message header " + "when displaying a log message. The activity hierarchy is " + "displayed as {grandparent-activity}:" + "{parent-activity}:{activity}[:...]."}, + {LLDB_OPT_SET_ALL, false, "all-fields", 'A', OptionParser::eNoArgument, + nullptr, nullptr, 0, eArgTypeNone, + "Shortcut to specify that all header fields should be displayed."}}; + class EnableOptions : public Options { public: EnableOptions() @@ -492,7 +591,7 @@ public: return error; } - const OptionDefinition *GetDefinitions() override { + llvm::ArrayRef GetDefinitions() override { return g_enable_option_table; } @@ -661,8 +760,6 @@ private: return -1; } - static OptionDefinition g_enable_option_table[]; - bool m_include_debug_level; bool m_include_info_level; bool m_include_any_process; @@ -677,107 +774,6 @@ private: FilterRules m_filter_rules; }; -OptionDefinition EnableOptions::g_enable_option_table[] = { - // Source stream include/exclude options (the first-level filter). - // This one should be made as small as possible as everything that - // goes through here must be processed by the process monitor. - {LLDB_OPT_SET_ALL, false, "any-process", 'a', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Specifies log messages from other related processes should be " - "included."}, - {LLDB_OPT_SET_ALL, false, "debug", 'd', OptionParser::eNoArgument, nullptr, - nullptr, 0, eArgTypeNone, - "Specifies debug-level log messages should be included. Specifying" - " --debug implies --info."}, - {LLDB_OPT_SET_ALL, false, "info", 'i', OptionParser::eNoArgument, nullptr, - nullptr, 0, eArgTypeNone, - "Specifies info-level log messages should be included."}, - {LLDB_OPT_SET_ALL, false, "filter", 'f', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgRawInput, - // There doesn't appear to be a great way for me to have these - // multi-line, formatted tables in help. This looks mostly right - // but there are extra linefeeds added at seemingly random spots, - // and indentation isn't handled properly on those lines. - "Appends a filter rule to the log message filter chain. Multiple " - "rules may be added by specifying this option multiple times, " - "once per filter rule. Filter rules are processed in the order " - "they are specified, with the --no-match-accepts setting used " - "for any message that doesn't match one of the rules.\n" - "\n" - " Filter spec format:\n" - "\n" - " --filter \"{action} {attribute} {op}\"\n" - "\n" - " {action} :=\n" - " accept |\n" - " reject\n" - "\n" - " {attribute} :=\n" - " activity | // message's most-derived activity\n" - " activity-chain | // message's {parent}:{child} activity\n" - " category | // message's category\n" - " message | // message's expanded contents\n" - " subsystem | // message's subsystem\n" - "\n" - " {op} :=\n" - " match {exact-match-text} |\n" - " regex {search-regex}\n" - "\n" - "The regex flavor used is the C++ std::regex ECMAScript format. " - "Prefer character classes like [[:digit:]] to \\d and the like, as " - "getting the backslashes escaped through properly is error-prone."}, - {LLDB_OPT_SET_ALL, false, "live-stream", 'l', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, - "Specify whether logging events are live-streamed or buffered. " - "True indicates live streaming, false indicates buffered. The " - "default is true (live streaming). Live streaming will deliver " - "log messages with less delay, but buffered capture mode has less " - "of an observer effect."}, - {LLDB_OPT_SET_ALL, false, "no-match-accepts", 'n', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, - "Specify whether a log message that doesn't match any filter rule " - "is accepted or rejected, where true indicates accept. The " - "default is true."}, - {LLDB_OPT_SET_ALL, false, "echo-to-stderr", 'e', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, - "Specify whether os_log()/NSLog() messages are echoed to the " - "target program's stderr. When DarwinLog is enabled, we shut off " - "the mirroring of os_log()/NSLog() to the program's stderr. " - "Setting this flag to true will restore the stderr mirroring." - "The default is false."}, - {LLDB_OPT_SET_ALL, false, "broadcast-events", 'b', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, - "Specify if the plugin should broadcast events. Broadcasting " - "log events is a requirement for displaying the log entries in " - "LLDB command-line. It is also required if LLDB clients want to " - "process log events. The default is true."}, - // Message formatting options - {LLDB_OPT_SET_ALL, false, "timestamp-relative", 'r', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, - "Include timestamp in the message header when printing a log " - "message. The timestamp is relative to the first displayed " - "message."}, - {LLDB_OPT_SET_ALL, false, "subsystem", 's', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Include the subsystem in the the message header when displaying " - "a log message."}, - {LLDB_OPT_SET_ALL, false, "category", 'c', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Include the category in the the message header when displaying " - "a log message."}, - {LLDB_OPT_SET_ALL, false, "activity-chain", 'C', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Include the activity parent-child chain in the the message header " - "when displaying a log message. The activity hierarchy is " - "displayed as {grandparent-activity}:" - "{parent-activity}:{activity}[:...]."}, - {LLDB_OPT_SET_ALL, false, "all-fields", 'A', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, - "Shortcut to specify that all header fields should be displayed."}, - - // Tail sentinel entry - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; - class EnableCommand : public CommandObjectParsed { public: EnableCommand(CommandInterpreter &interpreter, bool enable, const char *name, diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 6b0e098..73f28ec 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1387,8 +1387,7 @@ static OptionDefinition g_caching_option_table[] = { "Path in which to store local copies of files."}, }; -const lldb_private::OptionDefinition * -OptionGroupPlatformRSync::GetDefinitions() { +llvm::ArrayRef OptionGroupPlatformRSync::GetDefinitions() { return g_rsync_option_table; } @@ -1431,16 +1430,12 @@ OptionGroupPlatformRSync::SetOptionValue(uint32_t option_idx, return error; } -uint32_t OptionGroupPlatformRSync::GetNumDefinitions() { - return llvm::array_lengthof(g_rsync_option_table); -} - lldb::BreakpointSP Platform::SetThreadCreationBreakpoint(lldb_private::Target &target) { return lldb::BreakpointSP(); } -const lldb_private::OptionDefinition *OptionGroupPlatformSSH::GetDefinitions() { +llvm::ArrayRef OptionGroupPlatformSSH::GetDefinitions() { return g_ssh_option_table; } @@ -1473,12 +1468,7 @@ OptionGroupPlatformSSH::SetOptionValue(uint32_t option_idx, return error; } -uint32_t OptionGroupPlatformSSH::GetNumDefinitions() { - return llvm::array_lengthof(g_ssh_option_table); -} - -const lldb_private::OptionDefinition * -OptionGroupPlatformCaching::GetDefinitions() { +llvm::ArrayRef OptionGroupPlatformCaching::GetDefinitions() { return g_caching_option_table; } @@ -1505,10 +1495,6 @@ lldb_private::Error OptionGroupPlatformCaching::SetOptionValue( return error; } -uint32_t OptionGroupPlatformCaching::GetNumDefinitions() { - return llvm::array_lengthof(g_caching_option_table); -} - size_t Platform::GetEnvironment(StringList &environment) { environment.Clear(); return false; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 7837881..458cce0 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -529,7 +529,7 @@ Error ProcessLaunchCommandOptions::SetOptionValue( return error; } -OptionDefinition ProcessLaunchCommandOptions::g_option_table[] = { +static OptionDefinition g_process_launch_options[] = { {LLDB_OPT_SET_ALL, false, "stop-at-entry", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, @@ -576,7 +576,11 @@ OptionDefinition ProcessLaunchCommandOptions::g_option_table[] = { {LLDB_OPT_SET_4, false, "shell-expand-args", 'X', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Set whether to shell expand arguments to the process when launching."}, - {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; +}; + +llvm::ArrayRef ProcessLaunchCommandOptions::GetDefinitions() { + return g_process_launch_options; +} bool ProcessInstanceInfoMatch::NameMatches(const char *process_name) const { if (m_name_match_type == eNameMatchIgnore || process_name == nullptr) -- 2.7.4