From 7a33621fa576cfd75864dbacef3391e1aa9cca28 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Thu, 29 Oct 2015 23:40:24 +0000 Subject: [PATCH] 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 --- .../memory/read/TestMemoryRead.py | 9 +++++++++ .../test/functionalities/memory/read/main.cpp | 1 + lldb/source/Commands/CommandObjectMemory.cpp | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py b/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py index 085c9bdd9890..4fa570fc13af 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py @@ -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']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp index b4d7809d27c1..cd367ff318ab 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp @@ -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; diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index f91a6be6d79b..2be7918a4b93 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -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) {