Skip to content

Commit 3d0349f

Browse files
committed
[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. (cherry picked from commit 9ed8896)
1 parent 2c0d37b commit 3d0349f

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
@@ -465,6 +465,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
465465
byte_size = form_value.Unsigned();
466466
break;
467467

468+
case DW_AT_bit_size:
469+
data_bit_size = form_value.Unsigned();
470+
break;
471+
468472
case DW_AT_alignment:
469473
alignment = form_value.Unsigned();
470474
break;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ struct ParsedDWARFTypeAttributes {
592592
lldb_private::plugin::dwarf::DWARFFormValue type;
593593
lldb::LanguageType class_language = lldb::eLanguageTypeUnknown;
594594
std::optional<uint64_t> byte_size;
595+
std::optional<uint64_t> data_bit_size;
595596
std::optional<uint64_t> alignment;
596597
size_t calling_convention = llvm::dwarf::DW_CC_normal;
597598
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
@@ -1617,3 +1617,93 @@ TEST_F(DWARFASTParserClangTests, TestObjectPointer_IndexEncoding) {
16171617
EXPECT_EQ(param_die, ast_parser.GetObjectParameter(sub2, context_die));
16181618
}
16191619
}
1620+
1621+
TEST_F(DWARFASTParserClangTests, TestTypeBitSize) {
1622+
// Tests that we correctly parse DW_AT_bit_size of a DW_AT_base_type.
1623+
1624+
const char *yamldata = R"(
1625+
--- !ELF
1626+
FileHeader:
1627+
Class: ELFCLASS64
1628+
Data: ELFDATA2LSB
1629+
Type: ET_EXEC
1630+
Machine: EM_AARCH64
1631+
DWARF:
1632+
debug_str:
1633+
- _BitInt(2)
1634+
debug_abbrev:
1635+
- ID: 0
1636+
Table:
1637+
- Code: 0x1
1638+
Tag: DW_TAG_compile_unit
1639+
Children: DW_CHILDREN_yes
1640+
Attributes:
1641+
- Attribute: DW_AT_language
1642+
Form: DW_FORM_data2
1643+
- Code: 0x2
1644+
Tag: DW_TAG_base_type
1645+
Children: DW_CHILDREN_no
1646+
Attributes:
1647+
- Attribute: DW_AT_name
1648+
Form: DW_FORM_strp
1649+
- Attribute: DW_AT_encoding
1650+
Form: DW_FORM_data1
1651+
- Attribute: DW_AT_byte_size
1652+
Form: DW_FORM_data1
1653+
- Attribute: DW_AT_bit_size
1654+
Form: DW_FORM_data1
1655+
1656+
debug_info:
1657+
- Version: 5
1658+
UnitType: DW_UT_compile
1659+
AddrSize: 8
1660+
Entries:
1661+
1662+
# DW_TAG_compile_unit
1663+
# DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
1664+
1665+
- AbbrCode: 0x1
1666+
Values:
1667+
- Value: 0x04
1668+
1669+
# DW_TAG_base_type
1670+
# DW_AT_name [DW_FORM_strp] ('_BitInt(2)')
1671+
1672+
- AbbrCode: 0x2
1673+
Values:
1674+
- Value: 0x0
1675+
- Value: 0x05
1676+
- Value: 0x01
1677+
- Value: 0x02
1678+
...
1679+
)";
1680+
1681+
YAMLModuleTester t(yamldata);
1682+
1683+
DWARFUnit *unit = t.GetDwarfUnit();
1684+
ASSERT_NE(unit, nullptr);
1685+
const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE();
1686+
ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit);
1687+
ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus);
1688+
DWARFDIE cu_die(unit, cu_entry);
1689+
1690+
auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("ast");
1691+
auto &ast_ctx = *holder->GetAST();
1692+
DWARFASTParserClangStub ast_parser(ast_ctx);
1693+
1694+
auto type_die = cu_die.GetFirstChild();
1695+
ASSERT_TRUE(type_die.IsValid());
1696+
ASSERT_EQ(type_die.Tag(), DW_TAG_base_type);
1697+
1698+
ParsedDWARFTypeAttributes attrs(type_die);
1699+
EXPECT_EQ(attrs.byte_size.value_or(0), 1U);
1700+
EXPECT_EQ(attrs.data_bit_size.value_or(0), 2U);
1701+
1702+
SymbolContext sc;
1703+
auto type_sp =
1704+
ast_parser.ParseTypeFromDWARF(sc, type_die, /*type_is_new_ptr=*/nullptr);
1705+
ASSERT_NE(type_sp, nullptr);
1706+
1707+
EXPECT_EQ(llvm::expectedToOptional(type_sp->GetByteSize(nullptr)).value_or(0),
1708+
1U);
1709+
}

0 commit comments

Comments
 (0)