Skip to content

Commit 0a529f2

Browse files
author
Kevin Frei
committed
Finished first pass over the error()'s (inserted some TODO's)
1 parent af9eac8 commit 0a529f2

File tree

2 files changed

+66
-51
lines changed

2 files changed

+66
-51
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ class DWARFVerifier {
8181
private:
8282
DWARFVerifier &Verifier;
8383
std::map<std::string, int> UniqueErrors;
84+
raw_ostream *NextLineOverride;
85+
8486
static std::string Clean(const char *s);
8587

8688
public:
87-
ErrorAggregator(DWARFVerifier &v) : Verifier(v) {}
89+
ErrorAggregator(DWARFVerifier &v) : Verifier(v), NextLineOverride(nullptr) {}
8890
raw_ostream &operator<<(const char *s);
89-
void Collect(const std::string &s);
91+
ErrorAggregator &NextLineStreamOverride(raw_ostream &o);
92+
raw_ostream &Collect(const std::string &s);
9093
void Dump();
9194
};
9295
friend class ErrorAggregator;
@@ -102,13 +105,20 @@ class DWARFVerifier {
102105
using ReferenceMap = std::map<uint64_t, std::set<uint64_t>>;
103106

104107
// For errors that have sensible names as the first (or only) string
105-
// you can just use aggregate() << "DIE looks stupid: " << details...
106-
// and it will get aggregated as "DIE looks stupid".
108+
// you can just use aggregate() << "DIE is damaged: " << details...
109+
// and it will get aggregated as "DIE is damaged".
107110
ErrorAggregator &aggregate();
108-
// For errors that have details before good 'categories', you'll need
109-
// to provide the aggregated name, like this:
110-
// aggregate("CU index is busted") << "CU index [" << n << "] is busted"
111+
// For errors that have the useful aggregated category in a non-error stream
112+
// you can do things like this (aggregated as 'Die size is wrong')
113+
// aggregate(note()) << "DIE size is wrong.\n"
114+
ErrorAggregator &aggregate(raw_ostream &);
115+
116+
// For errors that have valuable detail before text that is the appropriate
117+
// aggregate category, you can provide the aggregated name for the error like
118+
// this:
119+
// aggregate("CU index is broken") << "CU index [" << n << "] is broken"
111120
raw_ostream &aggregate(const char *);
121+
112122
raw_ostream &error() const;
113123
raw_ostream &warn() const;
114124
raw_ostream &note() const;

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,19 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
170170
error() << format("Units[%d] - start offset: 0x%08" PRIx64 " \n", UnitIndex,
171171
OffsetStart);
172172
if (!ValidLength)
173-
note() << "The length for this unit is too "
173+
aggregate(note()) << "The length for this unit is too "
174174
"large for the .debug_info provided.\n";
175-
if (!ValidVersion)
176-
note() << "The 16 bit unit header version is not valid.\n";
177-
if (!ValidType)
178-
note() << "The unit type encoding is not valid.\n";
175+
if (!ValidVersion) {
176+
aggregate(note()) << "The 16 bit unit header version is not valid.\n";
177+
}
178+
if (!ValidType){
179+
aggregate(note()) << "The unit type encoding is not valid.\n";
180+
}
179181
if (!ValidAbbrevOffset)
180-
note() << "The offset into the .debug_abbrev section is "
182+
aggregate(note()) << "The offset into the .debug_abbrev section is "
181183
"not valid.\n";
182184
if (!ValidAddrSize)
183-
note() << "The address size is unsupported.\n";
185+
aggregate(note()) << "The address size is unsupported.\n";
184186
}
185187
*Offset = OffsetStart + Length + (isUnitDWARF64 ? 12 : 4);
186188
return Success;
@@ -198,7 +200,7 @@ bool DWARFVerifier::verifyName(const DWARFDie &Die) {
198200
if (OriginalFullName.empty() || OriginalFullName == ReconstructedName)
199201
return false;
200202

201-
error() << "Simplified template DW_AT_name could not be reconstituted:\n"
203+
aggregate() << "Simplified template DW_AT_name could not be reconstituted:\n"
202204
<< formatv(" original: {0}\n"
203205
" reconstituted: {1}\n",
204206
OriginalFullName, ReconstructedName);
@@ -581,6 +583,7 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
581583
return NumErrors;
582584
}
583585

586+
// Aggregation TODO:
584587
unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
585588
DWARFAttribute &AttrValue) {
586589
unsigned NumErrors = 0;
@@ -796,6 +799,7 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
796799
case DW_FORM_line_strp: {
797800
if (Error E = AttrValue.Value.getAsCString().takeError()) {
798801
++NumErrors;
802+
// Aggregation TODO:
799803
error() << toString(std::move(E)) << ":\n";
800804
dump(Die) << '\n';
801805
}
@@ -1005,6 +1009,7 @@ unsigned DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
10051009

10061010
// Verify that the section is not too short.
10071011
if (Error E = AccelTable.extract()) {
1012+
// Aggregation TODO:
10081013
error() << toString(std::move(E)) << '\n';
10091014
return 1;
10101015
}
@@ -1361,7 +1366,7 @@ DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) {
13611366
++NumErrors;
13621367
}
13631368
if (!Attributes.count(dwarf::DW_IDX_die_offset)) {
1364-
error() << formatv(
1369+
aggregate("Abbreviate in NameIndex missing attribute") << formatv(
13651370
"NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n",
13661371
NI.getUnitOffset(), Abbrev.Code, dwarf::DW_IDX_die_offset);
13671372
++NumErrors;
@@ -1417,7 +1422,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
14171422

14181423
const char *CStr = NTE.getString();
14191424
if (!CStr) {
1420-
error() << formatv(
1425+
aggregate("Unable to get string associated with name") << formatv(
14211426
"Name Index @ {0:x}: Unable to get string associated with name {1}.\n",
14221427
NI.getUnitOffset(), NTE.getIndex());
14231428
return 1;
@@ -1433,7 +1438,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
14331438
EntryOr = NI.getEntry(&NextEntryID)) {
14341439
uint32_t CUIndex = *EntryOr->getCUIndex();
14351440
if (CUIndex > NI.getCUCount()) {
1436-
error() << formatv("Name Index @ {0:x}: Entry @ {1:x} contains an "
1441+
aggregate("Name Index entry contains invalid CU index") << formatv("Name Index @ {0:x}: Entry @ {1:x} contains an "
14371442
"invalid CU index ({2}).\n",
14381443
NI.getUnitOffset(), EntryID, CUIndex);
14391444
++NumErrors;
@@ -1443,21 +1448,21 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
14431448
uint64_t DIEOffset = CUOffset + *EntryOr->getDIEUnitOffset();
14441449
DWARFDie DIE = DCtx.getDIEForOffset(DIEOffset);
14451450
if (!DIE) {
1446-
error() << formatv("Name Index @ {0:x}: Entry @ {1:x} references a "
1451+
aggregate("NameIndex references nonexisten DIE") << formatv("Name Index @ {0:x}: Entry @ {1:x} references a "
14471452
"non-existing DIE @ {2:x}.\n",
14481453
NI.getUnitOffset(), EntryID, DIEOffset);
14491454
++NumErrors;
14501455
continue;
14511456
}
14521457
if (DIE.getDwarfUnit()->getOffset() != CUOffset) {
1453-
error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of "
1454-
"DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n",
1458+
aggregate("Name index contains mismatched CU of DIE") << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched CU of "
1459+
"DIE @ {2:x}: index - {3:x}; debug_info - {4:x}.\n",
14551460
NI.getUnitOffset(), EntryID, DIEOffset, CUOffset,
14561461
DIE.getDwarfUnit()->getOffset());
14571462
++NumErrors;
14581463
}
14591464
if (DIE.getTag() != EntryOr->tag()) {
1460-
error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of "
1465+
aggregate("Name Index contains mismatched Tag of DIE") << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Tag of "
14611466
"DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
14621467
NI.getUnitOffset(), EntryID, DIEOffset, EntryOr->tag(),
14631468
DIE.getTag());
@@ -1471,7 +1476,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
14711476
DIE.getTag() == DW_TAG_inlined_subroutine;
14721477
auto EntryNames = getNames(DIE, IncludeStrippedTemplateNames);
14731478
if (!is_contained(EntryNames, Str)) {
1474-
error() << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Name "
1479+
aggregate("Name Index contains mismatched name of DIE") << formatv("Name Index @ {0:x}: Entry @ {1:x}: mismatched Name "
14751480
"of DIE @ {2:x}: index - {3}; debug_info - {4}.\n",
14761481
NI.getUnitOffset(), EntryID, DIEOffset, Str,
14771482
make_range(EntryNames.begin(), EntryNames.end()));
@@ -1482,12 +1487,13 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
14821487
[&](const DWARFDebugNames::SentinelError &) {
14831488
if (NumEntries > 0)
14841489
return;
1485-
error() << formatv("Name Index @ {0:x}: Name {1} ({2}) is "
1490+
aggregate("NameIndex Name is not associated with any entries") << formatv("Name Index @ {0:x}: Name {1} ({2}) is "
14861491
"not associated with any entries.\n",
14871492
NI.getUnitOffset(), NTE.getIndex(), Str);
14881493
++NumErrors;
14891494
},
14901495
[&](const ErrorInfoBase &Info) {
1496+
// Aggregation TODO:
14911497
error()
14921498
<< formatv("Name Index @ {0:x}: Name {1} ({2}): {3}\n",
14931499
NI.getUnitOffset(), NTE.getIndex(), Str,
@@ -1619,7 +1625,7 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
16191625
if (none_of(NI.equal_range(Name), [&](const DWARFDebugNames::Entry &E) {
16201626
return E.getDIEUnitOffset() == DieUnitOffset;
16211627
})) {
1622-
error() << formatv("Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1628+
aggregate("Name Index DIE entry missing name") << formatv("Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
16231629
"name {3} missing.\n",
16241630
NI.getUnitOffset(), Die.getOffset(), Die.getTag(),
16251631
Name);
@@ -1641,6 +1647,7 @@ unsigned DWARFVerifier::verifyDebugNames(const DWARFSection &AccelSection,
16411647
// This verifies that we can read individual name indices and their
16421648
// abbreviation tables.
16431649
if (Error E = AccelTable.extract()) {
1650+
// Aggregate TODO:
16441651
error() << toString(std::move(E)) << '\n';
16451652
return 1;
16461653
}
@@ -1741,7 +1748,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
17411748
if (!C)
17421749
break;
17431750
if (C.tell() + Length > DA.getData().size()) {
1744-
error() << formatv(
1751+
aggregate("Section contribution length exceeds available space") << formatv(
17451752
"{0}: contribution {1:X}: length exceeds available space "
17461753
"(contribution "
17471754
"offset ({1:X}) + length field space ({2:X}) + length ({3:X}) == "
@@ -1755,7 +1762,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
17551762
NextUnit = C.tell() + Length;
17561763
uint8_t Version = DA.getU16(C);
17571764
if (C && Version != 5) {
1758-
error() << formatv("{0}: contribution {1:X}: invalid version {2}\n",
1765+
aggregate("Invalid Section version") << formatv("{0}: contribution {1:X}: invalid version {2}\n",
17591766
SectionName, StartOffset, Version);
17601767
Success = false;
17611768
// Can't parse the rest of this contribution, since we don't know the
@@ -1768,7 +1775,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
17681775
DA.setAddressSize(OffsetByteSize);
17691776
uint64_t Remainder = (Length - 4) % OffsetByteSize;
17701777
if (Remainder != 0) {
1771-
error() << formatv(
1778+
aggregate("Invalid section contribution length") << formatv(
17721779
"{0}: contribution {1:X}: invalid length ((length ({2:X}) "
17731780
"- header (0x4)) % offset size {3:X} == {4:X} != 0)\n",
17741781
SectionName, StartOffset, Length, OffsetByteSize, Remainder);
@@ -1789,7 +1796,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
17891796
}
17901797
if (StrData[StrOff - 1] == '\0')
17911798
continue;
1792-
error() << formatv("{0}: contribution {1:X}: index {2:X}: invalid string "
1799+
aggregate("Section contribution contains invalid string offset") << formatv("{0}: contribution {1:X}: index {2:X}: invalid string "
17931800
"offset *{3:X} == {4:X}, is neither zero nor "
17941801
"immediately following a null character\n",
17951802
SectionName, StartOffset, Index, OffOff, StrOff);
@@ -1798,28 +1805,12 @@ bool DWARFVerifier::verifyDebugStrOffsets(
17981805
}
17991806

18001807
if (Error E = C.takeError()) {
1808+
// Aggregate TODO:
18011809
error() << SectionName << ": " << toString(std::move(E)) << '\n';
18021810
return false;
18031811
}
18041812
return Success;
18051813
}
1806-
/*
1807-
raw_ostream & operator <<(const char * s) {
1808-
collect(s);
1809-
out << "From inside the class: " << s;
1810-
return out;
1811-
}
1812-
void collect(const char * s) {
1813-
counters[s]++;
1814-
}
1815-
void dump() {
1816-
for (auto && [name, count]: counters) {
1817-
out << "counter: " << name << ", count: " << count << "\n";
1818-
}
1819-
}
1820-
1821-
ErrorAggregator collectErrors();
1822-
*/
18231814

18241815
std::string DWARFVerifier::ErrorAggregator::Clean(const char *s) {
18251816
// Find the position of the first alphabetic character
@@ -1839,12 +1830,18 @@ std::string DWARFVerifier::ErrorAggregator::Clean(const char *s) {
18391830
}
18401831

18411832
raw_ostream &DWARFVerifier::ErrorAggregator::operator<<(const char *s) {
1842-
Collect(Clean(s));
1843-
return Verifier.error() << s;
1833+
return Collect(Clean(s)) << s;
18441834
}
18451835

1846-
void DWARFVerifier::ErrorAggregator::Collect(const std::string &s) {
1836+
raw_ostream &DWARFVerifier::ErrorAggregator::Collect(const std::string &s) {
1837+
// Register the error in the aggregator
18471838
UniqueErrors[s]++;
1839+
1840+
// If we have an output stream override, return it and reset it back to
1841+
// the default
1842+
raw_ostream *o = NextLineOverride;
1843+
NextLineOverride = nullptr;
1844+
return (o == nullptr) ? Verifier.error() : *o;
18481845
}
18491846

18501847
void DWARFVerifier::ErrorAggregator::Dump() {
@@ -1854,8 +1851,16 @@ void DWARFVerifier::ErrorAggregator::Dump() {
18541851
}
18551852

18561853
raw_ostream &DWARFVerifier::aggregate(const char *name) {
1857-
ErrAggregation.Collect(name);
1858-
return error();
1854+
return ErrAggregation.Collect(name);
1855+
}
1856+
1857+
DWARFVerifier::ErrorAggregator &DWARFVerifier::ErrorAggregator::NextLineStreamOverride(raw_ostream &o) {
1858+
NextLineOverride = &o;
1859+
return *this;
1860+
}
1861+
1862+
DWARFVerifier::ErrorAggregator &DWARFVerifier::aggregate(raw_ostream &o) {
1863+
return ErrAggregation.NextLineStreamOverride(o);
18591864
}
18601865

18611866
DWARFVerifier::ErrorAggregator &DWARFVerifier::aggregate() {

0 commit comments

Comments
 (0)