Skip to content

Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature references"… #99495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading