Add a --offset option to memory read that allows one to specify, given a type, how many sizeof(type) bytes to speak before starting to read memory

llvm-svn: 251668
This commit is contained in:
Enrico Granata 2015-10-29 23:40:24 +00:00
parent bcfd1f0c56
commit 7a33621fa5
3 changed files with 24 additions and 2 deletions

View File

@ -89,3 +89,12 @@ class MemoryReadTestCase(TestBase):
# 0x7fff5fbff598: error: unsupported byte size (20) for float format
self.expect("memory read --format 'float' --count 1 --size 20 `&my_double`",
substrs = ['unsupported byte size (20) for float format'])
self.expect('memory read --type int --count 5 `&my_ints[0]`',
substrs=['(int) 0x', '2','4','6','8','10'])
self.expect('memory read --type int --count 5 --format hex `&my_ints[0]`',
substrs=['(int) 0x', '0x','0a'])
self.expect('memory read --type int --count 5 --offset 5 `&my_ints[0]`',
substrs=['(int) 0x', '12', '14','16','18', '20'])

View File

@ -12,6 +12,7 @@ int main (int argc, char const *argv[])
{
char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0};
double my_double = 1234.5678;
int my_ints[] = {2,4,6,8,10,12,14,16,18,20,22};
printf("my_string=%s\n", my_string); // Set break point at this line.
printf("my_double=%g\n", my_double);
return 0;

View File

@ -49,6 +49,7 @@ g_option_table[] =
{ LLDB_OPT_SET_1, false, "num-per-line" ,'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeNumberPerLine ,"The number of items per line to display."},
{ LLDB_OPT_SET_2, false, "binary" ,'b', OptionParser::eNoArgument , NULL, 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 , "type" ,'t', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeNone ,"The name of a type to view memory as."},
{ LLDB_OPT_SET_3, false , "offset" ,'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount ,"How many elements of the specified type to skip before starting to display data."},
{ LLDB_OPT_SET_1|
LLDB_OPT_SET_2|
LLDB_OPT_SET_3, false, "force" ,'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone ,"Necessary if reading over target.max-memory-read-size bytes."},
@ -63,7 +64,8 @@ public:
OptionGroupReadMemory () :
m_num_per_line (1,1),
m_output_as_binary (false),
m_view_as_type()
m_view_as_type(),
m_offset(0,0)
{
}
@ -112,6 +114,10 @@ public:
m_force = true;
break;
case 'o':
error = m_offset.SetValueFromString(option_arg);
break;
default:
error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
break;
@ -126,6 +132,7 @@ public:
m_output_as_binary = false;
m_view_as_type.Clear();
m_force = false;
m_offset.Clear();
}
Error
@ -291,13 +298,15 @@ public:
{
return m_num_per_line.OptionWasSet() ||
m_output_as_binary ||
m_view_as_type.OptionWasSet();
m_view_as_type.OptionWasSet() ||
m_offset.OptionWasSet();
}
OptionValueUInt64 m_num_per_line;
bool m_output_as_binary;
OptionValueString m_view_as_type;
bool m_force;
OptionValueUInt64 m_offset;
};
@ -697,6 +706,9 @@ protected:
m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault);
bytes_read = clang_ast_type.GetByteSize(nullptr) * m_format_options.GetCountValue().GetCurrentValue();
if (argc > 0)
addr = addr + (clang_ast_type.GetByteSize(nullptr) * m_memory_options.m_offset.GetCurrentValue());
}
else if (m_format_options.GetFormatValue().GetCurrentValue() != eFormatCString)
{