]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/memory/read/TestMemoryRead.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / memory / read / TestMemoryRead.py
1 """
2 Test the 'memory read' command.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import re
11 import lldb
12 from lldbsuite.test.lldbtest import *
13 import lldbsuite.test.lldbutil as lldbutil
14
15 class MemoryReadTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Find the line number to break inside main().
23         self.line = line_number('main.cpp', '// Set break point at this line.')
24
25     def test_memory_read(self):
26         """Test the 'memory read' command with plain and vector formats."""
27         self.build()
28         exe = os.path.join(os.getcwd(), "a.out")
29         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
30
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)
33
34         self.runCmd("run", RUN_SUCCEEDED)
35
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'])
39
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'])
43
44         # Test the memory read commands.
45
46         # (lldb) memory read -f d -c 1 `&argc`
47         # 0x7fff5fbff9a0: 1
48         self.runCmd("memory read -f d -c 1 `&argc`")
49
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
52         # correctly.
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)
58
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()
66         for i in range(4):
67             if i == 0:
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))
73
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'])
78
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'])
83
84         self.expect("memory read --format 'float' --count 1 --size 8 `&my_double`",
85             substrs = ['1234.'])
86
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'])
91
92         self.expect('memory read --type int --count 5 `&my_ints[0]`',
93             substrs=['(int) 0x', '2','4','6','8','10'])
94
95         self.expect('memory read --type int --count 5 --format hex `&my_ints[0]`',
96             substrs=['(int) 0x', '0x','0a'])
97
98         self.expect('memory read --type int --count 5 --offset 5 `&my_ints[0]`',
99             substrs=['(int) 0x', '12', '14','16','18', '20'])