diff options
author | Greg Clayton <gclayton@apple.com> | 2011-10-25 06:44:01 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2011-10-25 06:44:01 +0000 |
commit | 1deb79623896414dae71b7827de8c9ba2eb3bdd9 (patch) | |
tree | 47b4b9f36f0aaa3392665144a0c2ee28f947522f /lldb/source/Commands/CommandObjectRegister.cpp | |
parent | d4268d91e7f1df42776a8e1994c7415fc04d7571 (diff) | |
download | bcm5719-llvm-1deb79623896414dae71b7827de8c9ba2eb3bdd9.tar.gz bcm5719-llvm-1deb79623896414dae71b7827de8c9ba2eb3bdd9.zip |
Updated all commands that use a "--format" / "-f" options to use the new
OptionGroupFormat. Updated OptionGroupFormat to be able to also use the
"--size" and "--count" options. Commands that use a OptionGroupFormat instance
can choose which of the options they want by initializing OptionGroupFormat
accordingly. Clients can either get only the "--format", "--format" + "--size",
or "--format" + "--size" + "--count". This is in preparation for upcoming
chnages where there are alternate ways (GDB format specification) to set a
format.
llvm-svn: 142911
Diffstat (limited to 'lldb/source/Commands/CommandObjectRegister.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectRegister.cpp | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 73c9c8b8b9b..253aece718f 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -22,6 +22,7 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/NamedOptionValue.h" #include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionGroupFormat.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" @@ -43,7 +44,9 @@ public: //"register read [<reg-name1> [<reg-name2> [...]]]", NULL, eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), - m_options (interpreter) + m_option_group (interpreter), + m_format_options (eFormatDefault), + m_command_options () { CommandArgumentEntry arg; CommandArgumentData register_arg; @@ -57,6 +60,12 @@ public: // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg); + + // Add the "--format" + m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_ALL); + m_option_group.Append (&m_command_options); + m_option_group.Finalize(); + } virtual @@ -67,7 +76,7 @@ public: Options * GetOptions () { - return &m_options; + return &m_option_group; } bool @@ -83,15 +92,10 @@ public: if (reg_ctx->ReadRegister (reg_info, reg_value)) { strm.Indent (); - Format format; - if (m_options.format == eFormatDefault) - format = reg_info->format; - else - format = m_options.format; - bool prefix_with_altname = m_options.alternate_name; + bool prefix_with_altname = m_command_options.alternate_name; bool prefix_with_name = !prefix_with_altname; - reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname, m_options.format); + reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat()); if (((reg_info->encoding == eEncodingUint) || (reg_info->encoding == eEncodingSint)) && (reg_info->byte_size == reg_ctx->GetThread().GetProcess().GetAddressByteSize())) { @@ -165,12 +169,12 @@ public: uint32_t set_idx; uint32_t num_register_sets = 1; - const uint32_t set_array_size = m_options.set_indexes.GetSize(); + const uint32_t set_array_size = m_command_options.set_indexes.GetSize(); if (set_array_size > 0) { for (uint32_t i=0; i<set_array_size; ++i) { - set_idx = m_options.set_indexes[i]->GetUInt64Value (UINT32_MAX, NULL); + set_idx = m_command_options.set_indexes[i]->GetUInt64Value (UINT32_MAX, NULL); if (set_idx != UINT32_MAX) { if (!DumpRegisterSet (exe_ctx, strm, reg_ctx, set_idx)) @@ -190,7 +194,7 @@ public: } else { - if (m_options.dump_all_sets) + if (m_command_options.dump_all_sets) num_register_sets = reg_ctx->GetRegisterSetCount(); for (set_idx = 0; set_idx < num_register_sets; ++set_idx) @@ -201,12 +205,12 @@ public: } else { - if (m_options.dump_all_sets) + if (m_command_options.dump_all_sets) { result.AppendError ("the --all option can't be used when registers names are supplied as arguments\n"); result.SetStatus (eReturnStatusFailed); } - else if (m_options.set_indexes.GetSize() > 0) + else if (m_command_options.set_indexes.GetSize() > 0) { result.AppendError ("the --set <set> option can't be used when registers names are supplied as arguments\n"); result.SetStatus (eReturnStatusFailed); @@ -239,17 +243,15 @@ public: return result.Succeeded(); } -protected: - class CommandOptions : public Options + class CommandOptions : public OptionGroup { public: - CommandOptions (CommandInterpreter &interpreter) : - Options(interpreter), + CommandOptions () : + OptionGroup(), set_indexes (OptionValue::ConvertTypeToMask (OptionValue::eTypeUInt64)), dump_all_sets (false, false), // Initial and default values are false alternate_name (false, false) { - OptionParsingStarting(); } virtual @@ -257,20 +259,36 @@ protected: { } + + virtual uint32_t + GetNumDefinitions (); + + virtual const OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter) + { + set_indexes.Clear(); + dump_all_sets.Clear(); + alternate_name.Clear(); + } + virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg) + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_value) { Error error; - char short_option = (char) m_getopt_table[option_idx].val; + const char short_option = (char) g_option_table[option_idx].short_option; switch (short_option) { - case 'f': - error = Args::StringToFormat (option_arg, format, NULL); - break; - case 's': { - OptionValueSP value_sp (OptionValueUInt64::Create (option_arg, error)); + OptionValueSP value_sp (OptionValueUInt64::Create (option_value, error)); if (value_sp) set_indexes.AppendValue (value_sp); } @@ -299,45 +317,34 @@ protected: return error; } - void - OptionParsingStarting () - { - format = eFormatDefault; - set_indexes.Clear(); - dump_all_sets.Clear(); - alternate_name.Clear(); - } - - const OptionDefinition* - GetDefinitions () - { - return g_option_table; - } - // Options table: Required for subclasses of Options. - static OptionDefinition g_option_table[]; + static const OptionDefinition g_option_table[]; // Instance variables to hold the values for command options. - lldb::Format format; OptionValueArray set_indexes; OptionValueBoolean dump_all_sets; OptionValueBoolean alternate_name; }; - CommandOptions m_options; + OptionGroupOptions m_option_group; + OptionGroupFormat m_format_options; + CommandOptions m_command_options; }; OptionDefinition CommandObjectRegisterRead::CommandOptions::g_option_table[] = { - { LLDB_OPT_SET_ALL, false, "format" , 'f', required_argument, NULL, 0, eArgTypeExprFormat, "Specify the format to use when dumping register values."}, { LLDB_OPT_SET_ALL, false, "alternate", 'A', no_argument , NULL, 0, eArgTypeNone , "Display register names using the alternate register name if there is one."}, { LLDB_OPT_SET_1 , false, "set" , 's', required_argument, NULL, 0, eArgTypeIndex , "Specify which register sets to dump by index."}, { LLDB_OPT_SET_2 , false, "all" , 'a', no_argument , NULL, 0, eArgTypeNone , "Show all register sets."}, - { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL } }; +uint32_t +CommandObjectRegisterRead::CommandOptions::GetNumDefinitions () +{ + return sizeof(g_option_table)/sizeof(OptionDefinition); +} //---------------------------------------------------------------------- @@ -350,7 +357,6 @@ public: CommandObject (interpreter, "register write", "Modify a single register value.", - //"register write <reg-name> <value>", NULL, eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) { |