1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
"""Show bitfields and check that they display correctly."""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class CppBitfieldsTestCase(TestBase):
@no_debug_info_test
def test_bitfields(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)
# Accessing LargeBitsA.
self.expect_expr(
"lba",
result_children=[
ValueCheck(name="", type="int:32"),
ValueCheck(name="a", type="unsigned int:20", value="2"),
],
)
self.expect_expr("lba.a", result_type="unsigned int", result_value="2")
# Accessing LargeBitsB.
self.expect_expr(
"lbb",
result_children=[
ValueCheck(name="a", type="unsigned int:1", value="1"),
ValueCheck(name="", type="int:31"),
ValueCheck(name="b", type="unsigned int:20", value="3"),
],
)
self.expect_expr("lbb.b", result_type="unsigned int", result_value="3")
# Accessing LargeBitsC.
self.expect_expr(
"lbc",
result_children=[
ValueCheck(name="", type="int:22"),
ValueCheck(name="a", type="unsigned int:1", value="1"),
ValueCheck(name="b", type="unsigned int:1", value="0"),
ValueCheck(name="c", type="unsigned int:5", value="4"),
ValueCheck(name="d", type="unsigned int:1", value="1"),
ValueCheck(name="", type="int:2"),
ValueCheck(name="e", type="unsigned int:20", value="20"),
],
)
self.expect_expr("lbc.c", result_type="unsigned int", result_value="4")
# Accessing LargeBitsD.
self.expect_expr(
"lbd",
result_children=[
ValueCheck(name="arr", type="char[3]", summary='"ab"'),
ValueCheck(name="", type="int:32"),
ValueCheck(name="a", type="unsigned int:20", value="5"),
],
)
self.expect_expr("lbd.a", result_type="unsigned int", result_value="5")
# Test BitfieldsInStructInUnion.
# FIXME: This needs some more explanation for what it's actually testing.
nested_struct_children = [
ValueCheck(name="", type="int:22"),
ValueCheck(name="a", type="uint64_t:1", value="1"),
ValueCheck(name="b", type="uint64_t:1", value="0"),
ValueCheck(name="c", type="uint64_t:1", value="1"),
ValueCheck(name="d", type="uint64_t:1", value="0"),
ValueCheck(name="e", type="uint64_t:1", value="1"),
ValueCheck(name="f", type="uint64_t:1", value="0"),
ValueCheck(name="g", type="uint64_t:1", value="1"),
ValueCheck(name="h", type="uint64_t:1", value="0"),
ValueCheck(name="i", type="uint64_t:1", value="1"),
ValueCheck(name="j", type="uint64_t:1", value="0"),
ValueCheck(name="k", type="uint64_t:1", value="1"),
]
self.expect_expr(
"bitfields_in_struct_in_union",
result_type="BitfieldsInStructInUnion",
result_children=[
ValueCheck(
name="",
children=[ValueCheck(name="f", children=nested_struct_children)],
)
],
)
self.expect_expr(
"bitfields_in_struct_in_union.f.a", result_type="uint64_t", result_value="1"
)
# Unions with bitfields.
self.expect_expr(
"uwbf",
result_type="UnionWithBitfields",
result_children=[
ValueCheck(name="a", value="255"),
ValueCheck(name="b", value="65535"),
ValueCheck(name="c", value="4294967295"),
ValueCheck(name="x", value="4294967295"),
],
)
self.expect_expr(
"uwubf",
result_type="UnionWithUnnamedBitfield",
result_children=[
ValueCheck(name="a", value="16777215"),
ValueCheck(name="x", value="4294967295"),
],
)
# Class with a base class and a bitfield.
self.expect_expr(
"derived",
result_type="Derived",
result_children=[
ValueCheck(
name="Base",
children=[ValueCheck(name="b_a", value="2", type="uint32_t")],
),
ValueCheck(name="d_a", value="1", type="uint32_t:1"),
],
)
# Struct with bool bitfields.
self.expect_expr(
"bb",
result_type="",
result_children=[
ValueCheck(name="a", value="true", type="bool:1"),
ValueCheck(name="b", value="false", type="bool:1"),
ValueCheck(name="c", value="true", type="bool:2"),
ValueCheck(name="d", value="true", type="bool:2"),
],
)
bb = self.frame().FindVariable("bb")
self.assertSuccess(bb.GetError())
bb_a = bb.GetChildAtIndex(0)
self.assertSuccess(bb_a.GetError())
self.assertEqual(bb_a.GetValueAsUnsigned(), 1)
self.assertEqual(bb_a.GetValueAsSigned(), 1)
bb_b = bb.GetChildAtIndex(1)
self.assertSuccess(bb_b.GetError())
self.assertEqual(bb_b.GetValueAsUnsigned(), 0)
self.assertEqual(bb_b.GetValueAsSigned(), 0)
bb_c = bb.GetChildAtIndex(2)
self.assertSuccess(bb_c.GetError())
self.assertEqual(bb_c.GetValueAsUnsigned(), 1)
self.assertEqual(bb_c.GetValueAsSigned(), 1)
bb_d = bb.GetChildAtIndex(3)
self.assertSuccess(bb_d.GetError())
self.assertEqual(bb_d.GetValueAsUnsigned(), 1)
self.assertEqual(bb_d.GetValueAsSigned(), 1)
# Test a class with a base class that has a vtable ptr. The derived
# class has bitfields.
base_with_vtable_children = [
ValueCheck(name="a", type="unsigned int:4", value="5"),
ValueCheck(name="b", type="unsigned int:4", value="0"),
ValueCheck(name="c", type="unsigned int:4", value="5"),
]
self.expect_expr("base_with_vtable", result_children=base_with_vtable_children)
self.expect_var_path("base_with_vtable", children=base_with_vtable_children)
@no_debug_info_test
def test_bitfield_behind_vtable_ptr(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp", False)
)
# Test a class with a vtable ptr and bitfields.
with_vtable_children = [
ValueCheck(name="a", type="unsigned int:4", value="5"),
ValueCheck(name="b", type="unsigned int:4", value="0"),
ValueCheck(name="c", type="unsigned int:4", value="5"),
]
self.expect_expr("with_vtable", result_children=with_vtable_children)
self.expect_var_path("with_vtable", children=with_vtable_children)
# Test a class with a vtable ptr and unnamed bitfield directly after.
with_vtable_and_unnamed_children = [
ValueCheck(name="", type="int:4", value="0"),
ValueCheck(name="b", type="unsigned int:4", value="0"),
ValueCheck(name="c", type="unsigned int:4", value="5"),
]
self.expect_expr(
"with_vtable_and_unnamed", result_children=with_vtable_and_unnamed_children
)
self.expect_var_path(
"with_vtable_and_unnamed", children=with_vtable_and_unnamed_children
)
derived_with_vtable_children = [
ValueCheck(
name="Base",
children=[ValueCheck(name="b_a", value="2", type="uint32_t")],
),
ValueCheck(name="a", value="1", type="unsigned int:1"),
]
self.expect_expr(
"derived_with_vtable", result_children=derived_with_vtable_children
)
self.expect_var_path(
"derived_with_vtable", children=derived_with_vtable_children
)
|