2 Test the 'memory read' command.
5 from __future__ import print_function
12 from lldbsuite.test.lldbtest import *
13 import lldbsuite.test.lldbutil as lldbutil
15 class MemoryReadTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Find the line number to break inside main().
23 self.line = line_number('main.cpp', '// Set break point at this line.')
25 def test_memory_read(self):
26 """Test the 'memory read' command with plain and vector formats."""
28 exe = os.path.join(os.getcwd(), "a.out")
29 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
31 # Break in main() aftre the variables are assigned values.
32 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
34 self.runCmd("run", RUN_SUCCEEDED)
36 # The stop reason of the thread should be breakpoint.
37 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38 substrs = ['stopped', 'stop reason = breakpoint'])
40 # The breakpoint should have a hit count of 1.
41 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
42 substrs = [' resolved, hit count = 1'])
44 # Test the memory read commands.
46 # (lldb) memory read -f d -c 1 `&argc`
48 self.runCmd("memory read -f d -c 1 `&argc`")
50 # Find the starting address for variable 'argc' to verify later that the
51 # '--format uint32_t[] --size 4 --count 4' option increments the address
53 line = self.res.GetOutput().splitlines()[0]
54 items = line.split(':')
55 address = int(items[0], 0)
56 argc = int(items[1], 0)
57 self.assertTrue(address > 0 and argc == 1)
59 # (lldb) memory read --format uint32_t[] --size 4 --count 4 `&argc`
60 # 0x7fff5fbff9a0: {0x00000001}
61 # 0x7fff5fbff9a4: {0x00000000}
62 # 0x7fff5fbff9a8: {0x0ec0bf27}
63 # 0x7fff5fbff9ac: {0x215db505}
64 self.runCmd("memory read --format uint32_t[] --size 4 --count 4 `&argc`")
65 lines = self.res.GetOutput().splitlines()
68 # Verify that the printout for argc is correct.
69 self.assertTrue(argc == int(lines[i].split(':')[1].strip(' {}'), 0))
70 addr = int(lines[i].split(':')[0], 0)
71 # Verify that the printout for addr is incremented correctly.
72 self.assertTrue(addr == (address + i*4))
74 # (lldb) memory read --format char[] --size 7 --count 1 `&my_string`
75 # 0x7fff5fbff990: {abcdefg}
76 self.expect("memory read --format char[] --size 7 --count 1 `&my_string`",
77 substrs = ['abcdefg'])
79 # (lldb) memory read --format 'hex float' --size 16 `&argc`
80 # 0x7fff5fbff5b0: error: unsupported byte size (16) for hex float format
81 self.expect("memory read --format 'hex float' --size 16 `&argc`",
82 substrs = ['unsupported byte size (16) for hex float format'])
84 self.expect("memory read --format 'float' --count 1 --size 8 `&my_double`",
87 # (lldb) memory read --format 'float' --count 1 --size 20 `&my_double`
88 # 0x7fff5fbff598: error: unsupported byte size (20) for float format
89 self.expect("memory read --format 'float' --count 1 --size 20 `&my_double`",
90 substrs = ['unsupported byte size (20) for float format'])
92 self.expect('memory read --type int --count 5 `&my_ints[0]`',
93 substrs=['(int) 0x', '2','4','6','8','10'])
95 self.expect('memory read --type int --count 5 --format hex `&my_ints[0]`',
96 substrs=['(int) 0x', '0x','0a'])
98 self.expect('memory read --type int --count 5 --offset 5 `&my_ints[0]`',
99 substrs=['(int) 0x', '12', '14','16','18', '20'])