[llvm] GSym aggregated output to JSON file (PR #81763)

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 14 13:58:54 PST 2024


================
@@ -515,10 +520,31 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
     // Call error() if we have an error and it will exit with a status of 1
     if (auto Err = convertFileToGSYM(Aggregation))
       error("DWARF conversion failed: ", std::move(Err));
+
     // Report the errors from aggregator:
     Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
       OS << category << " occurred " << count << " time(s)\n";
     });
+    if (!AggregateJsonFile.empty()) {
+      std::error_code EC;
+      raw_fd_ostream JsonStream(AggregateJsonFile, EC, sys::fs::OF_Text);
+      if (EC) {
+        OS << "error opening aggregate error json file '" << AggregateJsonFile
+           << "' for writing: " << EC.message() << '\n';
+        return 1;
+      }
+      JsonStream << "{\"errors\":[\n";
+      bool prev = false;
+      Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
+        if (prev)
+          JsonStream << ",\n";
+        JsonStream << "{\"category\":\"";
+        llvm::printEscapedString(category, JsonStream);
+        JsonStream << "\",\"count\":" << count << "}";
+        prev = true;
+      });
+      JsonStream << "\n]}\n";
----------------
clayborg wrote:

Instead of making manual JSON, I would use the llvm JSON objects.  There are many examples in lldb/tools/lldb-dap/lldb-dap.cpp or in lldb/tools/lldb-dap/JSONUtils.cpp.

We should probably agree on the format first. I was thinking something like a top level dictionary with a value called "errors" that contains a dictionary of `"<category>" : <object>`:
```
{ "error-categories":  
  {
    "Overlapping address ranges":  {"count": 12 },
    "Invalid file index":  {"count": 12 },
  }
}
```
This way if we eventually add information per category, like say a vector of DIE offsets that show where this issue is in the DWARF, can add it without any changes to the format:
```
{ "error-categories":  
  {
    "Overlapping address ranges":  {"count": 12, "dies": [12312312, 223423423] },
    "Invalid file index":  {"count": 32, , "dies": [443423432, 234234323]},
  }
}
```

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


More information about the llvm-commits mailing list