Skip to content

Commit 771b7af

Browse files
authored
Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature references"… (#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.
1 parent 01e5684 commit 771b7af

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,12 @@ DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
291291
if (auto Value = Die.find(Attrs))
292292
return Value;
293293

294-
if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
295-
if (Seen.insert(D).second)
296-
Worklist.push_back(D);
297-
298-
if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
299-
if (Seen.insert(D).second)
300-
Worklist.push_back(D);
294+
for (dwarf::Attribute Attr :
295+
{DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) {
296+
if (auto D = Die.getAttributeValueAsReferencedDie(Attr))
297+
if (Seen.insert(D).second)
298+
Worklist.push_back(D);
299+
}
301300
}
302301

303302
return std::nullopt;

llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,4 +643,65 @@ TEST(DWARFDie, getDeclFileSpecificationAcrossCUBoundary) {
643643
EXPECT_EQ(DeclFile, Ref);
644644
}
645645

646+
TEST(DWARFDie, getNameFromTypeUnit) {
647+
const char *yamldata = R"(
648+
debug_abbrev:
649+
- ID: 0
650+
Table:
651+
- Code: 0x1
652+
Tag: DW_TAG_compile_unit
653+
Children: DW_CHILDREN_yes
654+
- Code: 0x2
655+
Tag: DW_TAG_structure_type
656+
Children: DW_CHILDREN_no
657+
Attributes:
658+
- Attribute: DW_AT_signature
659+
Form: DW_FORM_ref_sig8
660+
- Code: 0x3
661+
Tag: DW_TAG_type_unit
662+
Children: DW_CHILDREN_yes
663+
- Code: 0x4
664+
Tag: DW_TAG_structure_type
665+
Children: DW_CHILDREN_no
666+
Attributes:
667+
- Attribute: DW_AT_name
668+
Form: DW_FORM_string
669+
debug_info:
670+
- Version: 5
671+
UnitType: DW_UT_compile
672+
AbbrevTableID: 0
673+
Entries:
674+
- AbbrCode: 0x1
675+
- AbbrCode: 0x2
676+
Values:
677+
- Value: 0xdeadbeefbaadf00d
678+
- AbbrCode: 0x0
679+
- Version: 5
680+
UnitType: DW_UT_type
681+
AbbrevTableID: 0
682+
TypeSignature: 0xdeadbeefbaadf00d
683+
TypeOffset: 25
684+
Entries:
685+
- AbbrCode: 0x3
686+
- AbbrCode: 0x4
687+
Values:
688+
- CStr: "STRUCT"
689+
- AbbrCode: 0x0
690+
)";
691+
692+
Expected<StringMap<std::unique_ptr<MemoryBuffer>>> Sections =
693+
DWARFYAML::emitDebugSections(StringRef(yamldata),
694+
/*IsLittleEndian=*/true,
695+
/*Is64BitAddrSize=*/true);
696+
ASSERT_THAT_EXPECTED(Sections, Succeeded());
697+
std::unique_ptr<DWARFContext> Ctx =
698+
DWARFContext::create(*Sections, 4, /*isLittleEndian=*/true);
699+
DWARFCompileUnit *CU = Ctx->getCompileUnitForOffset(0);
700+
ASSERT_NE(nullptr, CU);
701+
DWARFDie Die = CU->getUnitDIE(/*ExtractUnitDIEOnly=*/false).getFirstChild();
702+
ASSERT_TRUE(Die.isValid());
703+
704+
ASSERT_STREQ(Die.getName(DINameKind::ShortName), "STRUCT");
705+
}
706+
646707
} // end anonymous namespace

0 commit comments

Comments
 (0)