Skip to content

Commit 9ed8896

Browse files
authored
[lldb][DWARF] Support DW_AT_bit_size on type tags (llvm#165686)
One (DWARF-spec compliant) exmample is: llvm#164372, where we attach a `DW_AT_bit_size` to `_BitInt` types that can't be exactly described by a byte-size. This patch adds support for `DW_AT_bit_size` to `DWARFASTParserClang` when parsing type tags. Note, we don't use this bit-size yet, but will do so in follow-up patches.
1 parent 9b02901 commit 9ed8896

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
450450
byte_size = form_value.Unsigned();
451451
break;
452452

453+
case DW_AT_bit_size:
454+
data_bit_size = form_value.Unsigned();
455+
break;
456+
453457
case DW_AT_alignment:
454458
alignment = form_value.Unsigned();
455459
break;

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ struct ParsedDWARFTypeAttributes {
574574
lldb_private::plugin::dwarf::DWARFFormValue type;
575575
lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;
576576
std::optional<uint64_t> byte_size;
577+
std::optional<uint64_t> data_bit_size;
577578
std::optional<uint64_t> alignment;
578579
size_t calling_convention = llvm::dwarf::DW_CC_normal;
579580
uint32_t bit_stride = 0;

lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,3 +1651,93 @@ TEST_F(DWARFASTParserClangTests, TestObjectPointer_IndexEncoding) {
16511651
EXPECT_EQ(param_die, ast_parser.GetObjectParameter(sub2, context_die));
16521652
}
16531653
}
1654+
1655+
TEST_F(DWARFASTParserClangTests, TestTypeBitSize) {
1656+
// Tests that we correctly parse DW_AT_bit_size of a DW_AT_base_type.
1657+
1658+
const char *yamldata = R"(
1659+
--- !ELF
1660+
FileHeader:
1661+
Class: ELFCLASS64
1662+
Data: ELFDATA2LSB
1663+
Type: ET_EXEC
1664+
Machine: EM_AARCH64
1665+
DWARF:
1666+
debug_str:
1667+
- _BitInt(2)
1668+
debug_abbrev:
1669+
- ID: 0
1670+
Table:
1671+
- Code: 0x1
1672+
Tag: DW_TAG_compile_unit
1673+
Children: DW_CHILDREN_yes
1674+
Attributes:
1675+
- Attribute: DW_AT_language
1676+
Form: DW_FORM_data2
1677+
- Code: 0x2
1678+
Tag: DW_TAG_base_type
1679+
Children: DW_CHILDREN_no
1680+
Attributes:
1681+
- Attribute: DW_AT_name
1682+
Form: DW_FORM_strp
1683+
- Attribute: DW_AT_encoding
1684+
Form: DW_FORM_data1
1685+
- Attribute: DW_AT_byte_size
1686+
Form: DW_FORM_data1
1687+
- Attribute: DW_AT_bit_size
1688+
Form: DW_FORM_data1
1689+
1690+
debug_info:
1691+
- Version: 5
1692+
UnitType: DW_UT_compile
1693+
AddrSize: 8
1694+
Entries:
1695+
1696+
# DW_TAG_compile_unit
1697+
# DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
1698+
1699+
- AbbrCode: 0x1
1700+
Values:
1701+
- Value: 0x04
1702+
1703+
# DW_TAG_base_type
1704+
# DW_AT_name [DW_FORM_strp] ('_BitInt(2)')
1705+
1706+
- AbbrCode: 0x2
1707+
Values:
1708+
- Value: 0x0
1709+
- Value: 0x05
1710+
- Value: 0x01
1711+
- Value: 0x02
1712+
...
1713+
)";
1714+
1715+
YAMLModuleTester t(yamldata);
1716+
1717+
DWARFUnit *unit = t.GetDwarfUnit();
1718+
ASSERT_NE(unit, nullptr);
1719+
const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE();
1720+
ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit);
1721+
ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus);
1722+
DWARFDIE cu_die(unit, cu_entry);
1723+
1724+
auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("ast");
1725+
auto &ast_ctx = *holder->GetAST();
1726+
DWARFASTParserClangStub ast_parser(ast_ctx);
1727+
1728+
auto type_die = cu_die.GetFirstChild();
1729+
ASSERT_TRUE(type_die.IsValid());
1730+
ASSERT_EQ(type_die.Tag(), DW_TAG_base_type);
1731+
1732+
ParsedDWARFTypeAttributes attrs(type_die);
1733+
EXPECT_EQ(attrs.byte_size.value_or(0), 1U);
1734+
EXPECT_EQ(attrs.data_bit_size.value_or(0), 2U);
1735+
1736+
SymbolContext sc;
1737+
auto type_sp =
1738+
ast_parser.ParseTypeFromDWARF(sc, type_die, /*type_is_new_ptr=*/nullptr);
1739+
ASSERT_NE(type_sp, nullptr);
1740+
1741+
EXPECT_EQ(llvm::expectedToOptional(type_sp->GetByteSize(nullptr)).value_or(0),
1742+
1U);
1743+
}

0 commit comments

Comments
 (0)