summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz
wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory')
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/TestMemoryCache.py62
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/main.cpp13
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py66
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/main.cpp16
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py133
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp20
9 files changed, 319 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/TestMemoryCache.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/TestMemoryCache.py
new file mode 100644
index 00000000000..8a1523495b4
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/TestMemoryCache.py
@@ -0,0 +1,62 @@
+"""
+Test the MemoryCache L1 flush.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class MemoryCacheTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ 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.')
+
+ @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
+ def test_memory_cache(self):
+ """Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break in main() after the variables are assigned values.
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+
+ 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'])
+
+ # Read a chunk of memory containing &my_ints[0]. The number of bytes read
+ # must be greater than m_L2_cache_line_byte_size to make sure the L1
+ # cache is used.
+ self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
+
+ # Check the value of my_ints[0] is the same as set in main.cpp.
+ line = self.res.GetOutput().splitlines()[100]
+ self.assertTrue(0x00000042 == int(line.split(':')[1], 0))
+
+ # Change the value of my_ints[0] in memory.
+ self.runCmd("memory write -s 4 `&my_ints` AA")
+
+ # Re-read the chunk of memory. The cache line should have been
+ # flushed because of the 'memory write'.
+ self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
+
+ # Check the value of my_ints[0] have been updated correctly.
+ line = self.res.GetOutput().splitlines()[100]
+ self.assertTrue(0x000000AA == int(line.split(':')[1], 0))
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/main.cpp
new file mode 100644
index 00000000000..d47107cef87
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/cache/main.cpp
@@ -0,0 +1,13 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+int main ()
+{
+ int my_ints[] = {0x42};
+ return 0; // Set break point at this line.
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py
new file mode 100644
index 00000000000..66d43665dc7
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/TestMemoryFind.py
@@ -0,0 +1,66 @@
+"""
+Test the 'memory find' command.
+"""
+
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+
+
+class MemoryFindTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line = line_number('main.cpp', '// break here')
+
+ def test_memory_find(self):
+ """Test the 'memory find' command."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break in main() after the variables are assigned values.
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+
+ 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 find commands.
+
+ self.expect(
+ 'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`',
+ substrs=[
+ 'data found at location: 0x',
+ '69 6e 20 63',
+ 'in const'])
+
+ self.expect(
+ 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
+ substrs=[
+ 'data found at location: 0x',
+ '22 33 44 55 66'])
+
+ self.expect(
+ 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[2]`',
+ substrs=['data not found within the range.'])
+
+ self.expect('memory find -s "nothere" `stringdata` `stringdata+5`',
+ substrs=['data not found within the range.'])
+
+ self.expect('memory find -s "nothere" `stringdata` `stringdata+10`',
+ substrs=['data not found within the range.'])
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/main.cpp
new file mode 100644
index 00000000000..5f4545daabd
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/find/main.cpp
@@ -0,0 +1,16 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdint.h>
+
+int main (int argc, char const *argv[])
+{
+ const char* stringdata = "hello world; I like to write text in const char pointers";
+ uint8_t bytedata[] = {0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99};
+ return 0; // break here
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py
new file mode 100644
index 00000000000..72d55dfa51f
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py
@@ -0,0 +1,133 @@
+"""
+Test the 'memory read' command.
+"""
+
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class MemoryReadTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ 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 test_memory_read(self):
+ """Test the 'memory read' command with plain and vector formats."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break in main() after the variables are assigned values.
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
+
+ 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'])
+
+ # (lldb) memory read --format 'hex float' --size 16 `&argc`
+ # 0x7fff5fbff5b0: error: unsupported byte size (16) for hex float
+ # format
+ self.expect(
+ "memory read --format 'hex float' --size 16 `&argc`",
+ substrs=['unsupported byte size (16) for hex float format'])
+
+ self.expect(
+ "memory read --format 'float' --count 1 --size 8 `&my_double`",
+ substrs=['1234.'])
+
+ # (lldb) memory read --format 'float' --count 1 --size 20 `&my_double`
+ # 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'])
+
+ # the gdb format specifier and the size in characters for
+ # the returned values including the 0x prefix.
+ variations = [['b', 4], ['h', 6], ['w', 10], ['g', 18]]
+ for v in variations:
+ formatter = v[0]
+ expected_object_length = v[1]
+ self.runCmd(
+ "memory read --gdb-format 4%s &my_uint64s" % formatter)
+ lines = self.res.GetOutput().splitlines()
+ objects_read = []
+ for l in lines:
+ objects_read.extend(l.split(':')[1].split())
+ # Check that we got back 4 0x0000 etc bytes
+ for o in objects_read:
+ self.assertTrue (len(o) == expected_object_length)
+ self.assertTrue(len(objects_read) == 4)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp
new file mode 100644
index 00000000000..3c1ab5e3f33
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/memory/read/main.cpp
@@ -0,0 +1,20 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdint.h>
+
+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};
+ uint64_t my_uint64s[] = {0, 1, 2, 3, 4, 5, 6, 7};
+ printf("my_string=%s\n", my_string); // Set break point at this line.
+ printf("my_double=%g\n", my_double);
+ return 0;
+}