diff options
Diffstat (limited to 'lldb/source/Commands/CommandObjectMemory.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 262 |
1 files changed, 122 insertions, 140 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 1aa92fdcc84..3336bafec29 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -35,10 +35,6 @@ using namespace lldb_private; static OptionDefinition g_option_table[] = { - { LLDB_OPT_SET_1| - LLDB_OPT_SET_2, false, "size" ,'s', required_argument, NULL, 0, eArgTypeByteSize ,"The size in bytes to use when displaying with the selected format."}, - { LLDB_OPT_SET_1| - LLDB_OPT_SET_3, false, "count" ,'c', required_argument, NULL, 0, eArgTypeCount ,"The number of total items to display."}, { LLDB_OPT_SET_1, false, "num-per-line" ,'l', required_argument, NULL, 0, eArgTypeNumberPerLine ,"The number of items per line to display."}, { LLDB_OPT_SET_2, false, "binary" ,'b', no_argument , NULL, 0, eArgTypeNone ,"If true, memory will be saved as binary. If false, the memory is saved save as an ASCII dump that uses the format, size, count and number per line settings."}, { LLDB_OPT_SET_3, true , "view-as" ,'t', required_argument, NULL, 0, eArgTypeNone ,"The name of a type to view memory as."}, @@ -51,8 +47,6 @@ class OptionGroupReadMemory : public OptionGroup public: OptionGroupReadMemory () : - m_byte_size (1,1), - m_count (8,8), m_num_per_line (1,1), m_output_as_binary (false), m_view_as_type() @@ -92,19 +86,7 @@ public: if (m_num_per_line.GetCurrentValue() == 0) error.SetErrorStringWithFormat("Invalid value for --num-per-line option '%s'. Must be positive integer value.\n", option_arg); break; - - case 'c': - error = m_count.SetValueFromCString (option_arg); - if (m_count.GetCurrentValue() == 0) - error.SetErrorStringWithFormat("Invalid value for --count option '%s'. Must be positive integer value.\n", option_arg); - break; - - case 's': - error = m_byte_size.SetValueFromCString (option_arg); - if (m_byte_size.GetCurrentValue() == 0) - error.SetErrorStringWithFormat("Invalid value for --size option '%s'. Must be positive integer value.\n", option_arg); - break; - + case 'b': m_output_as_binary = true; break; @@ -123,22 +105,22 @@ public: virtual void OptionParsingStarting (CommandInterpreter &interpreter) { - m_byte_size.Clear(); - m_count.Clear(); m_num_per_line.Clear(); m_output_as_binary = false; m_view_as_type.Clear(); } Error - FinalizeSettings (Target *target, const OptionGroupFormat& format_options) + FinalizeSettings (Target *target, OptionGroupFormat& format_options) { Error error; - bool byte_size_option_set = m_byte_size.OptionWasSet(); + OptionValueUInt64 &byte_size_value = format_options.GetByteSizeValue(); + OptionValueUInt64 &count_value = format_options.GetCountValue(); + bool byte_size_option_set = byte_size_value.OptionWasSet(); const bool num_per_line_option_set = m_num_per_line.OptionWasSet(); - const bool count_option_set = m_count.OptionWasSet(); + const bool count_option_set = format_options.GetCountValue().OptionWasSet(); - uint32_t format_byte_size = format_options.GetByteSize(); + uint32_t format_byte_size = byte_size_value.GetCurrentValue(); if (byte_size_option_set) { if (format_byte_size > 0) @@ -152,7 +134,7 @@ public: if (format_byte_size != 0) { byte_size_option_set = true; - m_byte_size = format_byte_size; + byte_size_value = format_byte_size; } } @@ -163,22 +145,22 @@ public: case eFormatBoolean: if (!byte_size_option_set) - m_byte_size = 1; + byte_size_value = 1; if (!num_per_line_option_set) m_num_per_line = 1; if (!count_option_set) - m_count = 8; + format_options.GetCountValue() = 8; break; case eFormatCString: break; case eFormatPointer: - m_byte_size = target->GetArchitecture().GetAddressByteSize(); + byte_size_value = target->GetArchitecture().GetAddressByteSize(); if (!num_per_line_option_set) m_num_per_line = 4; if (!count_option_set) - m_count = 8; + format_options.GetCountValue() = 8; break; case eFormatBinary: @@ -190,51 +172,51 @@ public: case eFormatUnicode32: case eFormatUnsigned: if (!byte_size_option_set) - m_byte_size = 4; + byte_size_value = 4; if (!num_per_line_option_set) m_num_per_line = 1; if (!count_option_set) - m_count = 8; + format_options.GetCountValue() = 8; break; case eFormatBytes: case eFormatBytesWithASCII: - if (m_byte_size.OptionWasSet()) + if (byte_size_value.OptionWasSet()) { - if (m_byte_size > 1) + if (byte_size_value > 1) error.SetErrorString ("use --count option to specify an end address to display a number of bytes"); } else - m_byte_size = 1; + byte_size_value = 1; if (!num_per_line_option_set) m_num_per_line = 16; if (!count_option_set) - m_count = 32; + format_options.GetCountValue() = 32; break; case eFormatCharArray: case eFormatChar: case eFormatCharPrintable: if (!byte_size_option_set) - m_byte_size = 1; + byte_size_value = 1; if (!num_per_line_option_set) m_num_per_line = 32; if (!count_option_set) - m_count = 64; + format_options.GetCountValue() = 64; break; case eFormatComplex: if (!byte_size_option_set) - m_byte_size = 8; + byte_size_value = 8; if (!num_per_line_option_set) m_num_per_line = 1; if (!count_option_set) - m_count = 8; + format_options.GetCountValue() = 8; break; case eFormatHex: if (!byte_size_option_set) - m_byte_size = 4; + byte_size_value = 4; if (!num_per_line_option_set) { - switch (m_byte_size) + switch (byte_size_value) { case 1: case 2: @@ -252,7 +234,7 @@ public: } } if (!count_option_set) - m_count = 8; + count_value = 8; break; case eFormatVectorOfChar: @@ -268,18 +250,16 @@ public: case eFormatVectorOfFloat64: case eFormatVectorOfUInt128: if (!byte_size_option_set) - m_byte_size = 128; + byte_size_value = 128; if (!num_per_line_option_set) m_num_per_line = 1; if (!count_option_set) - m_count = 4; + count_value = 4; break; } return error; } - OptionValueUInt64 m_byte_size; - OptionValueUInt64 m_count; OptionValueUInt64 m_num_per_line; bool m_output_as_binary; OptionValueString m_view_as_type; @@ -301,7 +281,7 @@ public: NULL, eFlagProcessMustBePaused), m_option_group (interpreter), - m_format_options (eFormatBytesWithASCII, 0, true), + m_format_options (eFormatBytesWithASCII, 1, 8), m_memory_options (), m_outfile_options (), m_varobj_options() @@ -329,7 +309,14 @@ public: m_arguments.push_back (arg1); m_arguments.push_back (arg2); - m_option_group.Append (&m_format_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_3); + // Add the "--format" and "--count" options to group 1 and 3 + m_option_group.Append (&m_format_options, + OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_COUNT, + LLDB_OPT_SET_1 | LLDB_OPT_SET_3); + // Add the "--size" option to group 1 and 2 + m_option_group.Append (&m_format_options, + OptionGroupFormat::OPTION_GROUP_SIZE, + LLDB_OPT_SET_1 | LLDB_OPT_SET_2); m_option_group.Append (&m_memory_options); m_option_group.Append (&m_outfile_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3); m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3); @@ -491,9 +478,9 @@ public: --pointer_count; } - m_memory_options.m_byte_size = (clang_ast_type.GetClangTypeBitWidth () + 7) / 8; + m_format_options.GetByteSizeValue() = (clang_ast_type.GetClangTypeBitWidth () + 7) / 8; - if (m_memory_options.m_byte_size == 0) + if (m_format_options.GetByteSizeValue() == 0) { result.AppendErrorWithFormat ("unable to get the byte size of the type '%s'\n", view_as_type_cstr); @@ -501,8 +488,8 @@ public: return false; } - if (!m_memory_options.m_count.OptionWasSet()) - m_memory_options.m_count = 1; + if (!m_format_options.GetCountValue().OptionWasSet()) + m_format_options.GetCountValue() = 1; } else { @@ -517,8 +504,8 @@ public: return false; } - size_t item_count = m_memory_options.m_count.GetCurrentValue(); - const size_t item_byte_size = m_memory_options.m_byte_size; + size_t item_count = m_format_options.GetCountValue().GetCurrentValue(); + const size_t item_byte_size = m_format_options.GetByteSizeValue().GetCurrentValue(); const size_t num_per_line = m_memory_options.m_num_per_line.GetCurrentValue(); size_t total_byte_size = item_count * item_byte_size; @@ -549,7 +536,7 @@ public: result.SetStatus(eReturnStatusFailed); return false; } - else if (m_memory_options.m_count.OptionWasSet()) + else if (m_format_options.GetCountValue().OptionWasSet()) { result.AppendErrorWithFormat("specify either the end address (0x%llx) or the count (--count %lu), not both.\n", end_addr, item_count); result.SetStatus(eReturnStatusFailed); @@ -708,6 +695,15 @@ protected: }; + +OptionDefinition +g_memory_write_option_table[] = +{ +{ LLDB_OPT_SET_1, true, "infile", 'i', required_argument, NULL, 0, eArgTypeFilename, "Write memory using the contents of a file."}, +{ LLDB_OPT_SET_1, false, "offset", 'o', required_argument, NULL, 0, eArgTypeOffset, "Start writng bytes from an offset within the input file."}, +}; + + //---------------------------------------------------------------------- // Write memory to the inferior process //---------------------------------------------------------------------- @@ -715,86 +711,75 @@ class CommandObjectMemoryWrite : public CommandObject { public: - class CommandOptions : public Options + class OptionGroupWriteMemory : public OptionGroup { public: - CommandOptions (CommandInterpreter &interpreter) : - Options(interpreter) + OptionGroupWriteMemory () : + OptionGroup() { - OptionParsingStarting(); } virtual - ~CommandOptions () + ~OptionGroupWriteMemory () { } + virtual uint32_t + GetNumDefinitions () + { + return sizeof (g_memory_write_option_table) / sizeof (OptionDefinition); + } + + virtual const OptionDefinition* + GetDefinitions () + { + return g_memory_write_option_table; + } + virtual Error - SetOptionValue (uint32_t option_idx, const char *option_arg) + SetOptionValue (CommandInterpreter &interpreter, + uint32_t option_idx, + const char *option_arg) { Error error; - char short_option = (char) m_getopt_table[option_idx].val; + char short_option = (char) g_memory_write_option_table[option_idx].short_option; + switch (short_option) { - case 'f': - error = Args::StringToFormat (option_arg, m_format, &m_byte_size); - break; - - case 's': - m_byte_size = Args::StringToUInt32 (option_arg, 0); - if (m_byte_size == 0) - error.SetErrorStringWithFormat("Invalid value for --size option '%s'. Must be positive integer value.\n", option_arg); - break; - - case 'i': - m_infile.SetFile (option_arg, true); - if (!m_infile.Exists()) - { - m_infile.Clear(); - error.SetErrorStringWithFormat("Input file does not exist: '%s'\n", option_arg); - } - break; - - case 'o': - { - bool success; - m_infile_offset = Args::StringToUInt64(option_arg, 0, 0, &success); - if (!success) + case 'i': + m_infile.SetFile (option_arg, true); + if (!m_infile.Exists()) { - error.SetErrorStringWithFormat("Invalid offset string '%s'\n", option_arg); + m_infile.Clear(); + error.SetErrorStringWithFormat("Input file does not exist: '%s'\n", option_arg); } - } - break; - - default: - error.SetErrorStringWithFormat("Unrecognized short option '%c'\n", short_option); - break; + break; + + case 'o': + { + bool success; + m_infile_offset = Args::StringToUInt64(option_arg, 0, 0, &success); + if (!success) + { + error.SetErrorStringWithFormat("Invalid offset string '%s'\n", option_arg); + } + } + break; + + default: + error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option); + break; } return error; } - - void - OptionParsingStarting () + + virtual void + OptionParsingStarting (CommandInterpreter &interpreter) { - m_format = eFormatBytes; - m_byte_size = 1; m_infile.Clear(); m_infile_offset = 0; } - const OptionDefinition* - GetDefinitions () - { - return g_option_table; - } - - // Options table: Required for subclasses of Options. - - static OptionDefinition g_option_table[]; - - // Instance variables to hold the values for command options. - lldb::Format m_format; - uint32_t m_byte_size; FileSpec m_infile; off_t m_infile_offset; }; @@ -806,7 +791,9 @@ public: //"memory write [<cmd-options>] <addr> [value1 value2 ...]", NULL, eFlagProcessMustBeLaunched), - m_options (interpreter) + m_option_group (interpreter), + m_format_options (eFormatBytes, 1, UINT64_MAX), + m_memory_options () { CommandArgumentEntry arg1; CommandArgumentEntry arg2; @@ -830,6 +817,12 @@ public: // Push the data for the first argument into the m_arguments vector. m_arguments.push_back (arg1); m_arguments.push_back (arg2); + + m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1); + m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_SIZE , LLDB_OPT_SET_1|LLDB_OPT_SET_2); + m_option_group.Append (&m_memory_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_2); + m_option_group.Finalize(); + } virtual @@ -840,7 +833,7 @@ public: Options * GetOptions () { - return &m_options; + return &m_option_group; } bool @@ -884,7 +877,7 @@ public: const size_t argc = command.GetArgumentCount(); - if (m_options.m_infile) + if (m_memory_options.m_infile) { if (argc < 1) { @@ -904,7 +897,8 @@ public: process->GetTarget().GetArchitecture().GetAddressByteSize(), process->GetTarget().GetArchitecture().GetByteOrder()); - size_t item_byte_size = m_options.m_byte_size; + OptionValueUInt64 &byte_size_value = m_format_options.GetByteSizeValue(); + size_t item_byte_size = byte_size_value.GetCurrentValue(); lldb::addr_t addr = Args::StringToUInt64(command.GetArgumentAtIndex(0), LLDB_INVALID_ADDRESS, 0); @@ -915,12 +909,12 @@ public: return false; } - if (m_options.m_infile) + if (m_memory_options.m_infile) { size_t length = SIZE_MAX; - if (m_options.m_byte_size > 0) - length = m_options.m_byte_size; - lldb::DataBufferSP data_sp (m_options.m_infile.ReadFileContents (m_options.m_infile_offset, length)); + if (item_byte_size > 0) + length = item_byte_size; + lldb::DataBufferSP data_sp (m_memory_options.m_infile.ReadFileContents (m_memory_options.m_infile_offset, length)); if (data_sp) { length = data_sp->GetByteSize(); @@ -955,9 +949,9 @@ public: } return result.Succeeded(); } - else if (m_options.m_byte_size == 0) + else if (item_byte_size == 0) { - if (m_options.m_format == eFormatPointer) + if (m_format_options.GetFormat() == eFormatPointer) item_byte_size = buffer.GetAddressByteSize(); else item_byte_size = 1; @@ -973,7 +967,7 @@ public: { const char *value_str = command.GetArgumentAtIndex(i); - switch (m_options.m_format) + switch (m_format_options.GetFormat()) { case kNumFormats: case eFormatFloat: // TODO: add support for floats soon @@ -1058,7 +1052,7 @@ public: { size_t len = strlen (value_str); // Include the NULL for C strings... - if (m_options.m_format == eFormatCString) + if (m_format_options.GetFormat() == eFormatCString) ++len; Error error; if (process->WriteMemory (addr, value_str, len, error) == len) @@ -1143,24 +1137,12 @@ public: } protected: - CommandOptions m_options; -}; - -#define SET1 LLDB_OPT_SET_1 -#define SET2 LLDB_OPT_SET_2 - -OptionDefinition -CommandObjectMemoryWrite::CommandOptions::g_option_table[] = -{ -{ SET1 , false, "format", 'f', required_argument, NULL, 0, eArgTypeFormat, "The format value types that will be decoded and written to memory."}, -{ SET1 | SET2, false, "size", 's', required_argument, NULL, 0, eArgTypeByteSize, "The size in bytes of the values to write to memory."}, -{ SET2, true, "infile", 'i', required_argument, NULL, 0, eArgTypeFilename, "Write memory using the contents of a file."}, -{ SET2, false, "offset", 'o', required_argument, NULL, 0, eArgTypeOffset, "Start writng bytes from an offset within the input file."}, -{ 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone, NULL } + + OptionGroupOptions m_option_group; + OptionGroupFormat m_format_options; + OptionGroupWriteMemory m_memory_options; }; -#undef SET1 -#undef SET2 //------------------------------------------------------------------------- // CommandObjectMemory |