diff options
author | Zachary Turner <zturner@google.com> | 2016-09-22 20:22:55 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-09-22 20:22:55 +0000 |
commit | 1f0f5b5b9eeaea93126583b40070091baf3bc92d (patch) | |
tree | 93be6068ce5a7314fb9bfdf0621f65c03b3cad0b /lldb/source/Commands/CommandObjectPlatform.cpp | |
parent | 387eb83a509926ed6bd36591d1f235335ec215c0 (diff) | |
download | bcm5719-llvm-1f0f5b5b9eeaea93126583b40070091baf3bc92d.tar.gz bcm5719-llvm-1f0f5b5b9eeaea93126583b40070091baf3bc92d.zip |
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<OptionDefinition>`
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
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectPlatform.cpp | 165 |
1 files changed, 74 insertions, 91 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 295f4c7133c..db3e2aba9dc 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<OptionDefinition> 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<OptionDefinition> 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<OptionDefinition> 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<OptionDefinition> + 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<OptionDefinition> 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 <process-name> 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<OptionDefinition> 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 <process-name> 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<OptionDefinition> 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 //---------------------------------------------------------------------- |