1 """Show bitfields and check that they display correctly."""
4 from lldbsuite
.test
.decorators
import *
5 from lldbsuite
.test
.lldbtest
import *
6 from lldbsuite
.test
import lldbutil
9 class CppBitfieldsTestCase(TestBase
):
11 def test_bitfields(self
):
13 lldbutil
.run_to_source_breakpoint(
14 self
, "// break here", lldb
.SBFileSpec("main.cpp", False)
17 # Accessing LargeBitsA.
21 ValueCheck(name
="", type="int:32"),
22 ValueCheck(name
="a", type="unsigned int:20", value
="2"),
25 self
.expect_expr("lba.a", result_type
="unsigned int", result_value
="2")
27 # Accessing LargeBitsB.
31 ValueCheck(name
="a", type="unsigned int:1", value
="1"),
32 ValueCheck(name
="", type="int:31"),
33 ValueCheck(name
="b", type="unsigned int:20", value
="3"),
36 self
.expect_expr("lbb.b", result_type
="unsigned int", result_value
="3")
38 # Accessing LargeBitsC.
42 ValueCheck(name
="", type="int:22"),
43 ValueCheck(name
="a", type="unsigned int:1", value
="1"),
44 ValueCheck(name
="b", type="unsigned int:1", value
="0"),
45 ValueCheck(name
="c", type="unsigned int:5", value
="4"),
46 ValueCheck(name
="d", type="unsigned int:1", value
="1"),
47 ValueCheck(name
="", type="int:2"),
48 ValueCheck(name
="e", type="unsigned int:20", value
="20"),
51 self
.expect_expr("lbc.c", result_type
="unsigned int", result_value
="4")
53 # Accessing LargeBitsD.
57 ValueCheck(name
="arr", type="char[3]", summary
='"ab"'),
58 ValueCheck(name
="", type="int:32"),
59 ValueCheck(name
="a", type="unsigned int:20", value
="5"),
62 self
.expect_expr("lbd.a", result_type
="unsigned int", result_value
="5")
64 # Test BitfieldsInStructInUnion.
65 # FIXME: This needs some more explanation for what it's actually testing.
66 nested_struct_children
= [
67 ValueCheck(name
="", type="int:22"),
68 ValueCheck(name
="a", type="uint64_t:1", value
="1"),
69 ValueCheck(name
="b", type="uint64_t:1", value
="0"),
70 ValueCheck(name
="c", type="uint64_t:1", value
="1"),
71 ValueCheck(name
="d", type="uint64_t:1", value
="0"),
72 ValueCheck(name
="e", type="uint64_t:1", value
="1"),
73 ValueCheck(name
="f", type="uint64_t:1", value
="0"),
74 ValueCheck(name
="g", type="uint64_t:1", value
="1"),
75 ValueCheck(name
="h", type="uint64_t:1", value
="0"),
76 ValueCheck(name
="i", type="uint64_t:1", value
="1"),
77 ValueCheck(name
="j", type="uint64_t:1", value
="0"),
78 ValueCheck(name
="k", type="uint64_t:1", value
="1"),
81 "bitfields_in_struct_in_union",
82 result_type
="BitfieldsInStructInUnion",
86 children
=[ValueCheck(name
="f", children
=nested_struct_children
)],
91 "bitfields_in_struct_in_union.f.a", result_type
="uint64_t", result_value
="1"
94 # Unions with bitfields.
97 result_type
="UnionWithBitfields",
99 ValueCheck(name
="a", value
="255"),
100 ValueCheck(name
="b", value
="65535"),
101 ValueCheck(name
="c", value
="4294967295"),
102 ValueCheck(name
="x", value
="4294967295"),
107 result_type
="UnionWithUnnamedBitfield",
109 ValueCheck(name
="a", value
="16777215"),
110 ValueCheck(name
="x", value
="4294967295"),
114 # Class with a base class and a bitfield.
117 result_type
="Derived",
121 children
=[ValueCheck(name
="b_a", value
="2", type="uint32_t")],
123 ValueCheck(name
="d_a", value
="1", type="uint32_t:1"),
127 # Struct with bool bitfields.
132 ValueCheck(name
="a", value
="true", type="bool:1"),
133 ValueCheck(name
="b", value
="false", type="bool:1"),
134 ValueCheck(name
="c", value
="true", type="bool:2"),
135 ValueCheck(name
="d", value
="true", type="bool:2"),
139 bb
= self
.frame().FindVariable("bb")
140 self
.assertSuccess(bb
.GetError())
142 bb_a
= bb
.GetChildAtIndex(0)
143 self
.assertSuccess(bb_a
.GetError())
144 self
.assertEqual(bb_a
.GetValueAsUnsigned(), 1)
145 self
.assertEqual(bb_a
.GetValueAsSigned(), 1)
147 bb_b
= bb
.GetChildAtIndex(1)
148 self
.assertSuccess(bb_b
.GetError())
149 self
.assertEqual(bb_b
.GetValueAsUnsigned(), 0)
150 self
.assertEqual(bb_b
.GetValueAsSigned(), 0)
152 bb_c
= bb
.GetChildAtIndex(2)
153 self
.assertSuccess(bb_c
.GetError())
154 self
.assertEqual(bb_c
.GetValueAsUnsigned(), 1)
155 self
.assertEqual(bb_c
.GetValueAsSigned(), 1)
157 bb_d
= bb
.GetChildAtIndex(3)
158 self
.assertSuccess(bb_d
.GetError())
159 self
.assertEqual(bb_d
.GetValueAsUnsigned(), 1)
160 self
.assertEqual(bb_d
.GetValueAsSigned(), 1)
162 # Test a class with a base class that has a vtable ptr. The derived
163 # class has bitfields.
164 base_with_vtable_children
= [
165 ValueCheck(name
="a", type="unsigned int:4", value
="5"),
166 ValueCheck(name
="b", type="unsigned int:4", value
="0"),
167 ValueCheck(name
="c", type="unsigned int:4", value
="5"),
169 self
.expect_expr("base_with_vtable", result_children
=base_with_vtable_children
)
170 self
.expect_var_path("base_with_vtable", children
=base_with_vtable_children
)
173 def test_bitfield_behind_vtable_ptr(self
):
175 lldbutil
.run_to_source_breakpoint(
176 self
, "// break here", lldb
.SBFileSpec("main.cpp", False)
179 # Test a class with a vtable ptr and bitfields.
180 with_vtable_children
= [
181 ValueCheck(name
="a", type="unsigned int:4", value
="5"),
182 ValueCheck(name
="b", type="unsigned int:4", value
="0"),
183 ValueCheck(name
="c", type="unsigned int:4", value
="5"),
185 self
.expect_expr("with_vtable", result_children
=with_vtable_children
)
186 self
.expect_var_path("with_vtable", children
=with_vtable_children
)
188 # Test a class with a vtable ptr and unnamed bitfield directly after.
189 with_vtable_and_unnamed_children
= [
190 ValueCheck(name
="", type="int:4", value
="0"),
191 ValueCheck(name
="b", type="unsigned int:4", value
="0"),
192 ValueCheck(name
="c", type="unsigned int:4", value
="5"),
195 "with_vtable_and_unnamed", result_children
=with_vtable_and_unnamed_children
197 self
.expect_var_path(
198 "with_vtable_and_unnamed", children
=with_vtable_and_unnamed_children
201 derived_with_vtable_children
= [
204 children
=[ValueCheck(name
="b_a", value
="2", type="uint32_t")],
206 ValueCheck(name
="a", value
="1", type="unsigned int:1"),
209 "derived_with_vtable", result_children
=derived_with_vtable_children
211 self
.expect_var_path(
212 "derived_with_vtable", children
=derived_with_vtable_children