[llvm] Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature references"… (PR #99495)
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 08:17:43 PDT 2024
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/99495
>From 4147f18d415ea359275e5538107d0a1fdc6679a7 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Thu, 18 Jul 2024 11:23:56 +0200
Subject: [PATCH] Reapply "[llvm/DWARF] Recursively resolve DW_AT_signature
references" (#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.
---
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 13 ++--
.../DebugInfo/DWARF/DWARFDieTest.cpp | 61 +++++++++++++++++++
2 files changed, 67 insertions(+), 7 deletions(-)
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