Skip to content

Commit 9016939

Browse files
Kevin Freikevinfrei
authored andcommitted
dwarfdump --verify aggregated output to JSON file
1 parent d2942a8 commit 9016939

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/include/llvm/DebugInfo/DIContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ struct DIDumpOptions {
206206
bool IsEH = false;
207207
bool DumpNonSkeleton = false;
208208
bool ShowAggregateErrors = false;
209+
std::string AggregateErrJsonFile = "";
209210
std::function<llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)>
210211
GetNameForDWARFReg;
211212

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/ADT/IntervalMap.h"
1010
#include "llvm/ADT/STLExtras.h"
1111
#include "llvm/ADT/SmallSet.h"
12+
#include "llvm/ADT/StringExtras.h"
1213
#include "llvm/BinaryFormat/Dwarf.h"
1314
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
1415
#include "llvm/DebugInfo/DWARF/DWARFAttribute.h"
@@ -29,6 +30,7 @@
2930
#include "llvm/Support/DJB.h"
3031
#include "llvm/Support/Error.h"
3132
#include "llvm/Support/ErrorHandling.h"
33+
#include "llvm/Support/FileSystem.h"
3234
#include "llvm/Support/FormatVariadic.h"
3335
#include "llvm/Support/WithColor.h"
3436
#include "llvm/Support/raw_ostream.h"
@@ -2026,12 +2028,32 @@ void OutputCategoryAggregator::EnumerateResults(
20262028
}
20272029

20282030
void DWARFVerifier::summarize() {
2029-
if (ErrorCategory.GetNumCategories() && DumpOpts.ShowAggregateErrors) {
2031+
if (!ErrorCategory.GetNumCategories())
2032+
return;
2033+
if (DumpOpts.ShowAggregateErrors) {
20302034
error() << "Aggregated error counts:\n";
20312035
ErrorCategory.EnumerateResults([&](StringRef s, unsigned count) {
20322036
error() << s << " occurred " << count << " time(s).\n";
20332037
});
20342038
}
2039+
if (!DumpOpts.AggregateErrJsonFile.empty()) {
2040+
std::error_code EC;
2041+
raw_fd_ostream JsonStream(DumpOpts.AggregateErrJsonFile, EC,
2042+
sys::fs::OF_Text | sys::fs::OF_None);
2043+
if (EC) {
2044+
error() << "error opening aggregate error json file '"
2045+
<< DumpOpts.AggregateErrJsonFile << "' for writing: "
2046+
<< EC.message() << '\n';
2047+
return;
2048+
}
2049+
JsonStream << "{\"errors\":[\n";
2050+
ErrorCategory.EnumerateResults([&](StringRef category, unsigned count) {
2051+
JsonStream << "\"category\":\"";
2052+
llvm::printEscapedString(category, JsonStream);
2053+
JsonStream << "\",\"count\":" << count;
2054+
});
2055+
JsonStream << "]}\n";
2056+
}
20352057
}
20362058

20372059
raw_ostream &DWARFVerifier::error() const { return WithColor::error(OS); }

llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ static opt<ErrorDetailLevel> ErrorDetails(
295295
clEnumValN(BothDetailsAndSummary, "full",
296296
"Display each error as well as a summary. [default]")),
297297
cat(DwarfDumpCategory));
298+
static opt<std::string> AggregationJsonFile(
299+
"aggregate-output-file", cl::init(""),
300+
cl::desc("Output JSON-formatted error summary to the specified file."),
301+
cl::value_desc("filename.json"), cat(DwarfDumpCategory));
298302
static opt<bool> Quiet("quiet", desc("Use with -verify to not emit to STDOUT."),
299303
cat(DwarfDumpCategory));
300304
static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture."),
@@ -836,6 +840,8 @@ int main(int argc, char **argv) {
836840
}
837841
if (!Verify && ErrorDetails != Unspecified)
838842
WithColor::warning() << "-error-detail has no affect without -verify";
843+
if (!Verify && !AggregationJsonFile.empty())
844+
WithColor::warning() << "-aggregation-json has no affect without -verify";
839845

840846
std::error_code EC;
841847
ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_TextWithCRLF);

0 commit comments

Comments
 (0)