Skip to content

Commit bfdd782

Browse files
kevinfreiKevin Frei
and
Kevin Frei
authored
Aggregate errors from llvm-dwarfdump --verify (#79648)
The amount and format of output from `llvm-dwarfdump --verify` makes it quite difficult to know if a change to a tool that produces or modifies DWARF is causing new problems, or is fixing existing problems. This diff adds a categorized summary of issues found by the DWARF verifier, on by default, at the bottom of the error output. The change includes a new `--error-display` option with 4 settings: * `--error-display=quiet`: Only display if errors occurred, but no details or summary are printed. * `--error-display=summary`: Only display the aggregated summary of errors with no error detail. * `--error-display=details`: Only display the detailed error messages with no summary (previous behavior) * `--error-display=full`: Display both the detailed error messages and the aggregated summary of errors (the default) I changed a handful of tests that were failing due to new output, adding the flag to use the old behavior for all but a couple. For those two I added the new aggregated output to the expected output of the test. The `OutputCategoryAggregator` is a pretty simple little class that @clayborg suggested to allow code to only be run to dump detail if it's enabled, while still collating counts of the category. Knowing that the lambda passed in is only conditionally executed is pretty important (handling errors has to be done *outside* the lambda). I'm happy to move this somewhere else (and change/improve it) to be more broadly useful if folks would like. --------- Co-authored-by: Kevin Frei <[email protected]>
1 parent 09b4649 commit bfdd782

13 files changed

+560
-283
lines changed

llvm/include/llvm/DebugInfo/DIContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ struct DIDumpOptions {
205205
bool DisplayRawContents = false;
206206
bool IsEH = false;
207207
bool DumpNonSkeleton = false;
208+
bool ShowAggregateErrors = false;
208209
std::function<llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)>
209210
GetNameForDWARFReg;
210211

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ class DWARFDebugAbbrev;
3030
class DataExtractor;
3131
struct DWARFSection;
3232

33+
class OutputCategoryAggregator {
34+
private:
35+
std::map<std::string, unsigned> Aggregation;
36+
bool IncludeDetail;
37+
38+
public:
39+
OutputCategoryAggregator(bool includeDetail = false)
40+
: IncludeDetail(includeDetail) {}
41+
void ShowDetail(bool showDetail) { IncludeDetail = showDetail; }
42+
size_t GetNumCategories() const { return Aggregation.size(); }
43+
void Report(StringRef s, std::function<void()> detailCallback);
44+
void EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
45+
};
46+
3347
/// A class that verifies DWARF debug information given a DWARF Context.
3448
class DWARFVerifier {
3549
public:
@@ -81,6 +95,7 @@ class DWARFVerifier {
8195
DWARFContext &DCtx;
8296
DIDumpOptions DumpOpts;
8397
uint32_t NumDebugLineErrors = 0;
98+
OutputCategoryAggregator ErrorCategory;
8499
// Used to relax some checks that do not currently work portably
85100
bool IsObjectFile;
86101
bool IsMachOObject;
@@ -348,6 +363,9 @@ class DWARFVerifier {
348363
bool verifyDebugStrOffsets(
349364
StringRef SectionName, const DWARFSection &Section, StringRef StrData,
350365
void (DWARFObject::*)(function_ref<void(const DWARFSection &)>) const);
366+
367+
/// Emits any aggregate information collected, depending on the dump options
368+
void summarize();
351369
};
352370

353371
static inline bool operator<(const DWARFVerifier::DieRangeInfo &LHS,

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ bool DWARFContext::verify(raw_ostream &OS, DIDumpOptions DumpOpts) {
14081408
if (DumpOpts.DumpType & DIDT_DebugStrOffsets)
14091409
Success &= verifier.handleDebugStrOffsets();
14101410
Success &= verifier.handleAccelTables();
1411+
verifier.summarize();
14111412
return Success;
14121413
}
14131414

0 commit comments

Comments
 (0)