summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/DWARF
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2017-10-06 22:27:31 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2017-10-06 22:27:31 +0000
commitf2fa9ebe3f58eaa963f3ef0e9e2af7ce3ff31e76 (patch)
tree9d4d9facb665bbe972264654e1ff8ef3ffe2fb9b /llvm/lib/DebugInfo/DWARF
parentcc590600631eec93b92d052ea852befed4e30039 (diff)
downloadbcm5719-llvm-f2fa9ebe3f58eaa963f3ef0e9e2af7ce3ff31e76.tar.gz
bcm5719-llvm-f2fa9ebe3f58eaa963f3ef0e9e2af7ce3ff31e76.zip
[dwarfdump] Verify that unit type matches root DIE
This patch adds two new verifiers: - It checks that the root DIE of a CU is actually a valid unit DIE. (based on its tag) - For DWARF5 which contains a unit type int he CU header, it checks that this matches the type of the unit DIE. Differential revision: https://reviews.llvm.org/D38453 llvm-svn: 315121
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 27e6a05e6dd..bec6e922ceb 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -134,7 +134,7 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
UnitType = DebugInfoData.getU8(Offset);
AddrSize = DebugInfoData.getU8(Offset);
AbbrOffset = DebugInfoData.getU32(Offset);
- ValidType = DWARFUnit::isValidUnitType(UnitType);
+ ValidType = dwarf::isUnitType(UnitType);
} else {
UnitType = 0;
AbbrOffset = DebugInfoData.getU32(Offset);
@@ -169,7 +169,7 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
return Success;
}
-bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit) {
+bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit, uint8_t UnitType) {
uint32_t NumUnitErrors = 0;
unsigned NumDies = Unit.getNumDIEs();
for (unsigned I = 0; I < NumDies; ++I) {
@@ -182,14 +182,30 @@ bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit) {
}
}
- if (DWARFDie Die = Unit.getUnitDIE(/* ExtractUnitDIEOnly = */ false)) {
- DieRangeInfo RI;
- NumUnitErrors += verifyDieRanges(Die, RI);
- } else {
- error() << "Compilation unit without unit DIE.\n";
+ DWARFDie Die = Unit.getUnitDIE(/* ExtractUnitDIEOnly = */ false);
+ if (!Die) {
+ error() << "Compilation unit without DIE.\n";
+ NumUnitErrors++;
+ return NumUnitErrors == 0;
+ }
+
+ if (!dwarf::isUnitType(Die.getTag())) {
+ error() << "Compilation unit root DIE is not a unit DIE: "
+ << dwarf::TagString(Die.getTag()) << ".\n";
NumUnitErrors++;
}
+ if (UnitType != 0 &&
+ !DWARFUnit::isMatchingUnitTypeAndTag(UnitType, Die.getTag())) {
+ error() << "Compilation unit type (" << dwarf::UnitTypeString(UnitType)
+ << ") and root DIE (" << dwarf::TagString(Die.getTag())
+ << ") do not match.\n";
+ NumUnitErrors++;
+ }
+
+ DieRangeInfo RI;
+ NumUnitErrors += verifyDieRanges(Die, RI);
+
return NumUnitErrors == 0;
}
@@ -286,7 +302,7 @@ bool DWARFVerifier::handleDebugInfo() {
default: { llvm_unreachable("Invalid UnitType."); }
}
Unit->extract(DebugInfoData, &OffsetStart);
- if (!verifyUnitContents(*Unit))
+ if (!verifyUnitContents(*Unit, UnitType))
++NumDebugInfoErrors;
}
hasDIE = DebugInfoData.isValidOffset(Offset);
OpenPOWER on IntegriCloud