@@ -170,17 +170,19 @@ bool DWARFVerifier::verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
170
170
error () << format (" Units[%d] - start offset: 0x%08" PRIx64 " \n " , UnitIndex,
171
171
OffsetStart);
172
172
if (!ValidLength)
173
- note () << " The length for this unit is too "
173
+ aggregate ( note () ) << " The length for this unit is too "
174
174
" 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
+ }
179
181
if (!ValidAbbrevOffset)
180
- note () << " The offset into the .debug_abbrev section is "
182
+ aggregate ( note () ) << " The offset into the .debug_abbrev section is "
181
183
" not valid.\n " ;
182
184
if (!ValidAddrSize)
183
- note () << " The address size is unsupported.\n " ;
185
+ aggregate ( note () ) << " The address size is unsupported.\n " ;
184
186
}
185
187
*Offset = OffsetStart + Length + (isUnitDWARF64 ? 12 : 4 );
186
188
return Success;
@@ -198,7 +200,7 @@ bool DWARFVerifier::verifyName(const DWARFDie &Die) {
198
200
if (OriginalFullName.empty () || OriginalFullName == ReconstructedName)
199
201
return false ;
200
202
201
- error () << " Simplified template DW_AT_name could not be reconstituted:\n "
203
+ aggregate () << " Simplified template DW_AT_name could not be reconstituted:\n "
202
204
<< formatv (" original: {0}\n "
203
205
" reconstituted: {1}\n " ,
204
206
OriginalFullName, ReconstructedName);
@@ -581,6 +583,7 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
581
583
return NumErrors;
582
584
}
583
585
586
+ // Aggregation TODO:
584
587
unsigned DWARFVerifier::verifyDebugInfoAttribute (const DWARFDie &Die,
585
588
DWARFAttribute &AttrValue) {
586
589
unsigned NumErrors = 0 ;
@@ -796,6 +799,7 @@ unsigned DWARFVerifier::verifyDebugInfoForm(const DWARFDie &Die,
796
799
case DW_FORM_line_strp: {
797
800
if (Error E = AttrValue.Value .getAsCString ().takeError ()) {
798
801
++NumErrors;
802
+ // Aggregation TODO:
799
803
error () << toString (std::move (E)) << " :\n " ;
800
804
dump (Die) << ' \n ' ;
801
805
}
@@ -1005,6 +1009,7 @@ unsigned DWARFVerifier::verifyAppleAccelTable(const DWARFSection *AccelSection,
1005
1009
1006
1010
// Verify that the section is not too short.
1007
1011
if (Error E = AccelTable.extract ()) {
1012
+ // Aggregation TODO:
1008
1013
error () << toString (std::move (E)) << ' \n ' ;
1009
1014
return 1 ;
1010
1015
}
@@ -1361,7 +1366,7 @@ DWARFVerifier::verifyNameIndexAbbrevs(const DWARFDebugNames::NameIndex &NI) {
1361
1366
++NumErrors;
1362
1367
}
1363
1368
if (!Attributes.count (dwarf::DW_IDX_die_offset)) {
1364
- error ( ) << formatv (
1369
+ aggregate ( " Abbreviate in NameIndex missing attribute " ) << formatv (
1365
1370
" NameIndex @ {0:x}: Abbreviation {1:x} has no {2} attribute.\n " ,
1366
1371
NI.getUnitOffset (), Abbrev.Code , dwarf::DW_IDX_die_offset);
1367
1372
++NumErrors;
@@ -1417,7 +1422,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
1417
1422
1418
1423
const char *CStr = NTE.getString ();
1419
1424
if (!CStr) {
1420
- error ( ) << formatv (
1425
+ aggregate ( " Unable to get string associated with name " ) << formatv (
1421
1426
" Name Index @ {0:x}: Unable to get string associated with name {1}.\n " ,
1422
1427
NI.getUnitOffset (), NTE.getIndex ());
1423
1428
return 1 ;
@@ -1433,7 +1438,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
1433
1438
EntryOr = NI.getEntry (&NextEntryID)) {
1434
1439
uint32_t CUIndex = *EntryOr->getCUIndex ();
1435
1440
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 "
1437
1442
" invalid CU index ({2}).\n " ,
1438
1443
NI.getUnitOffset (), EntryID, CUIndex);
1439
1444
++NumErrors;
@@ -1443,21 +1448,21 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
1443
1448
uint64_t DIEOffset = CUOffset + *EntryOr->getDIEUnitOffset ();
1444
1449
DWARFDie DIE = DCtx.getDIEForOffset (DIEOffset);
1445
1450
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 "
1447
1452
" non-existing DIE @ {2:x}.\n " ,
1448
1453
NI.getUnitOffset (), EntryID, DIEOffset);
1449
1454
++NumErrors;
1450
1455
continue ;
1451
1456
}
1452
1457
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 " ,
1455
1460
NI.getUnitOffset (), EntryID, DIEOffset, CUOffset,
1456
1461
DIE.getDwarfUnit ()->getOffset ());
1457
1462
++NumErrors;
1458
1463
}
1459
1464
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 "
1461
1466
" DIE @ {2:x}: index - {3}; debug_info - {4}.\n " ,
1462
1467
NI.getUnitOffset (), EntryID, DIEOffset, EntryOr->tag (),
1463
1468
DIE.getTag ());
@@ -1471,7 +1476,7 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
1471
1476
DIE.getTag () == DW_TAG_inlined_subroutine;
1472
1477
auto EntryNames = getNames (DIE, IncludeStrippedTemplateNames);
1473
1478
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 "
1475
1480
" of DIE @ {2:x}: index - {3}; debug_info - {4}.\n " ,
1476
1481
NI.getUnitOffset (), EntryID, DIEOffset, Str,
1477
1482
make_range (EntryNames.begin (), EntryNames.end ()));
@@ -1482,12 +1487,13 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
1482
1487
[&](const DWARFDebugNames::SentinelError &) {
1483
1488
if (NumEntries > 0 )
1484
1489
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 "
1486
1491
" not associated with any entries.\n " ,
1487
1492
NI.getUnitOffset (), NTE.getIndex (), Str);
1488
1493
++NumErrors;
1489
1494
},
1490
1495
[&](const ErrorInfoBase &Info) {
1496
+ // Aggregation TODO:
1491
1497
error ()
1492
1498
<< formatv (" Name Index @ {0:x}: Name {1} ({2}): {3}\n " ,
1493
1499
NI.getUnitOffset (), NTE.getIndex (), Str,
@@ -1619,7 +1625,7 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
1619
1625
if (none_of (NI.equal_range (Name), [&](const DWARFDebugNames::Entry &E) {
1620
1626
return E.getDIEUnitOffset () == DieUnitOffset;
1621
1627
})) {
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 "
1623
1629
" name {3} missing.\n " ,
1624
1630
NI.getUnitOffset (), Die.getOffset (), Die.getTag (),
1625
1631
Name);
@@ -1641,6 +1647,7 @@ unsigned DWARFVerifier::verifyDebugNames(const DWARFSection &AccelSection,
1641
1647
// This verifies that we can read individual name indices and their
1642
1648
// abbreviation tables.
1643
1649
if (Error E = AccelTable.extract ()) {
1650
+ // Aggregate TODO:
1644
1651
error () << toString (std::move (E)) << ' \n ' ;
1645
1652
return 1 ;
1646
1653
}
@@ -1741,7 +1748,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
1741
1748
if (!C)
1742
1749
break ;
1743
1750
if (C.tell () + Length > DA.getData ().size ()) {
1744
- error ( ) << formatv (
1751
+ aggregate ( " Section contribution length exceeds available space " ) << formatv (
1745
1752
" {0}: contribution {1:X}: length exceeds available space "
1746
1753
" (contribution "
1747
1754
" offset ({1:X}) + length field space ({2:X}) + length ({3:X}) == "
@@ -1755,7 +1762,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
1755
1762
NextUnit = C.tell () + Length;
1756
1763
uint8_t Version = DA.getU16 (C);
1757
1764
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 " ,
1759
1766
SectionName, StartOffset, Version);
1760
1767
Success = false ;
1761
1768
// Can't parse the rest of this contribution, since we don't know the
@@ -1768,7 +1775,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
1768
1775
DA.setAddressSize (OffsetByteSize);
1769
1776
uint64_t Remainder = (Length - 4 ) % OffsetByteSize;
1770
1777
if (Remainder != 0 ) {
1771
- error ( ) << formatv (
1778
+ aggregate ( " Invalid section contribution length " ) << formatv (
1772
1779
" {0}: contribution {1:X}: invalid length ((length ({2:X}) "
1773
1780
" - header (0x4)) % offset size {3:X} == {4:X} != 0)\n " ,
1774
1781
SectionName, StartOffset, Length, OffsetByteSize, Remainder);
@@ -1789,7 +1796,7 @@ bool DWARFVerifier::verifyDebugStrOffsets(
1789
1796
}
1790
1797
if (StrData[StrOff - 1 ] == ' \0 ' )
1791
1798
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 "
1793
1800
" offset *{3:X} == {4:X}, is neither zero nor "
1794
1801
" immediately following a null character\n " ,
1795
1802
SectionName, StartOffset, Index, OffOff, StrOff);
@@ -1798,28 +1805,12 @@ bool DWARFVerifier::verifyDebugStrOffsets(
1798
1805
}
1799
1806
1800
1807
if (Error E = C.takeError ()) {
1808
+ // Aggregate TODO:
1801
1809
error () << SectionName << " : " << toString (std::move (E)) << ' \n ' ;
1802
1810
return false ;
1803
1811
}
1804
1812
return Success;
1805
1813
}
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
- */
1823
1814
1824
1815
std::string DWARFVerifier::ErrorAggregator::Clean (const char *s) {
1825
1816
// Find the position of the first alphabetic character
@@ -1839,12 +1830,18 @@ std::string DWARFVerifier::ErrorAggregator::Clean(const char *s) {
1839
1830
}
1840
1831
1841
1832
raw_ostream &DWARFVerifier::ErrorAggregator::operator <<(const char *s) {
1842
- Collect (Clean (s));
1843
- return Verifier.error () << s;
1833
+ return Collect (Clean (s)) << s;
1844
1834
}
1845
1835
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
1847
1838
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;
1848
1845
}
1849
1846
1850
1847
void DWARFVerifier::ErrorAggregator::Dump () {
@@ -1854,8 +1851,16 @@ void DWARFVerifier::ErrorAggregator::Dump() {
1854
1851
}
1855
1852
1856
1853
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);
1859
1864
}
1860
1865
1861
1866
DWARFVerifier::ErrorAggregator &DWARFVerifier::aggregate () {
0 commit comments