[Lldb-commits] [lldb] r150729 - in /lldb/trunk: source/Core/DataExtractor.cpp test/functionalities/memory/ test/functionalities/memory/read/ test/functionalities/memory/read/Makefile test/functionalities/memory/read/TestMemoryRead.py test/functionalities/memory/read/main.cpp

Johnny Chen johnny.chen at apple.com
Thu Feb 16 14:06:48 PST 2012


Author: johnny
Date: Thu Feb 16 16:06:47 2012
New Revision: 150729

URL: http://llvm.org/viewvc/llvm-project?rev=150729&view=rev
Log:
memory read prints out duplicate entries when using vector formats
DataExtractor::Dump() needs to supply the correct cursor when delegating to the child DataExtractor::Dump() calls.
Add a regression test file.
 
rdar://problem/10872908

Added:
    lldb/trunk/test/functionalities/memory/
    lldb/trunk/test/functionalities/memory/read/
    lldb/trunk/test/functionalities/memory/read/Makefile
    lldb/trunk/test/functionalities/memory/read/TestMemoryRead.py
    lldb/trunk/test/functionalities/memory/read/main.cpp
Modified:
    lldb/trunk/source/Core/DataExtractor.cpp

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=150729&r1=150728&r2=150729&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Thu Feb 16 16:06:47 2012
@@ -1768,73 +1768,73 @@
 // implementation details they should not care about ||
         case eFormatVectorOfChar:               //   ||
             s->PutChar('{');                    //   \/   
-            offset = Dump (s, start_offset, eFormatCharArray, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatCharArray, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfSInt8:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatDecimal, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatDecimal, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfUInt8:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatHex, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatHex, 1, item_byte_size, item_byte_size, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfSInt16:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatDecimal, sizeof(uint16_t), item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatDecimal, sizeof(uint16_t), item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfUInt16:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatHex,     sizeof(uint16_t), item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatHex,     sizeof(uint16_t), item_byte_size / sizeof(uint16_t), item_byte_size / sizeof(uint16_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfSInt32:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatDecimal, sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatDecimal, sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfUInt32:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatHex,     sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatHex,     sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfSInt64:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatDecimal, sizeof(uint64_t), item_byte_size / sizeof(uint64_t), item_byte_size / sizeof(uint64_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatDecimal, sizeof(uint64_t), item_byte_size / sizeof(uint64_t), item_byte_size / sizeof(uint64_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfUInt64:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatHex,     sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatHex,     sizeof(uint32_t), item_byte_size / sizeof(uint32_t), item_byte_size / sizeof(uint32_t), LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfFloat32:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatFloat,       4, item_byte_size / 4, item_byte_size / 4, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatFloat,       4, item_byte_size / 4, item_byte_size / 4, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfFloat64:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatFloat,       8, item_byte_size / 8, item_byte_size / 8, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatFloat,       8, item_byte_size / 8, item_byte_size / 8, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
 
         case eFormatVectorOfUInt128:
             s->PutChar('{');
-            offset = Dump (s, start_offset, eFormatHex, 16, item_byte_size / 16, item_byte_size / 16, LLDB_INVALID_ADDRESS, 0, 0);
+            offset = Dump (s, offset, eFormatHex, 16, item_byte_size / 16, item_byte_size / 16, LLDB_INVALID_ADDRESS, 0, 0);
             s->PutChar('}');
             break;
         }

Added: lldb/trunk/test/functionalities/memory/read/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/memory/read/Makefile?rev=150729&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/memory/read/Makefile (added)
+++ lldb/trunk/test/functionalities/memory/read/Makefile Thu Feb 16 16:06:47 2012
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/memory/read/TestMemoryRead.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/memory/read/TestMemoryRead.py?rev=150729&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/memory/read/TestMemoryRead.py (added)
+++ lldb/trunk/test/functionalities/memory/read/TestMemoryRead.py Thu Feb 16 16:06:47 2012
@@ -0,0 +1,93 @@
+"""
+Test the 'memory read' command.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class MemoryReadTestCase(TestBase):
+
+    mydir = os.path.join("functionalities", "memory", "read")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_memory_read_with_dsym(self):
+        """Test the 'memory read' command with plain and vector formats."""
+        self.buildDsym()
+        self.memory_read_command()
+
+    def test_memory_read_with_dwarf(self):
+        """Test the 'memory read' command with plain and vector formats."""
+        self.buildDwarf()
+        self.memory_read_command()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break inside main().
+        self.line = line_number('main.cpp', '// Set break point at this line.')
+
+    def memory_read_command(self):
+        """Test the 'memory read' command with plain and vector formats."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Break in main() aftre the variables are assigned values.
+        self.expect("breakpoint set -f main.cpp -l %d" % self.line,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
+                        self.line)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped', 'stop reason = breakpoint'])
+
+        # The breakpoint should have a hit count of 1.
+        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+            substrs = [' resolved, hit count = 1'])
+
+        # Test the memory read commands.
+
+        # (lldb) memory read -f d -c 1 `&argc`
+        # 0x7fff5fbff9a0: 1
+        self.runCmd("memory read -f d -c 1 `&argc`")
+
+        # Find the starting address for variable 'argc' to verify later that the
+        # '--format uint32_t[] --size 4 --count 4' option increments the address
+        # correctly.
+        line = self.res.GetOutput().splitlines()[0]
+        items = line.split(':')
+        address = int(items[0], 0)
+        argc = int(items[1], 0)
+        self.assertTrue(address > 0 and argc == 1)
+
+        # (lldb) memory read --format uint32_t[] --size 4 --count 4 `&argc`
+        # 0x7fff5fbff9a0: {0x00000001}
+        # 0x7fff5fbff9a4: {0x00000000}
+        # 0x7fff5fbff9a8: {0x0ec0bf27}
+        # 0x7fff5fbff9ac: {0x215db505}
+        self.runCmd("memory read --format uint32_t[] --size 4 --count 4 `&argc`")
+        lines = self.res.GetOutput().splitlines()
+        for i in range(4):
+            if i == 0:
+                # Verify that the printout for argc is correct.
+                self.assertTrue(argc == int(lines[i].split(':')[1].strip(' {}'), 0))
+            addr = int(lines[i].split(':')[0], 0)
+            # Verify that the printout for addr is incremented correctly.
+            self.assertTrue(addr == (address + i*4))
+
+        # (lldb) memory read --format char[] --size 7 --count 1 `&my_string`
+        # 0x7fff5fbff990: {abcdefg}
+        self.expect("memory read --format char[] --size 7 --count 1 `&my_string`",
+            substrs = ['abcdefg'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/memory/read/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/memory/read/main.cpp?rev=150729&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/memory/read/main.cpp (added)
+++ lldb/trunk/test/functionalities/memory/read/main.cpp Thu Feb 16 16:06:47 2012
@@ -0,0 +1,16 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+int main (int argc, char const *argv[])
+{
+    char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0};
+    printf("my_string=%s\n", my_string); // Set break point at this line.
+    return 0;
+}





More information about the lldb-commits mailing list