|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "llvm/ADT/STLExtras.h"
|
| 10 | +#include "llvm/ADT/StringExtras.h" |
10 | 11 | #include "llvm/DebugInfo/DIContext.h"
|
11 | 12 | #include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
12 | 13 | #include "llvm/Object/Archive.h"
|
@@ -87,6 +88,7 @@ static std::vector<std::string> InputFilenames;
|
87 | 88 | static std::string ConvertFilename;
|
88 | 89 | static std::vector<std::string> ArchFilters;
|
89 | 90 | static std::string OutputFilename;
|
| 91 | +static std::string AggregateJsonFile; |
90 | 92 | static bool Verify;
|
91 | 93 | static unsigned NumThreads;
|
92 | 94 | static uint64_t SegmentSize;
|
@@ -138,6 +140,9 @@ static void parseArgs(int argc, char **argv) {
|
138 | 140 | if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
|
139 | 141 | OutputFilename = A->getValue();
|
140 | 142 |
|
| 143 | + if (const llvm::opt::Arg *A = Args.getLastArg(OPT_aggregate_error_file_EQ)) |
| 144 | + AggregateJsonFile = A->getValue(); |
| 145 | + |
141 | 146 | Verify = Args.hasArg(OPT_verify);
|
142 | 147 |
|
143 | 148 | if (const llvm::opt::Arg *A = Args.getLastArg(OPT_num_threads_EQ)) {
|
@@ -515,10 +520,28 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
|
515 | 520 | // Call error() if we have an error and it will exit with a status of 1
|
516 | 521 | if (auto Err = convertFileToGSYM(Aggregation))
|
517 | 522 | error("DWARF conversion failed: ", std::move(Err));
|
| 523 | + |
518 | 524 | // Report the errors from aggregator:
|
519 | 525 | Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
|
520 | 526 | OS << category << " occurred " << count << " time(s)\n";
|
521 | 527 | });
|
| 528 | + if (!AggregateJsonFile.empty()) { |
| 529 | + std::error_code EC; |
| 530 | + raw_fd_ostream JsonStream(AggregateJsonFile, EC, |
| 531 | + sys::fs::OF_Text | sys::fs::OF_None); |
| 532 | + if (EC) { |
| 533 | + OS << "error opening aggregate error json file '" << AggregateJsonFile |
| 534 | + << "' for writing: " << EC.message() << '\n'; |
| 535 | + return 1; |
| 536 | + } |
| 537 | + JsonStream << "{\"errors\":[\n"; |
| 538 | + Aggregation.EnumerateResults([&](StringRef category, unsigned count) { |
| 539 | + JsonStream << "\"category\":\""; |
| 540 | + llvm::printEscapedString(category, JsonStream); |
| 541 | + JsonStream << "\",\"count\":" << count; |
| 542 | + }); |
| 543 | + JsonStream << "]}\n"; |
| 544 | + } |
522 | 545 | return 0;
|
523 | 546 | }
|
524 | 547 |
|
|
0 commit comments