[llvm] 771b7af - Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature references"… (#99495)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 01:13:51 PDT 2024
Author: Pavel Labath
Date: 2024-09-04T10:13:47+02:00
New Revision: 771b7af1db15e59f370ccadaa98bee8e5270b5f1
URL: https://github.com/llvm/llvm-project/commit/771b7af1db15e59f370ccadaa98bee8e5270b5f1
DIFF: https://github.com/llvm/llvm-project/commit/771b7af1db15e59f370ccadaa98bee8e5270b5f1.diff
LOG: 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.
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 5daa093ee8a1be..9c26c4f8892b01 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -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;
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
index e1057b214ee4d3..485ec720ffad62 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
@@ -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
More information about the llvm-commits
mailing list