[llvm] GSym aggregated output to JSON file (PR #81763)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:11:57 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:
I believe that if we use the llvm::json objects this will all be taken care of, but we should verify. If we don't the current code would end up creating invalid JSON if the category string had a '"'...
https://github.com/llvm/llvm-project/pull/81763
More information about the llvm-commits
mailing list