Skip to content

Commit

Permalink
Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature references"… (
Browse files Browse the repository at this point in the history
#99495)

… (#99444)

The previous version introduced a bug (caught by cross-project tests).
Explicit signature resolution is still necessary when one wants to
access the children (not attributes) of a given DIE.

The new version keeps just the findRecursively extension, and reverts
all the DWARFTypePrinter modifications.
  • Loading branch information
labath authored Sep 4, 2024
1 parent 01e5684 commit 771b7af
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
13 changes: 6 additions & 7 deletions llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,12 @@ DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
if (auto Value = Die.find(Attrs))
return Value;

if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
if (Seen.insert(D).second)
Worklist.push_back(D);

if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
if (Seen.insert(D).second)
Worklist.push_back(D);
for (dwarf::Attribute Attr :
{DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) {
if (auto D = Die.getAttributeValueAsReferencedDie(Attr))
if (Seen.insert(D).second)
Worklist.push_back(D);
}
}

return std::nullopt;
Expand Down
61 changes: 61 additions & 0 deletions llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,65 @@ TEST(DWARFDie, getDeclFileSpecificationAcrossCUBoundary) {
EXPECT_EQ(DeclFile, Ref);
}

TEST(DWARFDie, getNameFromTypeUnit) {
const char *yamldata = R"(
debug_abbrev:
- ID: 0
Table:
- Code: 0x1
Tag: DW_TAG_compile_unit
Children: DW_CHILDREN_yes
- Code: 0x2
Tag: DW_TAG_structure_type
Children: DW_CHILDREN_no
Attributes:
- Attribute: DW_AT_signature
Form: DW_FORM_ref_sig8
- Code: 0x3
Tag: DW_TAG_type_unit
Children: DW_CHILDREN_yes
- Code: 0x4
Tag: DW_TAG_structure_type
Children: DW_CHILDREN_no
Attributes:
- Attribute: DW_AT_name
Form: DW_FORM_string
debug_info:
- Version: 5
UnitType: DW_UT_compile
AbbrevTableID: 0
Entries:
- AbbrCode: 0x1
- AbbrCode: 0x2
Values:
- Value: 0xdeadbeefbaadf00d
- AbbrCode: 0x0
- Version: 5
UnitType: DW_UT_type
AbbrevTableID: 0
TypeSignature: 0xdeadbeefbaadf00d
TypeOffset: 25
Entries:
- AbbrCode: 0x3
- AbbrCode: 0x4
Values:
- CStr: "STRUCT"
- AbbrCode: 0x0
)";

Expected<StringMap<std::unique_ptr<MemoryBuffer>>> Sections =
DWARFYAML::emitDebugSections(StringRef(yamldata),
/*IsLittleEndian=*/true,
/*Is64BitAddrSize=*/true);
ASSERT_THAT_EXPECTED(Sections, Succeeded());
std::unique_ptr<DWARFContext> Ctx =
DWARFContext::create(*Sections, 4, /*isLittleEndian=*/true);
DWARFCompileUnit *CU = Ctx->getCompileUnitForOffset(0);
ASSERT_NE(nullptr, CU);
DWARFDie Die = CU->getUnitDIE(/*ExtractUnitDIEOnly=*/false).getFirstChild();
ASSERT_TRUE(Die.isValid());

ASSERT_STREQ(Die.getName(DINameKind::ShortName), "STRUCT");
}

} // end anonymous namespace

0 comments on commit 771b7af

Please sign in to comment.