Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 1 | //===- DWARFVerifier.cpp --------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/DebugInfo/DWARF/DWARFVerifier.h" |
Pavel Labath | 79cd942 | 2018-03-22 14:50:44 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallSet.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" |
| 13 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
| 14 | #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" |
| 15 | #include "llvm/DebugInfo/DWARF/DWARFDie.h" |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/DWARF/DWARFExpression.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" |
| 18 | #include "llvm/DebugInfo/DWARF/DWARFSection.h" |
Pavel Labath | 906b777 | 2018-03-16 10:02:16 +0000 | [diff] [blame] | 19 | #include "llvm/Support/DJB.h" |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 20 | #include "llvm/Support/FormatVariadic.h" |
Jonas Devlieghere | 6921753 | 2018-03-09 09:56:24 +0000 | [diff] [blame] | 21 | #include "llvm/Support/WithColor.h" |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
| 23 | #include <map> |
| 24 | #include <set> |
| 25 | #include <vector> |
| 26 | |
| 27 | using namespace llvm; |
| 28 | using namespace dwarf; |
| 29 | using namespace object; |
| 30 | |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 31 | DWARFVerifier::DieRangeInfo::address_range_iterator |
| 32 | DWARFVerifier::DieRangeInfo::insert(const DWARFAddressRange &R) { |
| 33 | auto Begin = Ranges.begin(); |
| 34 | auto End = Ranges.end(); |
| 35 | auto Pos = std::lower_bound(Begin, End, R); |
| 36 | |
| 37 | if (Pos != End) { |
| 38 | if (Pos->intersects(R)) |
| 39 | return Pos; |
| 40 | if (Pos != Begin) { |
| 41 | auto Iter = Pos - 1; |
| 42 | if (Iter->intersects(R)) |
| 43 | return Iter; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | Ranges.insert(Pos, R); |
| 48 | return Ranges.end(); |
| 49 | } |
| 50 | |
| 51 | DWARFVerifier::DieRangeInfo::die_range_info_iterator |
| 52 | DWARFVerifier::DieRangeInfo::insert(const DieRangeInfo &RI) { |
| 53 | auto End = Children.end(); |
| 54 | auto Iter = Children.begin(); |
| 55 | while (Iter != End) { |
| 56 | if (Iter->intersects(RI)) |
| 57 | return Iter; |
| 58 | ++Iter; |
| 59 | } |
| 60 | Children.insert(RI); |
| 61 | return Children.end(); |
| 62 | } |
| 63 | |
| 64 | bool DWARFVerifier::DieRangeInfo::contains(const DieRangeInfo &RHS) const { |
| 65 | // Both list of ranges are sorted so we can make this fast. |
| 66 | |
| 67 | if (Ranges.empty() || RHS.Ranges.empty()) |
| 68 | return false; |
| 69 | |
| 70 | // Since the ranges are sorted we can advance where we start searching with |
| 71 | // this object's ranges as we traverse RHS.Ranges. |
| 72 | auto End = Ranges.end(); |
| 73 | auto Iter = findRange(RHS.Ranges.front()); |
| 74 | |
| 75 | // Now linearly walk the ranges in this object and see if they contain each |
| 76 | // ranges from RHS.Ranges. |
| 77 | for (const auto &R : RHS.Ranges) { |
| 78 | while (Iter != End) { |
| 79 | if (Iter->contains(R)) |
| 80 | break; |
| 81 | ++Iter; |
| 82 | } |
| 83 | if (Iter == End) |
| 84 | return false; |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool DWARFVerifier::DieRangeInfo::intersects(const DieRangeInfo &RHS) const { |
| 90 | if (Ranges.empty() || RHS.Ranges.empty()) |
| 91 | return false; |
| 92 | |
| 93 | auto End = Ranges.end(); |
| 94 | auto Iter = findRange(RHS.Ranges.front()); |
| 95 | for (const auto &R : RHS.Ranges) { |
Jonas Devlieghere | d585a20 | 2017-09-14 17:46:23 +0000 | [diff] [blame] | 96 | if(Iter == End) |
| 97 | return false; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 98 | if (R.HighPC <= Iter->LowPC) |
| 99 | continue; |
| 100 | while (Iter != End) { |
| 101 | if (Iter->intersects(R)) |
| 102 | return true; |
| 103 | ++Iter; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return false; |
| 108 | } |
| 109 | |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 110 | bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData, |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 111 | uint32_t *Offset, unsigned UnitIndex, |
| 112 | uint8_t &UnitType, bool &isUnitDWARF64) { |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 113 | uint32_t AbbrOffset, Length; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 114 | uint8_t AddrSize = 0; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 115 | uint16_t Version; |
| 116 | bool Success = true; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 117 | |
| 118 | bool ValidLength = false; |
| 119 | bool ValidVersion = false; |
| 120 | bool ValidAddrSize = false; |
| 121 | bool ValidType = true; |
| 122 | bool ValidAbbrevOffset = true; |
| 123 | |
| 124 | uint32_t OffsetStart = *Offset; |
| 125 | Length = DebugInfoData.getU32(Offset); |
| 126 | if (Length == UINT32_MAX) { |
| 127 | isUnitDWARF64 = true; |
| 128 | OS << format( |
| 129 | "Unit[%d] is in 64-bit DWARF format; cannot verify from this point.\n", |
| 130 | UnitIndex); |
| 131 | return false; |
| 132 | } |
| 133 | Version = DebugInfoData.getU16(Offset); |
| 134 | |
| 135 | if (Version >= 5) { |
| 136 | UnitType = DebugInfoData.getU8(Offset); |
| 137 | AddrSize = DebugInfoData.getU8(Offset); |
| 138 | AbbrOffset = DebugInfoData.getU32(Offset); |
Jonas Devlieghere | f2fa9eb | 2017-10-06 22:27:31 +0000 | [diff] [blame] | 139 | ValidType = dwarf::isUnitType(UnitType); |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 140 | } else { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 141 | UnitType = 0; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 142 | AbbrOffset = DebugInfoData.getU32(Offset); |
| 143 | AddrSize = DebugInfoData.getU8(Offset); |
| 144 | } |
| 145 | |
| 146 | if (!DCtx.getDebugAbbrev()->getAbbreviationDeclarationSet(AbbrOffset)) |
| 147 | ValidAbbrevOffset = false; |
| 148 | |
| 149 | ValidLength = DebugInfoData.isValidOffset(OffsetStart + Length + 3); |
| 150 | ValidVersion = DWARFContext::isSupportedVersion(Version); |
| 151 | ValidAddrSize = AddrSize == 4 || AddrSize == 8; |
| 152 | if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset || |
| 153 | !ValidType) { |
| 154 | Success = false; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 155 | error() << format("Units[%d] - start offset: 0x%08x \n", UnitIndex, |
| 156 | OffsetStart); |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 157 | if (!ValidLength) |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 158 | note() << "The length for this unit is too " |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 159 | "large for the .debug_info provided.\n"; |
| 160 | if (!ValidVersion) |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 161 | note() << "The 16 bit unit header version is not valid.\n"; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 162 | if (!ValidType) |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 163 | note() << "The unit type encoding is not valid.\n"; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 164 | if (!ValidAbbrevOffset) |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 165 | note() << "The offset into the .debug_abbrev section is " |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 166 | "not valid.\n"; |
| 167 | if (!ValidAddrSize) |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 168 | note() << "The address size is unsupported.\n"; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 169 | } |
| 170 | *Offset = OffsetStart + Length + 4; |
| 171 | return Success; |
| 172 | } |
| 173 | |
Jonas Devlieghere | f2fa9eb | 2017-10-06 22:27:31 +0000 | [diff] [blame] | 174 | bool DWARFVerifier::verifyUnitContents(DWARFUnit Unit, uint8_t UnitType) { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 175 | uint32_t NumUnitErrors = 0; |
| 176 | unsigned NumDies = Unit.getNumDIEs(); |
| 177 | for (unsigned I = 0; I < NumDies; ++I) { |
| 178 | auto Die = Unit.getDIEAtIndex(I); |
| 179 | if (Die.getTag() == DW_TAG_null) |
| 180 | continue; |
| 181 | for (auto AttrValue : Die.attributes()) { |
| 182 | NumUnitErrors += verifyDebugInfoAttribute(Die, AttrValue); |
| 183 | NumUnitErrors += verifyDebugInfoForm(Die, AttrValue); |
| 184 | } |
| 185 | } |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 186 | |
Jonas Devlieghere | f2fa9eb | 2017-10-06 22:27:31 +0000 | [diff] [blame] | 187 | DWARFDie Die = Unit.getUnitDIE(/* ExtractUnitDIEOnly = */ false); |
| 188 | if (!Die) { |
| 189 | error() << "Compilation unit without DIE.\n"; |
| 190 | NumUnitErrors++; |
| 191 | return NumUnitErrors == 0; |
| 192 | } |
| 193 | |
| 194 | if (!dwarf::isUnitType(Die.getTag())) { |
| 195 | error() << "Compilation unit root DIE is not a unit DIE: " |
| 196 | << dwarf::TagString(Die.getTag()) << ".\n"; |
Jonas Devlieghere | 35fdaa9 | 2017-09-28 15:57:50 +0000 | [diff] [blame] | 197 | NumUnitErrors++; |
| 198 | } |
| 199 | |
Jonas Devlieghere | f2fa9eb | 2017-10-06 22:27:31 +0000 | [diff] [blame] | 200 | if (UnitType != 0 && |
| 201 | !DWARFUnit::isMatchingUnitTypeAndTag(UnitType, Die.getTag())) { |
| 202 | error() << "Compilation unit type (" << dwarf::UnitTypeString(UnitType) |
| 203 | << ") and root DIE (" << dwarf::TagString(Die.getTag()) |
| 204 | << ") do not match.\n"; |
| 205 | NumUnitErrors++; |
| 206 | } |
| 207 | |
| 208 | DieRangeInfo RI; |
| 209 | NumUnitErrors += verifyDieRanges(Die, RI); |
| 210 | |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 211 | return NumUnitErrors == 0; |
| 212 | } |
| 213 | |
Spyridoula Gravani | c6ef987 | 2017-07-21 00:51:32 +0000 | [diff] [blame] | 214 | unsigned DWARFVerifier::verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev) { |
Spyridoula Gravani | 364b535 | 2017-07-20 02:06:52 +0000 | [diff] [blame] | 215 | unsigned NumErrors = 0; |
Spyridoula Gravani | 364b535 | 2017-07-20 02:06:52 +0000 | [diff] [blame] | 216 | if (Abbrev) { |
| 217 | const DWARFAbbreviationDeclarationSet *AbbrDecls = |
| 218 | Abbrev->getAbbreviationDeclarationSet(0); |
| 219 | for (auto AbbrDecl : *AbbrDecls) { |
| 220 | SmallDenseSet<uint16_t> AttributeSet; |
| 221 | for (auto Attribute : AbbrDecl.attributes()) { |
| 222 | auto Result = AttributeSet.insert(Attribute.Attr); |
| 223 | if (!Result.second) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 224 | error() << "Abbreviation declaration contains multiple " |
| 225 | << AttributeString(Attribute.Attr) << " attributes.\n"; |
Spyridoula Gravani | c6ef987 | 2017-07-21 00:51:32 +0000 | [diff] [blame] | 226 | AbbrDecl.dump(OS); |
Spyridoula Gravani | 364b535 | 2017-07-20 02:06:52 +0000 | [diff] [blame] | 227 | ++NumErrors; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | } |
Spyridoula Gravani | c6ef987 | 2017-07-21 00:51:32 +0000 | [diff] [blame] | 232 | return NumErrors; |
| 233 | } |
| 234 | |
| 235 | bool DWARFVerifier::handleDebugAbbrev() { |
| 236 | OS << "Verifying .debug_abbrev...\n"; |
| 237 | |
| 238 | const DWARFObject &DObj = DCtx.getDWARFObj(); |
| 239 | bool noDebugAbbrev = DObj.getAbbrevSection().empty(); |
| 240 | bool noDebugAbbrevDWO = DObj.getAbbrevDWOSection().empty(); |
| 241 | |
| 242 | if (noDebugAbbrev && noDebugAbbrevDWO) { |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | unsigned NumErrors = 0; |
| 247 | if (!noDebugAbbrev) |
| 248 | NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrev()); |
| 249 | |
| 250 | if (!noDebugAbbrevDWO) |
| 251 | NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrevDWO()); |
Spyridoula Gravani | 364b535 | 2017-07-20 02:06:52 +0000 | [diff] [blame] | 252 | return NumErrors == 0; |
| 253 | } |
| 254 | |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 255 | bool DWARFVerifier::handleDebugInfo() { |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 256 | OS << "Verifying .debug_info Unit Header Chain...\n"; |
| 257 | |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 258 | const DWARFObject &DObj = DCtx.getDWARFObj(); |
| 259 | DWARFDataExtractor DebugInfoData(DObj, DObj.getInfoSection(), |
| 260 | DCtx.isLittleEndian(), 0); |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 261 | uint32_t NumDebugInfoErrors = 0; |
| 262 | uint32_t OffsetStart = 0, Offset = 0, UnitIdx = 0; |
| 263 | uint8_t UnitType = 0; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 264 | bool isUnitDWARF64 = false; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 265 | bool isHeaderChainValid = true; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 266 | bool hasDIE = DebugInfoData.isValidOffset(Offset); |
Jonas Devlieghere | aa6be82 | 2017-10-10 14:15:25 +0000 | [diff] [blame] | 267 | DWARFUnitSection<DWARFTypeUnit> TUSection{}; |
| 268 | DWARFUnitSection<DWARFCompileUnit> CUSection{}; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 269 | while (hasDIE) { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 270 | OffsetStart = Offset; |
| 271 | if (!verifyUnitHeader(DebugInfoData, &Offset, UnitIdx, UnitType, |
| 272 | isUnitDWARF64)) { |
| 273 | isHeaderChainValid = false; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 274 | if (isUnitDWARF64) |
| 275 | break; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 276 | } else { |
Paul Robinson | 5f53f07 | 2018-05-14 20:32:31 +0000 | [diff] [blame] | 277 | DWARFUnitHeader Header; |
| 278 | Header.extract(DCtx, DebugInfoData, &OffsetStart); |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 279 | std::unique_ptr<DWARFUnit> Unit; |
| 280 | switch (UnitType) { |
| 281 | case dwarf::DW_UT_type: |
| 282 | case dwarf::DW_UT_split_type: { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 283 | Unit.reset(new DWARFTypeUnit( |
Paul Robinson | 5f53f07 | 2018-05-14 20:32:31 +0000 | [diff] [blame] | 284 | DCtx, DObj.getInfoSection(), Header, DCtx.getDebugAbbrev(), |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 285 | &DObj.getRangeSection(), DObj.getStringSection(), |
| 286 | DObj.getStringOffsetSection(), &DObj.getAppleObjCSection(), |
Paul Robinson | 5f53f07 | 2018-05-14 20:32:31 +0000 | [diff] [blame] | 287 | DObj.getLineSection(), DCtx.isLittleEndian(), false, TUSection)); |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | case dwarf::DW_UT_skeleton: |
| 291 | case dwarf::DW_UT_split_compile: |
| 292 | case dwarf::DW_UT_compile: |
| 293 | case dwarf::DW_UT_partial: |
| 294 | // UnitType = 0 means that we are |
| 295 | // verifying a compile unit in DWARF v4. |
| 296 | case 0: { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 297 | Unit.reset(new DWARFCompileUnit( |
Paul Robinson | 5f53f07 | 2018-05-14 20:32:31 +0000 | [diff] [blame] | 298 | DCtx, DObj.getInfoSection(), Header, DCtx.getDebugAbbrev(), |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 299 | &DObj.getRangeSection(), DObj.getStringSection(), |
| 300 | DObj.getStringOffsetSection(), &DObj.getAppleObjCSection(), |
Paul Robinson | 5f53f07 | 2018-05-14 20:32:31 +0000 | [diff] [blame] | 301 | DObj.getLineSection(), DCtx.isLittleEndian(), false, CUSection)); |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | default: { llvm_unreachable("Invalid UnitType."); } |
| 305 | } |
Jonas Devlieghere | f2fa9eb | 2017-10-06 22:27:31 +0000 | [diff] [blame] | 306 | if (!verifyUnitContents(*Unit, UnitType)) |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 307 | ++NumDebugInfoErrors; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 308 | } |
| 309 | hasDIE = DebugInfoData.isValidOffset(Offset); |
| 310 | ++UnitIdx; |
| 311 | } |
| 312 | if (UnitIdx == 0 && !hasDIE) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 313 | warn() << ".debug_info is empty.\n"; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 314 | isHeaderChainValid = true; |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 315 | } |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 316 | NumDebugInfoErrors += verifyDebugInfoReferences(); |
| 317 | return (isHeaderChainValid && NumDebugInfoErrors == 0); |
Spyridoula Gravani | 890eedc | 2017-07-13 23:25:24 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 320 | unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die, |
| 321 | DieRangeInfo &ParentRI) { |
Spyridoula Gravani | e0ba415 | 2017-07-24 21:04:11 +0000 | [diff] [blame] | 322 | unsigned NumErrors = 0; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 323 | |
| 324 | if (!Die.isValid()) |
| 325 | return NumErrors; |
| 326 | |
| 327 | DWARFAddressRangesVector Ranges = Die.getAddressRanges(); |
| 328 | |
| 329 | // Build RI for this DIE and check that ranges within this DIE do not |
| 330 | // overlap. |
| 331 | DieRangeInfo RI(Die); |
| 332 | for (auto Range : Ranges) { |
| 333 | if (!Range.valid()) { |
Spyridoula Gravani | e0ba415 | 2017-07-24 21:04:11 +0000 | [diff] [blame] | 334 | ++NumErrors; |
Jonas Devlieghere | a15f25d3 | 2017-09-29 15:41:22 +0000 | [diff] [blame] | 335 | error() << "Invalid address range " << Range << "\n"; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 336 | continue; |
| 337 | } |
| 338 | |
| 339 | // Verify that ranges don't intersect. |
| 340 | const auto IntersectingRange = RI.insert(Range); |
| 341 | if (IntersectingRange != RI.Ranges.end()) { |
| 342 | ++NumErrors; |
Jonas Devlieghere | a15f25d3 | 2017-09-29 15:41:22 +0000 | [diff] [blame] | 343 | error() << "DIE has overlapping address ranges: " << Range << " and " |
| 344 | << *IntersectingRange << "\n"; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 345 | break; |
Spyridoula Gravani | e0ba415 | 2017-07-24 21:04:11 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 348 | |
| 349 | // Verify that children don't intersect. |
| 350 | const auto IntersectingChild = ParentRI.insert(RI); |
| 351 | if (IntersectingChild != ParentRI.Children.end()) { |
| 352 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 353 | error() << "DIEs have overlapping address ranges:"; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 354 | Die.dump(OS, 0); |
| 355 | IntersectingChild->Die.dump(OS, 0); |
| 356 | OS << "\n"; |
| 357 | } |
| 358 | |
| 359 | // Verify that ranges are contained within their parent. |
| 360 | bool ShouldBeContained = !Ranges.empty() && !ParentRI.Ranges.empty() && |
| 361 | !(Die.getTag() == DW_TAG_subprogram && |
| 362 | ParentRI.Die.getTag() == DW_TAG_subprogram); |
| 363 | if (ShouldBeContained && !ParentRI.contains(RI)) { |
| 364 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 365 | error() << "DIE address ranges are not " |
| 366 | "contained in its parent's ranges:"; |
Jonas Devlieghere | 5891060 | 2017-09-14 11:33:42 +0000 | [diff] [blame] | 367 | Die.dump(OS, 0); |
| 368 | ParentRI.Die.dump(OS, 0); |
| 369 | OS << "\n"; |
| 370 | } |
| 371 | |
| 372 | // Recursively check children. |
| 373 | for (DWARFDie Child : Die) |
| 374 | NumErrors += verifyDieRanges(Child, RI); |
| 375 | |
Spyridoula Gravani | e0ba415 | 2017-07-24 21:04:11 +0000 | [diff] [blame] | 376 | return NumErrors; |
| 377 | } |
| 378 | |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 379 | unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die, |
| 380 | DWARFAttribute &AttrValue) { |
| 381 | unsigned NumErrors = 0; |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 382 | auto ReportError = [&](const Twine &TitleMsg) { |
| 383 | ++NumErrors; |
| 384 | error() << TitleMsg << '\n'; |
| 385 | Die.dump(OS, 0, DumpOpts); |
| 386 | OS << "\n"; |
| 387 | }; |
| 388 | |
| 389 | const DWARFObject &DObj = DCtx.getDWARFObj(); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 390 | const auto Attr = AttrValue.Attr; |
| 391 | switch (Attr) { |
| 392 | case DW_AT_ranges: |
| 393 | // Make sure the offset in the DW_AT_ranges attribute is valid. |
| 394 | if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) { |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 395 | if (*SectionOffset >= DObj.getRangeSection().Data.size()) |
| 396 | ReportError("DW_AT_ranges offset is beyond .debug_ranges bounds:"); |
| 397 | break; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 398 | } |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 399 | ReportError("DIE has invalid DW_AT_ranges encoding:"); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 400 | break; |
| 401 | case DW_AT_stmt_list: |
| 402 | // Make sure the offset in the DW_AT_stmt_list attribute is valid. |
| 403 | if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) { |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 404 | if (*SectionOffset >= DObj.getLineSection().Data.size()) |
| 405 | ReportError("DW_AT_stmt_list offset is beyond .debug_line bounds: " + |
George Rimar | 3d07f60 | 2017-10-27 10:58:04 +0000 | [diff] [blame] | 406 | llvm::formatv("{0:x8}", *SectionOffset)); |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 407 | break; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 408 | } |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 409 | ReportError("DIE has invalid DW_AT_stmt_list encoding:"); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 410 | break; |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 411 | case DW_AT_location: { |
Jonas Devlieghere | 7e0b023 | 2018-05-22 17:37:27 +0000 | [diff] [blame^] | 412 | auto VerifyLocationExpr = [&](StringRef D) { |
Jonas Devlieghere | 7d4a974 | 2018-02-17 13:06:37 +0000 | [diff] [blame] | 413 | DWARFUnit *U = Die.getDwarfUnit(); |
| 414 | DataExtractor Data(D, DCtx.isLittleEndian(), 0); |
| 415 | DWARFExpression Expression(Data, U->getVersion(), |
| 416 | U->getAddressByteSize()); |
| 417 | bool Error = llvm::any_of(Expression, [](DWARFExpression::Operation &Op) { |
| 418 | return Op.isError(); |
| 419 | }); |
| 420 | if (Error) |
| 421 | ReportError("DIE contains invalid DWARF expression:"); |
| 422 | }; |
| 423 | if (Optional<ArrayRef<uint8_t>> Expr = AttrValue.Value.getAsBlock()) { |
| 424 | // Verify inlined location. |
Jonas Devlieghere | 7e0b023 | 2018-05-22 17:37:27 +0000 | [diff] [blame^] | 425 | VerifyLocationExpr(llvm::toStringRef(*Expr)); |
| 426 | } else if (auto LocOffset = AttrValue.Value.getAsSectionOffset()) { |
Jonas Devlieghere | 7d4a974 | 2018-02-17 13:06:37 +0000 | [diff] [blame] | 427 | // Verify location list. |
| 428 | if (auto DebugLoc = DCtx.getDebugLoc()) |
| 429 | if (auto LocList = DebugLoc->getLocationListAtOffset(*LocOffset)) |
| 430 | for (const auto &Entry : LocList->Entries) |
Jonas Devlieghere | 7e0b023 | 2018-05-22 17:37:27 +0000 | [diff] [blame^] | 431 | VerifyLocationExpr({Entry.Loc.data(), Entry.Loc.size()}); |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 432 | } |
George Rimar | 144e4c5 | 2017-10-27 10:42:04 +0000 | [diff] [blame] | 433 | break; |
| 434 | } |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 435 | |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 436 | default: |
| 437 | break; |
| 438 | } |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 439 | return NumErrors; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 440 | } |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 441 | |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 442 | unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die, |
| 443 | DWARFAttribute &AttrValue) { |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 444 | const DWARFObject &DObj = DCtx.getDWARFObj(); |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 445 | unsigned NumErrors = 0; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 446 | const auto Form = AttrValue.Value.getForm(); |
| 447 | switch (Form) { |
| 448 | case DW_FORM_ref1: |
| 449 | case DW_FORM_ref2: |
| 450 | case DW_FORM_ref4: |
| 451 | case DW_FORM_ref8: |
| 452 | case DW_FORM_ref_udata: { |
| 453 | // Verify all CU relative references are valid CU offsets. |
| 454 | Optional<uint64_t> RefVal = AttrValue.Value.getAsReference(); |
| 455 | assert(RefVal); |
| 456 | if (RefVal) { |
| 457 | auto DieCU = Die.getDwarfUnit(); |
| 458 | auto CUSize = DieCU->getNextUnitOffset() - DieCU->getOffset(); |
| 459 | auto CUOffset = AttrValue.Value.getRawUValue(); |
| 460 | if (CUOffset >= CUSize) { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 461 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 462 | error() << FormEncodingString(Form) << " CU offset " |
| 463 | << format("0x%08" PRIx64, CUOffset) |
| 464 | << " is invalid (must be less than CU size of " |
| 465 | << format("0x%08" PRIx32, CUSize) << "):\n"; |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 466 | Die.dump(OS, 0, DumpOpts); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 467 | OS << "\n"; |
| 468 | } else { |
| 469 | // Valid reference, but we will verify it points to an actual |
| 470 | // DIE later. |
| 471 | ReferenceToDIEOffsets[*RefVal].insert(Die.getOffset()); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 472 | } |
| 473 | } |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 474 | break; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 475 | } |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 476 | case DW_FORM_ref_addr: { |
| 477 | // Verify all absolute DIE references have valid offsets in the |
| 478 | // .debug_info section. |
| 479 | Optional<uint64_t> RefVal = AttrValue.Value.getAsReference(); |
| 480 | assert(RefVal); |
| 481 | if (RefVal) { |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 482 | if (*RefVal >= DObj.getInfoSection().Data.size()) { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 483 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 484 | error() << "DW_FORM_ref_addr offset beyond .debug_info " |
| 485 | "bounds:\n"; |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 486 | Die.dump(OS, 0, DumpOpts); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 487 | OS << "\n"; |
| 488 | } else { |
| 489 | // Valid reference, but we will verify it points to an actual |
| 490 | // DIE later. |
| 491 | ReferenceToDIEOffsets[*RefVal].insert(Die.getOffset()); |
| 492 | } |
| 493 | } |
| 494 | break; |
| 495 | } |
| 496 | case DW_FORM_strp: { |
| 497 | auto SecOffset = AttrValue.Value.getAsSectionOffset(); |
| 498 | assert(SecOffset); // DW_FORM_strp is a section offset. |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 499 | if (SecOffset && *SecOffset >= DObj.getStringSection().size()) { |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 500 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 501 | error() << "DW_FORM_strp offset beyond .debug_str bounds:\n"; |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 502 | Die.dump(OS, 0, DumpOpts); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 503 | OS << "\n"; |
| 504 | } |
| 505 | break; |
| 506 | } |
| 507 | default: |
| 508 | break; |
| 509 | } |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 510 | return NumErrors; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 511 | } |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 512 | |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 513 | unsigned DWARFVerifier::verifyDebugInfoReferences() { |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 514 | // Take all references and make sure they point to an actual DIE by |
| 515 | // getting the DIE by offset and emitting an error |
| 516 | OS << "Verifying .debug_info references...\n"; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 517 | unsigned NumErrors = 0; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 518 | for (auto Pair : ReferenceToDIEOffsets) { |
| 519 | auto Die = DCtx.getDIEForOffset(Pair.first); |
| 520 | if (Die) |
| 521 | continue; |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 522 | ++NumErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 523 | error() << "invalid DIE reference " << format("0x%08" PRIx64, Pair.first) |
| 524 | << ". Offset is in between DIEs:\n"; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 525 | for (auto Offset : Pair.second) { |
| 526 | auto ReferencingDie = DCtx.getDIEForOffset(Offset); |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 527 | ReferencingDie.dump(OS, 0, DumpOpts); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 528 | OS << "\n"; |
| 529 | } |
| 530 | OS << "\n"; |
| 531 | } |
Spyridoula Gravani | f6bd788d | 2017-07-18 01:00:26 +0000 | [diff] [blame] | 532 | return NumErrors; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 535 | void DWARFVerifier::verifyDebugLineStmtOffsets() { |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 536 | std::map<uint64_t, DWARFDie> StmtListToDie; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 537 | for (const auto &CU : DCtx.compile_units()) { |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 538 | auto Die = CU->getUnitDIE(); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 539 | // Get the attribute value as a section offset. No need to produce an |
| 540 | // error here if the encoding isn't correct because we validate this in |
| 541 | // the .debug_info verifier. |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 542 | auto StmtSectionOffset = toSectionOffset(Die.find(DW_AT_stmt_list)); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 543 | if (!StmtSectionOffset) |
| 544 | continue; |
| 545 | const uint32_t LineTableOffset = *StmtSectionOffset; |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 546 | auto LineTable = DCtx.getLineTableForUnit(CU.get()); |
Rafael Espindola | c398e67 | 2017-07-19 22:27:28 +0000 | [diff] [blame] | 547 | if (LineTableOffset < DCtx.getDWARFObj().getLineSection().Data.size()) { |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 548 | if (!LineTable) { |
| 549 | ++NumDebugLineErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 550 | error() << ".debug_line[" << format("0x%08" PRIx32, LineTableOffset) |
| 551 | << "] was not able to be parsed for CU:\n"; |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 552 | Die.dump(OS, 0, DumpOpts); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 553 | OS << '\n'; |
| 554 | continue; |
| 555 | } |
| 556 | } else { |
| 557 | // Make sure we don't get a valid line table back if the offset is wrong. |
| 558 | assert(LineTable == nullptr); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 559 | // Skip this line table as it isn't valid. No need to create an error |
| 560 | // here because we validate this in the .debug_info verifier. |
| 561 | continue; |
| 562 | } |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 563 | auto Iter = StmtListToDie.find(LineTableOffset); |
| 564 | if (Iter != StmtListToDie.end()) { |
| 565 | ++NumDebugLineErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 566 | error() << "two compile unit DIEs, " |
| 567 | << format("0x%08" PRIx32, Iter->second.getOffset()) << " and " |
| 568 | << format("0x%08" PRIx32, Die.getOffset()) |
| 569 | << ", have the same DW_AT_stmt_list section offset:\n"; |
Adrian Prantl | d3f9f21 | 2017-09-20 17:44:00 +0000 | [diff] [blame] | 570 | Iter->second.dump(OS, 0, DumpOpts); |
| 571 | Die.dump(OS, 0, DumpOpts); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 572 | OS << '\n'; |
| 573 | // Already verified this line table before, no need to do it again. |
| 574 | continue; |
| 575 | } |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 576 | StmtListToDie[LineTableOffset] = Die; |
| 577 | } |
| 578 | } |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 579 | |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 580 | void DWARFVerifier::verifyDebugLineRows() { |
| 581 | for (const auto &CU : DCtx.compile_units()) { |
| 582 | auto Die = CU->getUnitDIE(); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 583 | auto LineTable = DCtx.getLineTableForUnit(CU.get()); |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 584 | // If there is no line table we will have created an error in the |
| 585 | // .debug_info verifier or in verifyDebugLineStmtOffsets(). |
| 586 | if (!LineTable) |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 587 | continue; |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 588 | |
| 589 | // Verify prologue. |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 590 | uint32_t MaxFileIndex = LineTable->Prologue.FileNames.size(); |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 591 | uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size(); |
| 592 | uint32_t FileIndex = 1; |
| 593 | StringMap<uint16_t> FullPathMap; |
| 594 | for (const auto &FileName : LineTable->Prologue.FileNames) { |
| 595 | // Verify directory index. |
| 596 | if (FileName.DirIdx > MaxDirIndex) { |
| 597 | ++NumDebugLineErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 598 | error() << ".debug_line[" |
| 599 | << format("0x%08" PRIx64, |
| 600 | *toSectionOffset(Die.find(DW_AT_stmt_list))) |
| 601 | << "].prologue.file_names[" << FileIndex |
| 602 | << "].dir_idx contains an invalid index: " << FileName.DirIdx |
| 603 | << "\n"; |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | // Check file paths for duplicates. |
| 607 | std::string FullPath; |
| 608 | const bool HasFullPath = LineTable->getFileNameByIndex( |
| 609 | FileIndex, CU->getCompilationDir(), |
| 610 | DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FullPath); |
| 611 | assert(HasFullPath && "Invalid index?"); |
| 612 | (void)HasFullPath; |
| 613 | auto It = FullPathMap.find(FullPath); |
| 614 | if (It == FullPathMap.end()) |
| 615 | FullPathMap[FullPath] = FileIndex; |
| 616 | else if (It->second != FileIndex) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 617 | warn() << ".debug_line[" |
| 618 | << format("0x%08" PRIx64, |
| 619 | *toSectionOffset(Die.find(DW_AT_stmt_list))) |
| 620 | << "].prologue.file_names[" << FileIndex |
| 621 | << "] is a duplicate of file_names[" << It->second << "]\n"; |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | FileIndex++; |
| 625 | } |
| 626 | |
| 627 | // Verify rows. |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 628 | uint64_t PrevAddress = 0; |
| 629 | uint32_t RowIndex = 0; |
| 630 | for (const auto &Row : LineTable->Rows) { |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 631 | // Verify row address. |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 632 | if (Row.Address < PrevAddress) { |
| 633 | ++NumDebugLineErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 634 | error() << ".debug_line[" |
| 635 | << format("0x%08" PRIx64, |
| 636 | *toSectionOffset(Die.find(DW_AT_stmt_list))) |
| 637 | << "] row[" << RowIndex |
| 638 | << "] decreases in address from previous row:\n"; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 639 | |
| 640 | DWARFDebugLine::Row::dumpTableHeader(OS); |
| 641 | if (RowIndex > 0) |
| 642 | LineTable->Rows[RowIndex - 1].dump(OS); |
| 643 | Row.dump(OS); |
| 644 | OS << '\n'; |
| 645 | } |
| 646 | |
Jonas Devlieghere | f4ed65d | 2017-09-08 09:48:51 +0000 | [diff] [blame] | 647 | // Verify file index. |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 648 | if (Row.File > MaxFileIndex) { |
| 649 | ++NumDebugLineErrors; |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 650 | error() << ".debug_line[" |
| 651 | << format("0x%08" PRIx64, |
| 652 | *toSectionOffset(Die.find(DW_AT_stmt_list))) |
| 653 | << "][" << RowIndex << "] has invalid file index " << Row.File |
| 654 | << " (valid values are [1," << MaxFileIndex << "]):\n"; |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 655 | DWARFDebugLine::Row::dumpTableHeader(OS); |
| 656 | Row.dump(OS); |
| 657 | OS << '\n'; |
| 658 | } |
| 659 | if (Row.EndSequence) |
| 660 | PrevAddress = 0; |
| 661 | else |
| 662 | PrevAddress = Row.Address; |
| 663 | ++RowIndex; |
| 664 | } |
| 665 | } |
Greg Clayton | c5b2d56 | 2017-05-03 18:25:46 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | bool DWARFVerifier::handleDebugLine() { |
| 669 | NumDebugLineErrors = 0; |
| 670 | OS << "Verifying .debug_line...\n"; |
| 671 | verifyDebugLineStmtOffsets(); |
| 672 | verifyDebugLineRows(); |
Greg Clayton | b8c162b | 2017-05-03 16:02:29 +0000 | [diff] [blame] | 673 | return NumDebugLineErrors == 0; |
| 674 | } |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 675 | |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 676 | unsigned DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection, |
| 677 | DataExtractor *StrData, |
| 678 | const char *SectionName) { |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 679 | unsigned NumErrors = 0; |
| 680 | DWARFDataExtractor AccelSectionData(DCtx.getDWARFObj(), *AccelSection, |
| 681 | DCtx.isLittleEndian(), 0); |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 682 | AppleAcceleratorTable AccelTable(AccelSectionData, *StrData); |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 683 | |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 684 | OS << "Verifying " << SectionName << "...\n"; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 685 | |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 686 | // Verify that the fixed part of the header is not too short. |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 687 | if (!AccelSectionData.isValidOffset(AccelTable.getSizeHdr())) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 688 | error() << "Section is too small to fit a section header.\n"; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 689 | return 1; |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 690 | } |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 691 | |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 692 | // Verify that the section is not too short. |
Jonas Devlieghere | ba91589 | 2017-12-11 18:22:47 +0000 | [diff] [blame] | 693 | if (Error E = AccelTable.extract()) { |
| 694 | error() << toString(std::move(E)) << '\n'; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 695 | return 1; |
| 696 | } |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 697 | |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 698 | // Verify that all buckets have a valid hash index or are empty. |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 699 | uint32_t NumBuckets = AccelTable.getNumBuckets(); |
| 700 | uint32_t NumHashes = AccelTable.getNumHashes(); |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 701 | |
| 702 | uint32_t BucketsOffset = |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 703 | AccelTable.getSizeHdr() + AccelTable.getHeaderDataLength(); |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 704 | uint32_t HashesBase = BucketsOffset + NumBuckets * 4; |
| 705 | uint32_t OffsetsBase = HashesBase + NumHashes * 4; |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 706 | for (uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) { |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 707 | uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset); |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 708 | if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 709 | error() << format("Bucket[%d] has invalid hash index: %u.\n", BucketIdx, |
| 710 | HashIdx); |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 711 | ++NumErrors; |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 714 | uint32_t NumAtoms = AccelTable.getAtomsDesc().size(); |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 715 | if (NumAtoms == 0) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 716 | error() << "No atoms: failed to read HashData.\n"; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 717 | return 1; |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 718 | } |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 719 | if (!AccelTable.validateForms()) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 720 | error() << "Unsupported form: failed to read HashData.\n"; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 721 | return 1; |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | for (uint32_t HashIdx = 0; HashIdx < NumHashes; ++HashIdx) { |
| 725 | uint32_t HashOffset = HashesBase + 4 * HashIdx; |
| 726 | uint32_t DataOffset = OffsetsBase + 4 * HashIdx; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 727 | uint32_t Hash = AccelSectionData.getU32(&HashOffset); |
| 728 | uint32_t HashDataOffset = AccelSectionData.getU32(&DataOffset); |
| 729 | if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset, |
| 730 | sizeof(uint64_t))) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 731 | error() << format("Hash[%d] has invalid HashData offset: 0x%08x.\n", |
| 732 | HashIdx, HashDataOffset); |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 733 | ++NumErrors; |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | uint32_t StrpOffset; |
| 737 | uint32_t StringOffset; |
| 738 | uint32_t StringCount = 0; |
Spyridoula Gravani | 70d35e1 | 2017-07-31 18:01:16 +0000 | [diff] [blame] | 739 | unsigned Offset; |
| 740 | unsigned Tag; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 741 | while ((StrpOffset = AccelSectionData.getU32(&HashDataOffset)) != 0) { |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 742 | const uint32_t NumHashDataObjects = |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 743 | AccelSectionData.getU32(&HashDataOffset); |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 744 | for (uint32_t HashDataIdx = 0; HashDataIdx < NumHashDataObjects; |
| 745 | ++HashDataIdx) { |
Spyridoula Gravani | 70d35e1 | 2017-07-31 18:01:16 +0000 | [diff] [blame] | 746 | std::tie(Offset, Tag) = AccelTable.readAtoms(HashDataOffset); |
| 747 | auto Die = DCtx.getDIEForOffset(Offset); |
| 748 | if (!Die) { |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 749 | const uint32_t BucketIdx = |
| 750 | NumBuckets ? (Hash % NumBuckets) : UINT32_MAX; |
| 751 | StringOffset = StrpOffset; |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 752 | const char *Name = StrData->getCStr(&StringOffset); |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 753 | if (!Name) |
| 754 | Name = "<NULL>"; |
| 755 | |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 756 | error() << format( |
| 757 | "%s Bucket[%d] Hash[%d] = 0x%08x " |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 758 | "Str[%u] = 0x%08x " |
| 759 | "DIE[%d] = 0x%08x is not a valid DIE offset for \"%s\".\n", |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 760 | SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset, |
Spyridoula Gravani | 70d35e1 | 2017-07-31 18:01:16 +0000 | [diff] [blame] | 761 | HashDataIdx, Offset, Name); |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 762 | |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 763 | ++NumErrors; |
Spyridoula Gravani | 70d35e1 | 2017-07-31 18:01:16 +0000 | [diff] [blame] | 764 | continue; |
| 765 | } |
| 766 | if ((Tag != dwarf::DW_TAG_null) && (Die.getTag() != Tag)) { |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 767 | error() << "Tag " << dwarf::TagString(Tag) |
| 768 | << " in accelerator table does not match Tag " |
| 769 | << dwarf::TagString(Die.getTag()) << " of DIE[" << HashDataIdx |
| 770 | << "].\n"; |
Spyridoula Gravani | 70d35e1 | 2017-07-31 18:01:16 +0000 | [diff] [blame] | 771 | ++NumErrors; |
Spyridoula Gravani | 837c110 | 2017-06-29 20:13:05 +0000 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | ++StringCount; |
| 775 | } |
| 776 | } |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 777 | return NumErrors; |
| 778 | } |
| 779 | |
Pavel Labath | b136c39 | 2018-03-08 15:34:42 +0000 | [diff] [blame] | 780 | unsigned |
| 781 | DWARFVerifier::verifyDebugNamesCULists(const DWARFDebugNames &AccelTable) { |
| 782 | // A map from CU offset to the (first) Name Index offset which claims to index |
| 783 | // this CU. |
| 784 | DenseMap<uint32_t, uint32_t> CUMap; |
| 785 | const uint32_t NotIndexed = std::numeric_limits<uint32_t>::max(); |
| 786 | |
| 787 | CUMap.reserve(DCtx.getNumCompileUnits()); |
| 788 | for (const auto &CU : DCtx.compile_units()) |
| 789 | CUMap[CU->getOffset()] = NotIndexed; |
| 790 | |
| 791 | unsigned NumErrors = 0; |
| 792 | for (const DWARFDebugNames::NameIndex &NI : AccelTable) { |
| 793 | if (NI.getCUCount() == 0) { |
| 794 | error() << formatv("Name Index @ {0:x} does not index any CU\n", |
| 795 | NI.getUnitOffset()); |
| 796 | ++NumErrors; |
| 797 | continue; |
| 798 | } |
| 799 | for (uint32_t CU = 0, End = NI.getCUCount(); CU < End; ++CU) { |
| 800 | uint32_t Offset = NI.getCUOffset(CU); |
| 801 | auto Iter = CUMap.find(Offset); |
| 802 | |
| 803 | if (Iter == CUMap.end()) { |
| 804 | error() << formatv( |
| 805 | "Name Index @ {0:x} references a non-existing CU @ {1:x}\n", |
| 806 | NI.getUnitOffset(), Offset); |
| 807 | ++NumErrors; |
| 808 | continue; |
| 809 | } |
| 810 | |
| 811 | if (Iter->second != NotIndexed) { |
| 812 | error() << formatv("Name Index @ {0:x} references a CU @ {1:x}, but " |
| 813 | "this CU is already indexed by Name Index @ {2:x}\n", |
| 814 | NI.getUnitOffset(), Offset, Iter->second); |
| 815 | continue; |
| 816 | } |
| 817 | Iter->second = NI.getUnitOffset(); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | for (const auto &KV : CUMap) { |
| 822 | if (KV.second == NotIndexed) |
| 823 | warn() << formatv("CU @ {0:x} not covered by any Name Index\n", KV.first); |
| 824 | } |
| 825 | |
| 826 | return NumErrors; |
| 827 | } |
| 828 | |
Pavel Labath | 906b777 | 2018-03-16 10:02:16 +0000 | [diff] [blame] | 829 | unsigned |
| 830 | DWARFVerifier::verifyNameIndexBuckets(const DWARFDebugNames::NameIndex &NI, |
| 831 | const DataExtractor &StrData) { |
| 832 | struct BucketInfo { |
| 833 | uint32_t Bucket; |
| 834 | uint32_t Index; |
| 835 | |
| 836 | constexpr BucketInfo(uint32_t Bucket, uint32_t Index) |
| 837 | : Bucket(Bucket), Index(Index) {} |
| 838 | bool operator<(const BucketInfo &RHS) const { return Index < RHS.Index; }; |
| 839 | }; |
| 840 | |
| 841 | uint32_t NumErrors = 0; |
| 842 | if (NI.getBucketCount() == 0) { |
| 843 | warn() << formatv("Name Index @ {0:x} does not contain a hash table.\n", |
| 844 | NI.getUnitOffset()); |
| 845 | return NumErrors; |
| 846 | } |
| 847 | |
| 848 | // Build up a list of (Bucket, Index) pairs. We use this later to verify that |
| 849 | // each Name is reachable from the appropriate bucket. |
| 850 | std::vector<BucketInfo> BucketStarts; |
| 851 | BucketStarts.reserve(NI.getBucketCount() + 1); |
| 852 | for (uint32_t Bucket = 0, End = NI.getBucketCount(); Bucket < End; ++Bucket) { |
| 853 | uint32_t Index = NI.getBucketArrayEntry(Bucket); |
| 854 | if (Index > NI.getNameCount()) { |
| 855 | error() << formatv("Bucket {0} of Name Index @ {1:x} contains invalid " |
| 856 | "value {2}. Valid range is [0, {3}].\n", |
| 857 | Bucket, NI.getUnitOffset(), Index, NI.getNameCount()); |
| 858 | ++NumErrors; |
| 859 | continue; |
| 860 | } |
| 861 | if (Index > 0) |
| 862 | BucketStarts.emplace_back(Bucket, Index); |
| 863 | } |
| 864 | |
| 865 | // If there were any buckets with invalid values, skip further checks as they |
| 866 | // will likely produce many errors which will only confuse the actual root |
| 867 | // problem. |
| 868 | if (NumErrors > 0) |
| 869 | return NumErrors; |
| 870 | |
| 871 | // Sort the list in the order of increasing "Index" entries. |
| 872 | array_pod_sort(BucketStarts.begin(), BucketStarts.end()); |
| 873 | |
| 874 | // Insert a sentinel entry at the end, so we can check that the end of the |
| 875 | // table is covered in the loop below. |
| 876 | BucketStarts.emplace_back(NI.getBucketCount(), NI.getNameCount() + 1); |
| 877 | |
| 878 | // Loop invariant: NextUncovered is the (1-based) index of the first Name |
| 879 | // which is not reachable by any of the buckets we processed so far (and |
| 880 | // hasn't been reported as uncovered). |
| 881 | uint32_t NextUncovered = 1; |
| 882 | for (const BucketInfo &B : BucketStarts) { |
| 883 | // Under normal circumstances B.Index be equal to NextUncovered, but it can |
| 884 | // be less if a bucket points to names which are already known to be in some |
| 885 | // bucket we processed earlier. In that case, we won't trigger this error, |
| 886 | // but report the mismatched hash value error instead. (We know the hash |
| 887 | // will not match because we have already verified that the name's hash |
| 888 | // puts it into the previous bucket.) |
| 889 | if (B.Index > NextUncovered) { |
| 890 | error() << formatv("Name Index @ {0:x}: Name table entries [{1}, {2}] " |
| 891 | "are not covered by the hash table.\n", |
| 892 | NI.getUnitOffset(), NextUncovered, B.Index - 1); |
| 893 | ++NumErrors; |
| 894 | } |
| 895 | uint32_t Idx = B.Index; |
| 896 | |
| 897 | // The rest of the checks apply only to non-sentinel entries. |
| 898 | if (B.Bucket == NI.getBucketCount()) |
| 899 | break; |
| 900 | |
| 901 | // This triggers if a non-empty bucket points to a name with a mismatched |
| 902 | // hash. Clients are likely to interpret this as an empty bucket, because a |
| 903 | // mismatched hash signals the end of a bucket, but if this is indeed an |
| 904 | // empty bucket, the producer should have signalled this by marking the |
| 905 | // bucket as empty. |
| 906 | uint32_t FirstHash = NI.getHashArrayEntry(Idx); |
| 907 | if (FirstHash % NI.getBucketCount() != B.Bucket) { |
| 908 | error() << formatv( |
| 909 | "Name Index @ {0:x}: Bucket {1} is not empty but points to a " |
| 910 | "mismatched hash value {2:x} (belonging to bucket {3}).\n", |
| 911 | NI.getUnitOffset(), B.Bucket, FirstHash, |
| 912 | FirstHash % NI.getBucketCount()); |
| 913 | ++NumErrors; |
| 914 | } |
| 915 | |
| 916 | // This find the end of this bucket and also verifies that all the hashes in |
| 917 | // this bucket are correct by comparing the stored hashes to the ones we |
| 918 | // compute ourselves. |
| 919 | while (Idx <= NI.getNameCount()) { |
| 920 | uint32_t Hash = NI.getHashArrayEntry(Idx); |
| 921 | if (Hash % NI.getBucketCount() != B.Bucket) |
| 922 | break; |
| 923 | |
| 924 | auto NTE = NI.getNameTableEntry(Idx); |
| 925 | const char *Str = StrData.getCStr(&NTE.StringOffset); |
| 926 | if (caseFoldingDjbHash(Str) != Hash) { |
| 927 | error() << formatv("Name Index @ {0:x}: String ({1}) at index {2} " |
| 928 | "hashes to {3:x}, but " |
| 929 | "the Name Index hash is {4:x}\n", |
| 930 | NI.getUnitOffset(), Str, Idx, |
| 931 | caseFoldingDjbHash(Str), Hash); |
| 932 | ++NumErrors; |
| 933 | } |
| 934 | |
| 935 | ++Idx; |
| 936 | } |
| 937 | NextUncovered = std::max(NextUncovered, Idx); |
| 938 | } |
| 939 | return NumErrors; |
| 940 | } |
| 941 | |
Pavel Labath | 79cd942 | 2018-03-22 14:50:44 +0000 | [diff] [blame] | 942 | unsigned DWARFVerifier::verifyNameIndexAttribute( |
| 943 | const DWARFDebugNames::NameIndex &NI, const DWARFDebugNames::Abbrev &Abbr, |
| 944 | DWARFDebugNames::AttributeEncoding AttrEnc) { |
| 945 | StringRef FormName = dwarf::FormEncodingString(AttrEnc.Form); |
| 946 | if (FormName.empty()) { |
| 947 | error() << formatv("NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " |
| 948 | "unknown form: {3}.\n", |
| 949 | NI.getUnitOffset(), Abbr.Code, AttrEnc.Index, |
| 950 | AttrEnc.Form); |
| 951 | return 1; |
| 952 | } |
| 953 | |
| 954 | if (AttrEnc.Index == DW_IDX_type_hash) { |
| 955 | if (AttrEnc.Form != dwarf::DW_FORM_data8) { |
| 956 | error() << formatv( |
| 957 | "NameIndex @ {0:x}: Abbreviation {1:x}: DW_IDX_type_hash " |
| 958 | "uses an unexpected form {2} (should be {3}).\n", |
| 959 | NI.getUnitOffset(), Abbr.Code, AttrEnc.Form, dwarf::DW_FORM_data8); |
| 960 | return 1; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | // A list of known index attributes and their expected form classes. |
| 965 | // DW_IDX_type_hash is handled specially in the check above, as it has a |
| 966 | // specific form (not just a form class) we should expect. |
| 967 | struct FormClassTable { |
| 968 | dwarf::Index Index; |
| 969 | DWARFFormValue::FormClass Class; |
| 970 | StringLiteral ClassName; |
| 971 | }; |
| 972 | static constexpr FormClassTable Table[] = { |
| 973 | {dwarf::DW_IDX_compile_unit, DWARFFormValue::FC_Constant, {"constant"}}, |
| 974 | {dwarf::DW_IDX_type_unit, DWARFFormValue::FC_Constant, {"constant"}}, |
| 975 | {dwarf::DW_IDX_die_offset, DWARFFormValue::FC_Reference, {"reference"}}, |
| 976 | {dwarf::DW_IDX_parent, DWARFFormValue::FC_Constant, {"constant"}}, |
| 977 | }; |
| 978 | |
| 979 | ArrayRef<FormClassTable> TableRef(Table); |
| 980 | auto Iter = find_if(TableRef, [AttrEnc](const FormClassTable &T) { |
| 981 | return T.Index == AttrEnc.Index; |
| 982 | }); |
| 983 | if (Iter == TableRef.end()) { |
| 984 | warn() << formatv("NameIndex @ {0:x}: Abbreviation {1:x} contains an " |
| 985 | "unknown index attribute: {2}.\n", |
| 986 | NI.getUnitOffset(), Abbr.Code, AttrEnc.Index); |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | if (!DWARFFormValue(AttrEnc.Form).isFormClass(Iter->Class)) { |
| 991 | error() << formatv("NameIndex @ {0:x}: Abbreviation {1:x}: {2} uses an " |
| 992 | "unexpected form {3} (expected form class {4}).\n", |
| 993 | NI.getUnitOffset(), Abbr.Code, AttrEnc.Index, |
| 994 | AttrEnc.Form, Iter->ClassName); |
| 995 | return 1; |
| 996 | } |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | unsigned |
| 1001 | DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) { |
Pavel Labath | c9f07b0 | 2018-04-06 13:34:12 +0000 | [diff] [blame] | 1002 | if (NI.getLocalTUCount() + NI.getForeignTUCount() > 0) { |
| 1003 | warn() << formatv("Name Index @ {0:x}: Verifying indexes of type units is " |
| 1004 | "not currently supported.\n", |
| 1005 | NI.getUnitOffset()); |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
Pavel Labath | 79cd942 | 2018-03-22 14:50:44 +0000 | [diff] [blame] | 1009 | unsigned NumErrors = 0; |
| 1010 | for (const auto &Abbrev : NI.getAbbrevs()) { |
| 1011 | StringRef TagName = dwarf::TagString(Abbrev.Tag); |
| 1012 | if (TagName.empty()) { |
| 1013 | warn() << formatv("NameIndex @ {0:x}: Abbreviation {1:x} references an " |
| 1014 | "unknown tag: {2}.\n", |
| 1015 | NI.getUnitOffset(), Abbrev.Code, Abbrev.Tag); |
| 1016 | } |
| 1017 | SmallSet<unsigned, 5> Attributes; |
| 1018 | for (const auto &AttrEnc : Abbrev.Attributes) { |
| 1019 | if (!Attributes.insert(AttrEnc.Index).second) { |
| 1020 | error() << formatv("NameIndex @ {0:x}: Abbreviation {1:x} contains " |
| 1021 | "multiple {2} attributes.\n", |
| 1022 | NI.getUnitOffset(), Abbrev.Code, AttrEnc.Index); |
| 1023 | ++NumErrors; |
| 1024 | continue; |
| 1025 | } |
| 1026 | NumErrors += verifyNameIndexAttribute(NI, Abbrev, AttrEnc); |
| 1027 | } |
Pavel Labath | c9f07b0 | 2018-04-06 13:34:12 +0000 | [diff] [blame] | 1028 | |
| 1029 | if (NI.getCUCount() > 1 && !Attributes.count(dwarf::DW_IDX_compile_unit)) { |
| 1030 | error() << formatv("NameIndex @ {0:x}: Indexing multiple compile units " |
| 1031 | "and abbreviation {1:x} has no {2} attribute.\n", |
| 1032 | NI.getUnitOffset(), Abbrev.Code, |
| 1033 | dwarf::DW_IDX_compile_unit); |
| 1034 | ++NumErrors; |
| 1035 | } |
| 1036 | if (!Attributes.count(dwarf::DW_IDX_die_offset)) { |
| 1037 | error() << formatv( |
| 1038 | "NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n", |
| 1039 | NI.getUnitOffset(), Abbrev.Code, dwarf::DW_IDX_die_offset); |
| 1040 | ++NumErrors; |
| 1041 | } |
Pavel Labath | 79cd942 | 2018-03-22 14:50:44 +0000 | [diff] [blame] | 1042 | } |
| 1043 | return NumErrors; |
| 1044 | } |
| 1045 | |
Pavel Labath | c9f07b0 | 2018-04-06 13:34:12 +0000 | [diff] [blame] | 1046 | static SmallVector<StringRef, 2> getNames(const DWARFDie &DIE) { |
| 1047 | SmallVector<StringRef, 2> Result; |
| 1048 | if (const char *Str = DIE.getName(DINameKind::ShortName)) |
| 1049 | Result.emplace_back(Str); |
| 1050 | else if (DIE.getTag() == dwarf::DW_TAG_namespace) |
| 1051 | Result.emplace_back("(anonymous namespace)"); |
| 1052 | |
| 1053 | if (const char *Str = DIE.getName(DINameKind::LinkageName)) { |
| 1054 | if (Result.empty() || Result[0] != Str) |
| 1055 | Result.emplace_back(Str); |
| 1056 | } |
| 1057 | |
| 1058 | return Result; |
| 1059 | } |
| 1060 | |
| 1061 | unsigned |
| 1062 | DWARFVerifier::verifyNameIndexEntries(const DWARFDebugNames::NameIndex &NI, |
| 1063 | uint32_t Name, |
| 1064 | const DataExtractor &StrData) { |
| 1065 | // Verifying type unit indexes not supported. |
| 1066 | if (NI.getLocalTUCount() + NI.getForeignTUCount() > 0) |
| 1067 | return 0; |
| 1068 | |
| 1069 | DWARFDebugNames::NameTableEntry NTE = NI.getNameTableEntry(Name); |
| 1070 | const char *CStr = StrData.getCStr(&NTE.StringOffset); |
| 1071 | if (!CStr) { |
| 1072 | error() << formatv( |
| 1073 | "Name Index @ {0:x}: Unable to get string associated with name {1}.\n", |
| 1074 | NI.getUnitOffset(), Name); |
| 1075 | return 1; |
| 1076 | } |
| 1077 | StringRef Str(CStr); |
| 1078 | |
| 1079 | unsigned NumErrors = 0; |
| 1080 | unsigned NumEntries = 0; |
| 1081 | uint32_t EntryID = NTE.EntryOffset; |
| 1082 | Expected<DWARFDebugNames::Entry> EntryOr = NI.getEntry(&NTE.EntryOffset); |
| 1083 | for (; EntryOr; ++NumEntries, EntryID = NTE.EntryOffset, |
| 1084 | EntryOr = NI.getEntry(&NTE.EntryOffset)) { |
| 1085 | uint32_t CUIndex = *EntryOr->getCUIndex(); |
| 1086 | if (CUIndex > NI.getCUCount()) { |
| 1087 | error() << formatv("Name Index @ {0:x}: Entry @ {1:x} contains an " |
| 1088 | "invalid CU index ({2}).\n", |
| 1089 | NI.getUnitOffset(), EntryID, CUIndex); |
| 1090 | ++NumErrors; |
| 1091 | continue; |
| 1092 | } |
| 1093 | uint32_t CUOffset = NI.getCUOffset(CUIndex); |
| 1094 | uint64_t DIEOffset = *EntryOr->getDIESectionOffset(); |
| 1095 | DWARFDie DIE = DCtx.getDIEForOffset(DIEOffset); |
| 1096 | if (!DIE) { |
| 1097 | error() << formatv("Name Index @ {0:x}: Entry @ {1:x} references a " |
| 1098 | "non-existing DIE @ {2:x}.\n", |
| 1099 | NI.getUnitOffset(), EntryID, DIEOffset); |
| 1100 | ++NumErrors; |
| 1101 | continue; |
| 1102 | } |
| 1103 | if (DIE.getDwarfUnit()->getOffset() != CUOffset) { |
| 1104 | error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of " |
| 1105 | "DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n", |
| 1106 | NI.getUnitOffset(), EntryID, DIEOffset, CUOffset, |
| 1107 | DIE.getDwarfUnit()->getOffset()); |
| 1108 | ++NumErrors; |
| 1109 | } |
| 1110 | if (DIE.getTag() != EntryOr->tag()) { |
| 1111 | error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of " |
| 1112 | "DIE @ {2:x}: index - {3}; debug_info - {4}.\n", |
| 1113 | NI.getUnitOffset(), EntryID, DIEOffset, EntryOr->tag(), |
| 1114 | DIE.getTag()); |
| 1115 | ++NumErrors; |
| 1116 | } |
| 1117 | |
| 1118 | auto EntryNames = getNames(DIE); |
| 1119 | if (!is_contained(EntryNames, Str)) { |
| 1120 | error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Name " |
| 1121 | "of DIE @ {2:x}: index - {3}; debug_info - {4}.\n", |
| 1122 | NI.getUnitOffset(), EntryID, DIEOffset, Str, |
| 1123 | make_range(EntryNames.begin(), EntryNames.end())); |
Pavel Labath | 2a6afe5 | 2018-05-14 14:13:20 +0000 | [diff] [blame] | 1124 | ++NumErrors; |
Pavel Labath | c9f07b0 | 2018-04-06 13:34:12 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | handleAllErrors(EntryOr.takeError(), |
| 1128 | [&](const DWARFDebugNames::SentinelError &) { |
| 1129 | if (NumEntries > 0) |
| 1130 | return; |
| 1131 | error() << formatv("Name Index @ {0:x}: Name {1} ({2}) is " |
| 1132 | "not associated with any entries.\n", |
| 1133 | NI.getUnitOffset(), Name, Str); |
| 1134 | ++NumErrors; |
| 1135 | }, |
| 1136 | [&](const ErrorInfoBase &Info) { |
| 1137 | error() << formatv( |
| 1138 | "Name Index @ {0:x}: Name {1} ({2}): {3}\n", |
| 1139 | NI.getUnitOffset(), Name, Str, Info.message()); |
| 1140 | ++NumErrors; |
| 1141 | }); |
| 1142 | return NumErrors; |
| 1143 | } |
| 1144 | |
Pavel Labath | 80827f1 | 2018-05-15 13:24:10 +0000 | [diff] [blame] | 1145 | static bool isVariableIndexable(const DWARFDie &Die, DWARFContext &DCtx) { |
| 1146 | Optional<DWARFFormValue> Location = Die.findRecursively(DW_AT_location); |
| 1147 | if (!Location) |
| 1148 | return false; |
| 1149 | |
| 1150 | auto ContainsInterestingOperators = [&](StringRef D) { |
| 1151 | DWARFUnit *U = Die.getDwarfUnit(); |
| 1152 | DataExtractor Data(D, DCtx.isLittleEndian(), U->getAddressByteSize()); |
| 1153 | DWARFExpression Expression(Data, U->getVersion(), U->getAddressByteSize()); |
| 1154 | return any_of(Expression, [](DWARFExpression::Operation &Op) { |
| 1155 | return !Op.isError() && (Op.getCode() == DW_OP_addr || |
| 1156 | Op.getCode() == DW_OP_form_tls_address || |
| 1157 | Op.getCode() == DW_OP_GNU_push_tls_address); |
| 1158 | }); |
| 1159 | }; |
| 1160 | |
| 1161 | if (Optional<ArrayRef<uint8_t>> Expr = Location->getAsBlock()) { |
| 1162 | // Inlined location. |
| 1163 | if (ContainsInterestingOperators(toStringRef(*Expr))) |
| 1164 | return true; |
| 1165 | } else if (Optional<uint64_t> Offset = Location->getAsSectionOffset()) { |
| 1166 | // Location list. |
| 1167 | if (const DWARFDebugLoc *DebugLoc = DCtx.getDebugLoc()) { |
| 1168 | if (const DWARFDebugLoc::LocationList *LocList = |
| 1169 | DebugLoc->getLocationListAtOffset(*Offset)) { |
| 1170 | if (any_of(LocList->Entries, [&](const DWARFDebugLoc::Entry &E) { |
| 1171 | return ContainsInterestingOperators({E.Loc.data(), E.Loc.size()}); |
| 1172 | })) |
| 1173 | return true; |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | return false; |
| 1178 | } |
| 1179 | |
| 1180 | unsigned DWARFVerifier::verifyNameIndexCompleteness( |
| 1181 | const DWARFDie &Die, const DWARFDebugNames::NameIndex &NI) { |
| 1182 | |
| 1183 | // First check, if the Die should be indexed. The code follows the DWARF v5 |
| 1184 | // wording as closely as possible. |
| 1185 | |
| 1186 | // "All non-defining declarations (that is, debugging information entries |
| 1187 | // with a DW_AT_declaration attribute) are excluded." |
| 1188 | if (Die.find(DW_AT_declaration)) |
| 1189 | return 0; |
| 1190 | |
| 1191 | // "DW_TAG_namespace debugging information entries without a DW_AT_name |
| 1192 | // attribute are included with the name “(anonymous namespace)”. |
| 1193 | // All other debugging information entries without a DW_AT_name attribute |
| 1194 | // are excluded." |
| 1195 | // "If a subprogram or inlined subroutine is included, and has a |
| 1196 | // DW_AT_linkage_name attribute, there will be an additional index entry for |
| 1197 | // the linkage name." |
| 1198 | auto EntryNames = getNames(Die); |
| 1199 | if (EntryNames.empty()) |
| 1200 | return 0; |
| 1201 | |
| 1202 | // We deviate from the specification here, which says: |
| 1203 | // "The name index must contain an entry for each debugging information entry |
| 1204 | // that defines a named subprogram, label, variable, type, or namespace, |
| 1205 | // subject to ..." |
| 1206 | // Instead whitelisting all TAGs representing a "type" or a "subprogram", to |
| 1207 | // make sure we catch any missing items, we instead blacklist all TAGs that we |
| 1208 | // know shouldn't be indexed. |
| 1209 | switch (Die.getTag()) { |
| 1210 | // Compile unit has a name but it shouldn't be indexed. |
| 1211 | case DW_TAG_compile_unit: |
| 1212 | return 0; |
| 1213 | |
| 1214 | // Function and template parameters are not globally visible, so we shouldn't |
| 1215 | // index them. |
| 1216 | case DW_TAG_formal_parameter: |
| 1217 | case DW_TAG_template_value_parameter: |
| 1218 | case DW_TAG_template_type_parameter: |
| 1219 | case DW_TAG_GNU_template_parameter_pack: |
| 1220 | case DW_TAG_GNU_template_template_param: |
| 1221 | return 0; |
| 1222 | |
| 1223 | // Object members aren't globally visible. |
| 1224 | case DW_TAG_member: |
| 1225 | return 0; |
| 1226 | |
| 1227 | // According to a strict reading of the specification, enumerators should not |
| 1228 | // be indexed (and LLVM currently does not do that). However, this causes |
| 1229 | // problems for the debuggers, so we may need to reconsider this. |
| 1230 | case DW_TAG_enumerator: |
| 1231 | return 0; |
| 1232 | |
| 1233 | // Imported declarations should not be indexed according to the specification |
| 1234 | // and LLVM currently does not do that. |
| 1235 | case DW_TAG_imported_declaration: |
| 1236 | return 0; |
| 1237 | |
| 1238 | // "DW_TAG_subprogram, DW_TAG_inlined_subroutine, and DW_TAG_label debugging |
| 1239 | // information entries without an address attribute (DW_AT_low_pc, |
| 1240 | // DW_AT_high_pc, DW_AT_ranges, or DW_AT_entry_pc) are excluded." |
| 1241 | case DW_TAG_subprogram: |
| 1242 | case DW_TAG_inlined_subroutine: |
| 1243 | case DW_TAG_label: |
| 1244 | if (Die.findRecursively( |
| 1245 | {DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_entry_pc})) |
| 1246 | break; |
| 1247 | return 0; |
| 1248 | |
| 1249 | // "DW_TAG_variable debugging information entries with a DW_AT_location |
| 1250 | // attribute that includes a DW_OP_addr or DW_OP_form_tls_address operator are |
| 1251 | // included; otherwise, they are excluded." |
| 1252 | // |
| 1253 | // LLVM extension: We also add DW_OP_GNU_push_tls_address to this list. |
| 1254 | case DW_TAG_variable: |
| 1255 | if (isVariableIndexable(Die, DCtx)) |
| 1256 | break; |
| 1257 | return 0; |
| 1258 | |
| 1259 | default: |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | // Now we know that our Die should be present in the Index. Let's check if |
| 1264 | // that's the case. |
| 1265 | unsigned NumErrors = 0; |
| 1266 | for (StringRef Name : EntryNames) { |
| 1267 | if (none_of(NI.equal_range(Name), [&Die](const DWARFDebugNames::Entry &E) { |
| 1268 | return E.getDIESectionOffset() == uint64_t(Die.getOffset()); |
| 1269 | })) { |
| 1270 | error() << formatv("Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with " |
| 1271 | "name {3} missing.\n", |
| 1272 | NI.getUnitOffset(), Die.getOffset(), Die.getTag(), |
| 1273 | Name); |
| 1274 | ++NumErrors; |
| 1275 | } |
| 1276 | } |
| 1277 | return NumErrors; |
| 1278 | } |
| 1279 | |
Pavel Labath | b136c39 | 2018-03-08 15:34:42 +0000 | [diff] [blame] | 1280 | unsigned DWARFVerifier::verifyDebugNames(const DWARFSection &AccelSection, |
| 1281 | const DataExtractor &StrData) { |
| 1282 | unsigned NumErrors = 0; |
| 1283 | DWARFDataExtractor AccelSectionData(DCtx.getDWARFObj(), AccelSection, |
| 1284 | DCtx.isLittleEndian(), 0); |
| 1285 | DWARFDebugNames AccelTable(AccelSectionData, StrData); |
| 1286 | |
| 1287 | OS << "Verifying .debug_names...\n"; |
| 1288 | |
| 1289 | // This verifies that we can read individual name indices and their |
| 1290 | // abbreviation tables. |
| 1291 | if (Error E = AccelTable.extract()) { |
| 1292 | error() << toString(std::move(E)) << '\n'; |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | NumErrors += verifyDebugNamesCULists(AccelTable); |
Pavel Labath | 906b777 | 2018-03-16 10:02:16 +0000 | [diff] [blame] | 1297 | for (const auto &NI : AccelTable) |
| 1298 | NumErrors += verifyNameIndexBuckets(NI, StrData); |
Pavel Labath | 79cd942 | 2018-03-22 14:50:44 +0000 | [diff] [blame] | 1299 | for (const auto &NI : AccelTable) |
| 1300 | NumErrors += verifyNameIndexAbbrevs(NI); |
Pavel Labath | b136c39 | 2018-03-08 15:34:42 +0000 | [diff] [blame] | 1301 | |
Pavel Labath | c9f07b0 | 2018-04-06 13:34:12 +0000 | [diff] [blame] | 1302 | // Don't attempt Entry validation if any of the previous checks found errors |
| 1303 | if (NumErrors > 0) |
| 1304 | return NumErrors; |
| 1305 | for (const auto &NI : AccelTable) |
| 1306 | for (uint64_t Name = 1; Name <= NI.getNameCount(); ++Name) |
| 1307 | NumErrors += verifyNameIndexEntries(NI, Name, StrData); |
| 1308 | |
Pavel Labath | 80827f1 | 2018-05-15 13:24:10 +0000 | [diff] [blame] | 1309 | if (NumErrors > 0) |
| 1310 | return NumErrors; |
| 1311 | |
| 1312 | for (const std::unique_ptr<DWARFCompileUnit> &CU : DCtx.compile_units()) { |
| 1313 | if (const DWARFDebugNames::NameIndex *NI = |
| 1314 | AccelTable.getCUNameIndex(CU->getOffset())) { |
| 1315 | for (const DWARFDebugInfoEntry &Die : CU->dies()) |
| 1316 | NumErrors += verifyNameIndexCompleteness(DWARFDie(CU.get(), &Die), *NI); |
| 1317 | } |
| 1318 | } |
Pavel Labath | b136c39 | 2018-03-08 15:34:42 +0000 | [diff] [blame] | 1319 | return NumErrors; |
| 1320 | } |
| 1321 | |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 1322 | bool DWARFVerifier::handleAccelTables() { |
| 1323 | const DWARFObject &D = DCtx.getDWARFObj(); |
| 1324 | DataExtractor StrData(D.getStringSection(), DCtx.isLittleEndian(), 0); |
| 1325 | unsigned NumErrors = 0; |
| 1326 | if (!D.getAppleNamesSection().Data.empty()) |
| 1327 | NumErrors += |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 1328 | verifyAppleAccelTable(&D.getAppleNamesSection(), &StrData, ".apple_names"); |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 1329 | if (!D.getAppleTypesSection().Data.empty()) |
| 1330 | NumErrors += |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 1331 | verifyAppleAccelTable(&D.getAppleTypesSection(), &StrData, ".apple_types"); |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 1332 | if (!D.getAppleNamespacesSection().Data.empty()) |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 1333 | NumErrors += verifyAppleAccelTable(&D.getAppleNamespacesSection(), &StrData, |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 1334 | ".apple_namespaces"); |
| 1335 | if (!D.getAppleObjCSection().Data.empty()) |
| 1336 | NumErrors += |
Pavel Labath | 9b36fd2 | 2018-01-22 13:17:23 +0000 | [diff] [blame] | 1337 | verifyAppleAccelTable(&D.getAppleObjCSection(), &StrData, ".apple_objc"); |
Pavel Labath | b136c39 | 2018-03-08 15:34:42 +0000 | [diff] [blame] | 1338 | |
| 1339 | if (!D.getDebugNamesSection().Data.empty()) |
| 1340 | NumErrors += verifyDebugNames(D.getDebugNamesSection(), StrData); |
Spyridoula Gravani | dc635f4 | 2017-07-26 00:52:31 +0000 | [diff] [blame] | 1341 | return NumErrors == 0; |
Spyridoula Gravani | e41823b | 2017-06-14 00:17:55 +0000 | [diff] [blame] | 1342 | } |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 1343 | |
Jonas Devlieghere | 6be1f01 | 2018-04-15 08:44:15 +0000 | [diff] [blame] | 1344 | raw_ostream &DWARFVerifier::error() const { return WithColor::error(OS); } |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 1345 | |
Jonas Devlieghere | 6be1f01 | 2018-04-15 08:44:15 +0000 | [diff] [blame] | 1346 | raw_ostream &DWARFVerifier::warn() const { return WithColor::warning(OS); } |
Jonas Devlieghere | 19fc4d9 | 2017-09-29 09:33:31 +0000 | [diff] [blame] | 1347 | |
Jonas Devlieghere | 6be1f01 | 2018-04-15 08:44:15 +0000 | [diff] [blame] | 1348 | raw_ostream &DWARFVerifier::note() const { return WithColor::note(OS); } |