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 def test_and_run_command(self): 20 """Test 'frame variable ...' on a variable with bitfields.""" 21 self.build() 22 23 lldbutil.run_to_source_breakpoint(self, '// Set break point at this line.', 24 lldb.SBFileSpec("main.cpp", False)) 25 26 # The stop reason of the thread should be breakpoint. 27 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 28 substrs=['stopped', 29 'stop reason = breakpoint']) 30 31 # The breakpoint should have a hit count of 1. 32 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 33 substrs=[' resolved, hit count = 1']) 34 35 self.expect("expr (lba.a)", VARIABLES_DISPLAYED_CORRECTLY, 36 substrs=['unsigned int', '2']) 37 self.expect("expr (lbb.b)", VARIABLES_DISPLAYED_CORRECTLY, 38 substrs=['unsigned int', '3']) 39 self.expect("expr (lbc.c)", VARIABLES_DISPLAYED_CORRECTLY, 40 substrs=['unsigned int', '4']) 41 self.expect("expr (lbd.a)", VARIABLES_DISPLAYED_CORRECTLY, 42 substrs=['unsigned int', '5']) 43 self.expect("expr (clang_example.f.a)", VARIABLES_DISPLAYED_CORRECTLY, 44 substrs=['uint64_t', '1']) 45 46 self.expect("expr uwbf", 47 substrs=['a = 255', 48 'b = 65535', 49 'c = 4294967295', 50 'x = 4294967295'] ) 51 52 self.expect("expr uwubf", 53 substrs=['a = 16777215', 54 'x = 4294967295'] ) 55 56 self.expect( 57 "frame variable --show-types lba", 58 VARIABLES_DISPLAYED_CORRECTLY, 59 substrs=[ 60 '(int:32) = ', 61 '(unsigned int:20) a = 2', 62 ]) 63 64 self.expect( 65 "frame variable --show-types lbb", 66 VARIABLES_DISPLAYED_CORRECTLY, 67 substrs=[ 68 '(unsigned int:1) a = 1', 69 '(int:31) =', 70 '(unsigned int:20) b = 3', 71 ]) 72 73 self.expect( 74 "frame variable --show-types lbc", 75 VARIABLES_DISPLAYED_CORRECTLY, 76 substrs=[ 77 '(int:22) =', 78 '(unsigned int:1) a = 1', 79 '(unsigned int:1) b = 0', 80 '(unsigned int:5) c = 4', 81 '(unsigned int:1) d = 1', 82 '(int:2) =', 83 '(unsigned int:20) e = 20', 84 ]) 85 86 self.expect( 87 "frame variable --show-types lbd", 88 VARIABLES_DISPLAYED_CORRECTLY, 89 substrs=[ 90 '(char [3]) arr = "ab"', 91 '(int:32) =', 92 '(unsigned int:20) a = 5', 93 ]) 94 95 self.expect( 96 "frame variable --show-types clang_example", 97 VARIABLES_DISPLAYED_CORRECTLY, 98 substrs=[ 99 '(int:22) =', 100 '(uint64_t:1) a = 1', 101 '(uint64_t:1) b = 0', 102 '(uint64_t:1) c = 1', 103 '(uint64_t:1) d = 0', 104 '(uint64_t:1) e = 1', 105 '(uint64_t:1) f = 0', 106 '(uint64_t:1) g = 1', 107 '(uint64_t:1) h = 0', 108 '(uint64_t:1) i = 1', 109 '(uint64_t:1) j = 0', 110 '(uint64_t:1) k = 1', 111 ]) 112 113 self.expect( 114 "frame variable --show-types derived", 115 VARIABLES_DISPLAYED_CORRECTLY, 116 substrs=[ 117 '(uint32_t) b_a = 2', 118 '(uint32_t:1) d_a = 1', 119 ]) 120 121 self.expect( 122 "frame variable --show-types bb", 123 VARIABLES_DISPLAYED_CORRECTLY, 124 substrs=[ 125 '(bool:1) a = true', 126 '(bool:1) b = false', 127 '(bool:2) c = true', 128 '(bool:2) d = true', 129 ]) 130 131 bb = self.frame().FindVariable('bb') 132 self.assertTrue(bb.IsValid()) 133 134 bb_a = bb.GetChildAtIndex(0) 135 self.assertTrue(bb_a.IsValid()) 136 self.assertEqual(bb_a.GetValueAsUnsigned(), 1) 137 self.assertEqual(bb_a.GetValueAsSigned(), 1) 138 139 bb_b = bb.GetChildAtIndex(1) 140 self.assertTrue(bb_b.IsValid()) 141 self.assertEqual(bb_b.GetValueAsUnsigned(), 0) 142 self.assertEqual(bb_b.GetValueAsSigned(), 0) 143 144 bb_c = bb.GetChildAtIndex(2) 145 self.assertTrue(bb_c.IsValid()) 146 self.assertEqual(bb_c.GetValueAsUnsigned(), 1) 147 self.assertEqual(bb_c.GetValueAsSigned(), 1) 148 149 bb_d = bb.GetChildAtIndex(3) 150 self.assertTrue(bb_d.IsValid()) 151 self.assertEqual(bb_d.GetValueAsUnsigned(), 1) 152 self.assertEqual(bb_d.GetValueAsSigned(), 1) 153