[llvm] GSym aggregated output to JSON file (PR #81763)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:10:48 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:
Even if we use llvm::json objects to create the JSON we need to make sure we emit valid JSON. Here if the category strings have special JSON reserved characters, it would create invalid JSON, so we need to make sure the category strings have special characters, like '"' characters, that it works correctly.
https://github.com/llvm/llvm-project/pull/81763
More information about the llvm-commits
mailing list