Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[DebugInfo] Use WithColor to print errors/warnings
Browse files Browse the repository at this point in the history
Use the convenience methods from WithColor to consistently print errors
and warnings in libDebugInfo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330092 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
JDevlieghere committed Apr 14, 2018
1 parent 5baab4c commit 0c191c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
5 changes: 3 additions & 2 deletions lib/DebugInfo/DWARF/DWARFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cstdint>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
27 changes: 14 additions & 13 deletions lib/DebugInfo/DWARF/DWARFDebugLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cassert>
Expand Down Expand Up @@ -318,22 +319,23 @@ 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
parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
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;
Expand Down Expand Up @@ -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()) {
Expand Down
13 changes: 7 additions & 6 deletions lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cinttypes>
Expand Down Expand Up @@ -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;
}

Expand All @@ -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...
Expand All @@ -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<DWARFDebugLocDWO::LocationList>
Expand All @@ -150,8 +151,8 @@ DWARFDebugLocDWO::parseOneLocationList(DataExtractor Data, unsigned *Offset) {
while (auto Kind =
static_cast<dwarf::LocationListEntry>(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;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/DebugInfo/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cassert>
#include <cstddef>
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0c191c5

Please sign in to comment.