LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - DWARFVerifier.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 643 682 94.3 %
Date: 2018-09-23 13:06:45 Functions: 32 33 97.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13