1"""Show bitfields and check that they display correctly."""
2
3import lldb
4from lldbsuite.test.decorators import *
5from lldbsuite.test.lldbtest import *
6from lldbsuite.test import lldbutil
7
8
9class CppBitfieldsTestCase(TestBase):
10
11    mydir = TestBase.compute_mydir(__file__)
12
13    def setUp(self):
14        # Call super's setUp().
15        TestBase.setUp(self)
16        # Find the line number to break inside main().
17        self.line = line_number('main.cpp', '// Set break point at this line.')
18
19    # BitFields exhibit crashes in record layout on Windows
20    # (http://llvm.org/pr21800)
21    @skipIfWindows
22    def test_and_run_command(self):
23        """Test 'frame variable ...' on a variable with bitfields."""
24        self.build()
25
26        lldbutil.run_to_source_breakpoint(self, '// Set break point at this line.',
27          lldb.SBFileSpec("main.cpp", False))
28
29        # The stop reason of the thread should be breakpoint.
30        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
31                    substrs=['stopped',
32                             'stop reason = breakpoint'])
33
34        # The breakpoint should have a hit count of 1.
35        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
36                    substrs=[' resolved, hit count = 1'])
37
38        self.expect("expr (lba.a)", VARIABLES_DISPLAYED_CORRECTLY,
39                    substrs=['unsigned int', '2'])
40        self.expect("expr (lbb.b)", VARIABLES_DISPLAYED_CORRECTLY,
41                    substrs=['unsigned int', '3'])
42        self.expect("expr (lbc.c)", VARIABLES_DISPLAYED_CORRECTLY,
43                    substrs=['unsigned int', '4'])
44        self.expect("expr (lbd.a)", VARIABLES_DISPLAYED_CORRECTLY,
45                    substrs=['unsigned int', '5'])
46        self.expect("expr (clang_example.f.a)", VARIABLES_DISPLAYED_CORRECTLY,
47                    substrs=['uint64_t', '1'])
48
49        self.expect("expr uwbf",
50            substrs=['a = 255',
51                    'b = 65535',
52                    'c = 4294967295',
53                    'x = 4294967295'] )
54
55        self.expect("expr uwubf",
56            substrs=['a = 16777215',
57                    'x = 4294967295'] )
58
59        self.expect(
60            "frame variable --show-types lba",
61            VARIABLES_DISPLAYED_CORRECTLY,
62            substrs=[
63                '(int:32)  = ',
64                '(unsigned int:20) a = 2',
65                ])
66
67        self.expect(
68            "frame variable --show-types lbb",
69            VARIABLES_DISPLAYED_CORRECTLY,
70            substrs=[
71                '(unsigned int:1) a = 1',
72                '(int:31)  =',
73                '(unsigned int:20) b = 3',
74                ])
75
76        self.expect(
77            "frame variable --show-types lbc",
78            VARIABLES_DISPLAYED_CORRECTLY,
79            substrs=[
80                '(int:22)  =',
81                '(unsigned int:1) a = 1',
82                '(unsigned int:1) b = 0',
83                '(unsigned int:5) c = 4',
84                '(unsigned int:1) d = 1',
85                '(int:2)  =',
86                '(unsigned int:20) e = 20',
87                ])
88
89        self.expect(
90            "frame variable --show-types lbd",
91            VARIABLES_DISPLAYED_CORRECTLY,
92            substrs=[
93                '(char [3]) arr = "ab"',
94                '(int:32)  =',
95                '(unsigned int:20) a = 5',
96                ])
97
98        self.expect(
99            "frame variable --show-types clang_example",
100            VARIABLES_DISPLAYED_CORRECTLY,
101            substrs=[
102                   '(int:22)  =',
103                   '(uint64_t:1) a = 1',
104                   '(uint64_t:1) b = 0',
105                   '(uint64_t:1) c = 1',
106                   '(uint64_t:1) d = 0',
107                   '(uint64_t:1) e = 1',
108                   '(uint64_t:1) f = 0',
109                   '(uint64_t:1) g = 1',
110                   '(uint64_t:1) h = 0',
111                   '(uint64_t:1) i = 1',
112                   '(uint64_t:1) j = 0',
113                   '(uint64_t:1) k = 1',
114                ])
115
116        self.expect(
117            "frame variable --show-types derived",
118            VARIABLES_DISPLAYED_CORRECTLY,
119            substrs=[
120                '(uint32_t) b_a = 2',
121                '(uint32_t:1) d_a = 1',
122                ])
123