[Lldb-commits] [lldb] r251668 - 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

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 29 16:40:24 PDT 2015


Author: enrico
Date: Thu Oct 29 18:40:24 2015
New Revision: 251668

URL: http://llvm.org/viewvc/llvm-project?rev=251668&view=rev
Log:
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

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp
    lldb/trunk/source/Commands/CommandObjectMemory.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py?rev=251668&r1=251667&r2=251668&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py Thu Oct 29 18:40:24 2015
@@ -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'])

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp?rev=251668&r1=251667&r2=251668&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp Thu Oct 29 18:40:24 2015
@@ -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;

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=251668&r1=251667&r2=251668&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Thu Oct 29 18:40:24 2015
@@ -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)
         {




More information about the lldb-commits mailing list