[llvm] llvm-dwarfdump --verify aggregated output to JSON file (PR #81762)

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 11:11:39 PST 2024


================
@@ -2026,12 +2028,35 @@ void OutputCategoryAggregator::EnumerateResults(
 }
 
 void DWARFVerifier::summarize() {
-  if (ErrorCategory.GetNumCategories() && DumpOpts.ShowAggregateErrors) {
+  if (!ErrorCategory.GetNumCategories())
+    return;
+  if (DumpOpts.ShowAggregateErrors) {
     error() << "Aggregated error counts:\n";
     ErrorCategory.EnumerateResults([&](StringRef s, unsigned count) {
       error() << s << " occurred " << count << " time(s).\n";
     });
   }
+  if (!DumpOpts.JsonSummaryFile.empty()) {
+    std::error_code EC;
+    raw_fd_ostream JsonStream(DumpOpts.JsonSummaryFile, EC, sys::fs::OF_Text);
+    if (EC) {
+      error() << "error opening aggregate error json file '"
+              << DumpOpts.JsonSummaryFile << "' for writing: " << EC.message()
+              << '\n';
+      return;
+    }
+
+    llvm::json::Object Categories;
+    ErrorCategory.EnumerateResults([&](StringRef category, unsigned count) {
+      llvm::json::Object Val;
+      Val.try_emplace("count", count);
+      Categories.try_emplace(category, std::move(Val));
+    });
+    llvm::json::Object RootNode;
+    RootNode.try_emplace("error-categories", std::move(Categories));
----------------
clayborg wrote:

Add `"error-count"` or `"num-errors"` as a top level key value pair. Useful for when there are no errors:
```
RootNode. try_emplace("error-count", TotalErrorCount);
```

https://github.com/llvm/llvm-project/pull/81762


More information about the llvm-commits mailing list