[llvm] r342526 - [DWARF Verifier] Add helper function to dump DIEs. [NFC]

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 19 11:38:53 PDT 2018



> -----Original Message-----
> From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On Behalf
> Of Jonas Devlieghere via llvm-commits
> Sent: Wednesday, September 19, 2018 4:08 AM
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] r342526 - [DWARF Verifier] Add helper function to dump
> DIEs. [NFC]
> 
> Author: jdevlieghere
> Date: Wed Sep 19 01:08:13 2018
> New Revision: 342526
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=342526&view=rev
> Log:
> [DWARF Verifier] Add helper function to dump DIEs. [NFC]
> 
> It's pretty common for the verifier to dump the relevant DIE when it
> finds an issue. This tends to be relatively verbose and error prone
> because we have to pass the DIDumpOptions to the DIE's dump method. This
> patch adds a helper function to the verifier to make this easier.
> 
> Modified:
>     llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
>     llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
> 
> Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h?rev=342526
> &r1=342525&r2=342526&view=diff
> ==========================================================================
> ====
> --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h (original)
> +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFVerifier.h Wed Sep 19
> 01:08:13 2018
> @@ -101,6 +101,7 @@ private:
>    raw_ostream &error() const;
>    raw_ostream &warn() const;
>    raw_ostream &note() const;
> +  raw_ostream &dump(const DWARFDie &Die, unsigned indent = 0) const;
> 
>    /// Verifies the abbreviations section.
>    ///
> 
> Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp?rev=342526&r1=342
> 525&r2=342526&view=diff
> ==========================================================================
> ====
> --- llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp (original)
> +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp Wed Sep 19 01:08:13
> 2018
> @@ -6,7 +6,6 @@
>  // License. See LICENSE.TXT for details.
>  //
>  //===--------------------------------------------------------------------
> --===//
> -
>  #include "llvm/DebugInfo/DWARF/DWARFVerifier.h"
>  #include "llvm/ADT/SmallSet.h"
>  #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
> @@ -368,9 +367,8 @@ unsigned DWARFVerifier::verifyDieRanges(
>    if (IntersectingChild != ParentRI.Children.end()) {
>      ++NumErrors;
>      error() << "DIEs have overlapping address ranges:";
> -    Die.dump(OS, 0);
> -    IntersectingChild->Die.dump(OS, 0);
> -    OS << "\n";
> +    dump(Die);
> +    dump(IntersectingChild->Die) << '\n';
>    }
> 
>    // Verify that ranges are contained within their parent.
> @@ -380,9 +378,8 @@ unsigned DWARFVerifier::verifyDieRanges(
>    if (ShouldBeContained && !ParentRI.contains(RI)) {
>      ++NumErrors;
>      error() << "DIE address ranges are not contained in its parent's
> ranges:";
> -    ParentRI.Die.dump(OS, 0);
> -    Die.dump(OS, 2);
> -    OS << "\n";
> +    dump(ParentRI.Die);
> +    dump(Die, 2) << '\n';
>    }
> 
>    // Recursively check children.
> @@ -398,8 +395,7 @@ unsigned DWARFVerifier::verifyDebugInfoA
>    auto ReportError = [&](const Twine &TitleMsg) {
>      ++NumErrors;
>      error() << TitleMsg << '\n';
> -    Die.dump(OS, 0, DumpOpts);
> -    OS << "\n";
> +    dump(Die) << '\n';
>    };
> 
>    const DWARFObject &DObj = DCtx.getDWARFObj();
> @@ -480,7 +476,7 @@ unsigned DWARFVerifier::verifyDebugInfoF
>                  << " is invalid (must be less than CU size of "
>                  << format("0x%08" PRIx32, CUSize) << "):\n";
>          Die.dump(OS, 0, DumpOpts);
> -        OS << "\n";
> +        dump(Die) << '\n';

Looks like you forgot to delete the Die.dump() line here?


>        } else {
>          // Valid reference, but we will verify it points to an actual
>          // DIE later.
> @@ -499,8 +495,7 @@ unsigned DWARFVerifier::verifyDebugInfoF
>          ++NumErrors;
>          error() << "DW_FORM_ref_addr offset beyond .debug_info "
>                     "bounds:\n";
> -        Die.dump(OS, 0, DumpOpts);
> -        OS << "\n";
> +        dump(Die) << '\n';
>        } else {
>          // Valid reference, but we will verify it points to an actual
>          // DIE later.
> @@ -515,8 +510,7 @@ unsigned DWARFVerifier::verifyDebugInfoF
>      if (SecOffset && *SecOffset >= DObj.getStringSection().size()) {
>        ++NumErrors;
>        error() << "DW_FORM_strp offset beyond .debug_str bounds:\n";
> -      Die.dump(OS, 0, DumpOpts);
> -      OS << "\n";
> +      dump(Die) << '\n';
>      }
>      break;
>    }
> @@ -538,11 +532,8 @@ unsigned DWARFVerifier::verifyDebugInfoR
>      ++NumErrors;
>      error() << "invalid DIE reference " << format("0x%08" PRIx64,
> Pair.first)
>              << ". Offset is in between DIEs:\n";
> -    for (auto Offset : Pair.second) {
> -      auto ReferencingDie = DCtx.getDIEForOffset(Offset);
> -      ReferencingDie.dump(OS, 0, DumpOpts);
> -      OS << "\n";
> -    }
> +    for (auto Offset : Pair.second)
> +      dump(DCtx.getDIEForOffset(Offset)) << '\n';
>      OS << "\n";
>    }
>    return NumErrors;
> @@ -565,8 +556,7 @@ void DWARFVerifier::verifyDebugLineStmtO
>          ++NumDebugLineErrors;
>          error() << ".debug_line[" << format("0x%08" PRIx32,
> LineTableOffset)
>                  << "] was not able to be parsed for CU:\n";
> -        Die.dump(OS, 0, DumpOpts);
> -        OS << '\n';
> +        dump(Die) << '\n';
>          continue;
>        }
>      } else {
> @@ -583,9 +573,8 @@ void DWARFVerifier::verifyDebugLineStmtO
>                << format("0x%08" PRIx32, Iter->second.getOffset()) << "
> and "
>                << format("0x%08" PRIx32, Die.getOffset())
>                << ", have the same DW_AT_stmt_list section offset:\n";
> -      Iter->second.dump(OS, 0, DumpOpts);
> -      Die.dump(OS, 0, DumpOpts);
> -      OS << '\n';
> +      dump(Iter->second);
> +      dump(Die) << '\n';
>        // Already verified this line table before, no need to do it again.
>        continue;
>      }
> @@ -1369,3 +1358,8 @@ raw_ostream &DWARFVerifier::error() cons
>  raw_ostream &DWARFVerifier::warn() const { return WithColor::warning(OS);
> }
> 
>  raw_ostream &DWARFVerifier::note() const { return WithColor::note(OS); }
> +
> +raw_ostream &DWARFVerifier::dump(const DWARFDie &Die, unsigned indent)
> const {
> +  Die.dump(OS, indent, DumpOpts);
> +  return OS;
> +}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list