Skip to content

Commit 0c191c5

Browse files
committed
[DebugInfo] Use WithColor to print errors/warnings
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
1 parent 5baab4c commit 0c191c5

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Support/MemoryBuffer.h"
4545
#include "llvm/Support/Path.h"
4646
#include "llvm/Support/TargetRegistry.h"
47+
#include "llvm/Support/WithColor.h"
4748
#include "llvm/Support/raw_ostream.h"
4849
#include <algorithm>
4950
#include <cstdint>
@@ -502,7 +503,7 @@ void DWARFContext::dump(
502503
DWARFDebugRnglistTable Rnglists;
503504
uint32_t TableOffset = Offset;
504505
if (Error Err = Rnglists.extract(rnglistData, &Offset)) {
505-
errs() << "error: " + toString(std::move(Err)) << '\n';
506+
WithColor::error() << toString(std::move(Err)) << '\n';
506507
uint64_t Length = Rnglists.length();
507508
// Keep going after an error, if we can, assuming that the length field
508509
// could be read. If it couldn't, stop reading the section.
@@ -1167,7 +1168,7 @@ static bool isRelocScattered(const object::ObjectFile &Obj,
11671168
}
11681169

11691170
ErrorPolicy DWARFContext::defaultErrorHandler(Error E) {
1170-
errs() << "error: " + toString(std::move(E)) << '\n';
1171+
WithColor::error() << toString(std::move(E)) << '\n';
11711172
return ErrorPolicy::Continue;
11721173
}
11731174

lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
1818
#include "llvm/Support/Format.h"
1919
#include "llvm/Support/Path.h"
20+
#include "llvm/Support/WithColor.h"
2021
#include "llvm/Support/raw_ostream.h"
2122
#include <algorithm>
2223
#include <cassert>
@@ -318,22 +319,23 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
318319
if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
319320
FormParams, Ctx, U, ContentTypes,
320321
IncludeDirectories, FileNames)) {
321-
fprintf(stderr,
322-
"warning: parsing line table prologue at 0x%8.8" PRIx64
323-
" found an invalid directory or file table description at"
324-
" 0x%8.8" PRIx64 "\n", PrologueOffset, (uint64_t)*OffsetPtr);
322+
WithColor::warning() << format(
323+
"parsing line table prologue at 0x%8.8" PRIx64
324+
" found an invalid directory or file table description at"
325+
" 0x%8.8" PRIx64 "\n",
326+
PrologueOffset, (uint64_t)*OffsetPtr);
325327
return false;
326328
}
327329
} else
328330
parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
329331
ContentTypes, IncludeDirectories, FileNames);
330332

331333
if (*OffsetPtr != EndPrologueOffset) {
332-
fprintf(stderr,
333-
"warning: parsing line table prologue at 0x%8.8" PRIx64
334-
" should have ended at 0x%8.8" PRIx64
335-
" but it ended at 0x%8.8" PRIx64 "\n",
336-
PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
334+
WithColor::warning() << format(
335+
"parsing line table prologue at 0x%8.8" PRIx64
336+
" should have ended at 0x%8.8" PRIx64 " but it ended at 0x%8.8" PRIx64
337+
"\n",
338+
PrologueOffset, EndPrologueOffset, (uint64_t)*OffsetPtr);
337339
return false;
338340
}
339341
return true;
@@ -828,10 +830,9 @@ bool DWARFDebugLine::LineTable::parse(DWARFDataExtractor &DebugLineData,
828830
*OS << "\n";
829831
}
830832

831-
if (!State.Sequence.Empty) {
832-
fprintf(stderr, "warning: last sequence in debug line table is not"
833-
"terminated!\n");
834-
}
833+
if (!State.Sequence.Empty)
834+
WithColor::warning() << "last sequence in debug line table is not"
835+
"terminated!\n";
835836

836837
// Sort all sequences so that address lookup will work faster.
837838
if (!Sequences.empty()) {

lib/DebugInfo/DWARF/DWARFDebugLoc.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1717
#include "llvm/Support/Compiler.h"
1818
#include "llvm/Support/Format.h"
19+
#include "llvm/Support/WithColor.h"
1920
#include "llvm/Support/raw_ostream.h"
2021
#include <algorithm>
2122
#include <cinttypes>
@@ -91,7 +92,7 @@ DWARFDebugLoc::parseOneLocationList(DWARFDataExtractor Data, unsigned *Offset) {
9192
while (true) {
9293
Entry E;
9394
if (!Data.isValidOffsetForDataOfSize(*Offset, 2 * Data.getAddressSize())) {
94-
llvm::errs() << "Location list overflows the debug_loc section.\n";
95+
WithColor::error() << "location list overflows the debug_loc section.\n";
9596
return None;
9697
}
9798

@@ -108,13 +109,13 @@ DWARFDebugLoc::parseOneLocationList(DWARFDataExtractor Data, unsigned *Offset) {
108109
return LL;
109110

110111
if (!Data.isValidOffsetForDataOfSize(*Offset, 2)) {
111-
llvm::errs() << "Location list overflows the debug_loc section.\n";
112+
WithColor::error() << "location list overflows the debug_loc section.\n";
112113
return None;
113114
}
114115

115116
unsigned Bytes = Data.getU16(Offset);
116117
if (!Data.isValidOffsetForDataOfSize(*Offset, Bytes)) {
117-
llvm::errs() << "Location list overflows the debug_loc section.\n";
118+
WithColor::error() << "location list overflows the debug_loc section.\n";
118119
return None;
119120
}
120121
// A single location description describing the location of the object...
@@ -138,7 +139,7 @@ void DWARFDebugLoc::parse(const DWARFDataExtractor &data) {
138139
break;
139140
}
140141
if (data.isValidOffset(Offset))
141-
errs() << "error: failed to consume entire .debug_loc section\n";
142+
WithColor::error() << "failed to consume entire .debug_loc section\n";
142143
}
143144

144145
Optional<DWARFDebugLocDWO::LocationList>
@@ -150,8 +151,8 @@ DWARFDebugLocDWO::parseOneLocationList(DataExtractor Data, unsigned *Offset) {
150151
while (auto Kind =
151152
static_cast<dwarf::LocationListEntry>(Data.getU8(Offset))) {
152153
if (Kind != dwarf::DW_LLE_startx_length) {
153-
llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
154-
<< " not implemented\n";
154+
WithColor::error() << "dumping support for LLE of kind " << (int)Kind
155+
<< " not implemented\n";
155156
return None;
156157
}
157158

lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1919
#include "llvm/Support/DataExtractor.h"
2020
#include "llvm/Support/Path.h"
21+
#include "llvm/Support/WithColor.h"
2122
#include <algorithm>
2223
#include <cassert>
2324
#include <cstddef>
@@ -225,8 +226,9 @@ void DWARFUnit::extractDIEsToVector(
225226
// should always terminate at or before the start of the next compilation
226227
// unit header).
227228
if (DIEOffset > NextCUOffset)
228-
fprintf(stderr, "warning: DWARF compile unit extends beyond its "
229-
"bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), DIEOffset);
229+
WithColor::warning() << format("DWARF compile unit extends beyond its "
230+
"bounds cu 0x%8.8x at 0x%8.8x\n",
231+
getOffset(), DIEOffset);
230232
}
231233

232234
size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {

0 commit comments

Comments
 (0)