[llvm] llvm-dwarfdump --verify aggregated output to JSON file (PR #81762)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:09:51 PST 2024
================
@@ -2026,12 +2028,36 @@ 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.AggregateErrJsonFile.empty()) {
+ std::error_code EC;
+ raw_fd_ostream JsonStream(DumpOpts.AggregateErrJsonFile, EC,
+ sys::fs::OF_Text);
+ if (EC) {
+ error() << "error opening aggregate error json file '"
+ << DumpOpts.AggregateErrJsonFile
+ << "' for writing: " << EC.message() << '\n';
+ return;
+ }
+ JsonStream << "{\"errors\":[\n";
+ bool prev = false;
+ ErrorCategory.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:
Like gsym patch, use llvm::json objects to create the JSON, then convert to a string. This helps ensure that we emit valid JSON. Here if the category strings have special JSON reserved characters, it would create invalid JSON
https://github.com/llvm/llvm-project/pull/81762
More information about the llvm-commits
mailing list