From 84e99265d6a7589fee870f8f0a85ad50351e6cdc Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Sat, 14 Apr 2018 22:07:23 +0000 Subject: [PATCH] [DebugInfo] Use WithColor to print errors/warnings Use the convenience methods from WithColor to consistently print errors and warnings in libDebugInfo. llvm-svn: 330092 --- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 5 +++-- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 27 ++++++++++++++------------- llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp | 13 +++++++------ llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 6 ++++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index e9f4df6..e8330a0 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -44,6 +44,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -502,7 +503,7 @@ void DWARFContext::dump( DWARFDebugRnglistTable Rnglists; uint32_t TableOffset = Offset; if (Error Err = Rnglists.extract(rnglistData, &Offset)) { - errs() << "error: " + toString(std::move(Err)) << '\n'; + WithColor::error() << toString(std::move(Err)) << '\n'; uint64_t Length = Rnglists.length(); // Keep going after an error, if we can, assuming that the length field // could be read. If it couldn't, stop reading the section. @@ -1167,7 +1168,7 @@ static bool isRelocScattered(const object::ObjectFile &Obj, } ErrorPolicy DWARFContext::defaultErrorHandler(Error E) { - errs() << "error: " + toString(std::move(E)) << '\n'; + WithColor::error() << toString(std::move(E)) << '\n'; return ErrorPolicy::Continue; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index cba21b0..dd74ea3 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -17,6 +17,7 @@ #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -318,10 +319,11 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData, if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset, FormParams, Ctx, U, ContentTypes, IncludeDirectories, FileNames)) { - fprintf(stderr, - "warning: parsing line table prologue at 0x%8.8" PRIx64 - " found an invalid directory or file table description at" - " 0x%8.8" PRIx64 "\n", PrologueOffset, (uint64_t)*OffsetPtr); + WithColor::warning() << format( + "parsing line table prologue at 0x%8.8" PRIx64 + " found an invalid directory or file table description at" + " 0x%8.8" PRIx64 "\n", + PrologueOffset, (uint64_t)*OffsetPtr); return false; } } else @@ -329,11 +331,11 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData, ContentTypes, IncludeDirectories, FileNames); if (*OffsetPtr != EndPrologueOffset) { - fprintf(stderr, - "warning: parsing line table prologue at 0x%8.8" PRIx64 - " should have ended at 0x%8.8" PRIx64 - " but it ended at 0x%8.8" PRIx64 "\n", - PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr); + WithColor::warning() << format( + "parsing line table prologue at 0x%8.8" PRIx64 + " should have ended at 0x%8.8" PRIx64 " but it ended at 0x%8.8" PRIx64 + "\n", + PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr); return false; } return true; @@ -828,10 +830,9 @@ bool DWARFDebugLine::LineTable::parse(DWARFDataExtractor &DebugLineData, *OS << "\n"; } - if (!State.Sequence.Empty) { - fprintf(stderr, "warning: last sequence in debug line table is not" - "terminated!\n"); - } + if (!State.Sequence.Empty) + WithColor::warning() << "last sequence in debug line table is not" + "terminated!\n"; // Sort all sequences so that address lookup will work faster. if (!Sequences.empty()) { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp index 90f3b45..d24e1ab 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -16,6 +16,7 @@ #include "llvm/DebugInfo/DWARF/DWARFUnit.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Format.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -91,7 +92,7 @@ DWARFDebugLoc::parseOneLocationList(DWARFDataExtractor Data, unsigned *Offset) { while (true) { Entry E; if (!Data.isValidOffsetForDataOfSize(*Offset, 2 * Data.getAddressSize())) { - llvm::errs() << "Location list overflows the debug_loc section.\n"; + WithColor::error() << "location list overflows the debug_loc section.\n"; return None; } @@ -108,13 +109,13 @@ DWARFDebugLoc::parseOneLocationList(DWARFDataExtractor Data, unsigned *Offset) { return LL; if (!Data.isValidOffsetForDataOfSize(*Offset, 2)) { - llvm::errs() << "Location list overflows the debug_loc section.\n"; + WithColor::error() << "location list overflows the debug_loc section.\n"; return None; } unsigned Bytes = Data.getU16(Offset); if (!Data.isValidOffsetForDataOfSize(*Offset, Bytes)) { - llvm::errs() << "Location list overflows the debug_loc section.\n"; + WithColor::error() << "location list overflows the debug_loc section.\n"; return None; } // A single location description describing the location of the object... @@ -138,7 +139,7 @@ void DWARFDebugLoc::parse(const DWARFDataExtractor &data) { break; } if (data.isValidOffset(Offset)) - errs() << "error: failed to consume entire .debug_loc section\n"; + WithColor::error() << "failed to consume entire .debug_loc section\n"; } Optional @@ -150,8 +151,8 @@ DWARFDebugLocDWO::parseOneLocationList(DataExtractor Data, unsigned *Offset) { while (auto Kind = static_cast(Data.getU8(Offset))) { if (Kind != dwarf::DW_LLE_startx_length) { - llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind - << " not implemented\n"; + WithColor::error() << "dumping support for LLE of kind " << (int)Kind + << " not implemented\n"; return None; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index c1b8246..884d3bb 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -18,6 +18,7 @@ #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Path.h" +#include "llvm/Support/WithColor.h" #include #include #include @@ -225,8 +226,9 @@ void DWARFUnit::extractDIEsToVector( // should always terminate at or before the start of the next compilation // unit header). if (DIEOffset > NextCUOffset) - fprintf(stderr, "warning: DWARF compile unit extends beyond its " - "bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), DIEOffset); + WithColor::warning() << format("DWARF compile unit extends beyond its " + "bounds cu 0x%8.8x at 0x%8.8x\n", + getOffset(), DIEOffset); } size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) { -- 2.7.4