[PATCH] D30456: [DebugInfo] Unique abbrevs for DIEs with different implicit_const values
Victor Leschuk via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 28 06:00:46 PST 2017
vleschuk created this revision.
Herald added a subscriber: mehdi_amini.
Take DW_FORM_implicit_const attribute value into account when profiling DIEAbbrevData.
Currently if we have two similar types with implicit_const attributes and different values we end up with only one abbrev in .debug_abbrev section. For example consider two structures: S1 with implicit_const attribute ATTR and value VAL1 and S2 with implicit_const ATTR and value VAL2. The .debug_abbrev section will contain only 1 related record:
[N] DW_TAG_structure_type DW_CHILDREN_yes
DW_AT_ATTR DW_FORM_implicit_const VAL1
// ....
This is incorrect as struct S2 (with VAL2) will use abbrev record with VAL1.
With this patch we will have two different abbreviations here:
[N] DW_TAG_structure_type DW_CHILDREN_yes
DW_AT_ATTR DW_FORM_implicit_const VAL1
// ....
[M] DW_TAG_structure_type DW_CHILDREN_yes
DW_AT_ATTR DW_FORM_implicit_const VAL2
// ....
https://reviews.llvm.org/D30456
Files:
lib/CodeGen/AsmPrinter/DIE.cpp
unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
unittests/DebugInfo/DWARF/DwarfGenerator.h
Index: unittests/DebugInfo/DWARF/DwarfGenerator.h
===================================================================
--- unittests/DebugInfo/DWARF/DwarfGenerator.h
+++ unittests/DebugInfo/DWARF/DwarfGenerator.h
@@ -132,6 +132,9 @@
/// Force a DIE to say it has children even when it doesn't.
void setForceChildren();
+
+ /// Get actual DIE object
+ llvm::DIE &getDIE() { return *Die; }
};
/// A DWARF compile unit used to generate DWARF compile/type units.
Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
===================================================================
--- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -1543,4 +1543,38 @@
EXPECT_EQ(DieMangled, toString(NameOpt, ""));
}
+TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) {
+ uint16_t Version = 5;
+
+ const uint8_t AddrSize = sizeof(void *);
+ initLLVMIfNeeded();
+ Triple Triple = getHostTripleForAddrSize(AddrSize);
+ auto ExpectedDG = dwarfgen::Generator::create(Triple, Version);
+ if (HandleExpectedError(ExpectedDG))
+ return;
+ dwarfgen::Generator *DG = ExpectedDG.get().get();
+ dwarfgen::CompileUnit &CU = DG->addCompileUnit();
+ dwarfgen::DIE CUDie = CU.getUnitDIE();
+ uint16_t Attr = DW_AT_lo_user;
+ int64_t Val1 = 42;
+ int64_t Val2 = 43;
+
+ auto &AbbrevSet = DG->getAbbrevSet();
+ auto FirstVal1DIE = CUDie.addChild(DW_TAG_class_type);
+ FirstVal1DIE.addAttribute(Attr, DW_FORM_implicit_const, Val1);
+ auto &FirstVal1Abbrev = AbbrevSet.uniqueAbbreviation(FirstVal1DIE.getDIE());
+
+ auto SecondVal1DIE = CUDie.addChild(DW_TAG_class_type);
+ SecondVal1DIE.addAttribute(Attr, DW_FORM_implicit_const, Val1);
+ auto &SecondVal1Abbrev = AbbrevSet.uniqueAbbreviation(SecondVal1DIE.getDIE());
+
+ EXPECT_EQ(FirstVal1Abbrev.getNumber(), SecondVal1Abbrev.getNumber());
+
+ auto Val2DIE = CUDie.addChild(DW_TAG_class_type);
+ Val2DIE.addAttribute(Attr, DW_FORM_implicit_const, Val2);
+ auto &Val2Abbrev = AbbrevSet.uniqueAbbreviation(Val2DIE.getDIE());
+
+ EXPECT_NE(FirstVal1Abbrev.getNumber(), Val2Abbrev.getNumber());
+}
+
} // end anonymous namespace
Index: lib/CodeGen/AsmPrinter/DIE.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DIE.cpp
+++ lib/CodeGen/AsmPrinter/DIE.cpp
@@ -42,6 +42,8 @@
// overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
ID.AddInteger(unsigned(Attribute));
ID.AddInteger(unsigned(Form));
+ if (dwarf::DW_FORM_implicit_const == Form)
+ ID.AddInteger(Value);
}
//===----------------------------------------------------------------------===//
@@ -107,8 +109,12 @@
O << " "
<< dwarf::AttributeString(Data[i].getAttribute())
<< " "
- << dwarf::FormEncodingString(Data[i].getForm())
- << '\n';
+ << dwarf::FormEncodingString(Data[i].getForm());
+
+ if (dwarf::DW_FORM_implicit_const == Data[i].getForm())
+ O << " " << Data[i].getValue();
+
+ O << '\n';
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30456.90016.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170228/d25fea93/attachment.bin>
More information about the llvm-commits
mailing list