diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-cov/CodeCoverage.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/contrib/llvm/tools/llvm-cov/CodeCoverage.cpp b/contrib/llvm/tools/llvm-cov/CodeCoverage.cpp index 0a9807ab0033..6179c760d5b2 100644 --- a/contrib/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/contrib/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -15,6 +15,7 @@ #include "CoverageFilters.h" #include "CoverageReport.h" +#include "CoverageSummaryInfo.h" #include "CoverageViewOptions.h" #include "RenderingSupport.h" #include "SourceCoverageView.h" @@ -98,9 +99,6 @@ private: /// \brief If a demangler is available, demangle all symbol names. void demangleSymbols(const CoverageMapping &Coverage); - /// \brief Demangle \p Sym if possible. Otherwise, just return \p Sym. - StringRef getSymbolForHumans(StringRef Sym) const; - /// \brief Write out a source file view to the filesystem. void writeSourceFileView(StringRef SourceFile, CoverageMapping *Coverage, CoveragePrinter *Printer, bool ShowFilenames); @@ -136,10 +134,10 @@ private: /// The architecture the coverage mapping data targets. std::string CoverageArch; - /// A cache for demangled symbol names. - StringMap<std::string> DemangledNames; + /// A cache for demangled symbols. + DemangleCache DC; - /// Errors and warnings which have not been printed. + /// A lock which guards printing to stderr. std::mutex ErrsLock; /// A container for input source file buffers. @@ -267,7 +265,7 @@ CodeCoverageTool::createFunctionView(const FunctionRecord &Function, return nullptr; auto Expansions = FunctionCoverage.getExpansions(); - auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name), + auto View = SourceCoverageView::create(DC.demangle(Function.Name), SourceBuffer.get(), ViewOpts, std::move(FunctionCoverage)); attachExpansionSubViews(*View, Expansions, Coverage); @@ -293,7 +291,7 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile, for (const auto *Function : Coverage.getInstantiations(SourceFile)) { std::unique_ptr<SourceCoverageView> SubView{nullptr}; - StringRef Funcname = getSymbolForHumans(Function->Name); + StringRef Funcname = DC.demangle(Function->Name); if (Function->ExecutionCount > 0) { auto SubViewCoverage = Coverage.getCoverageForFunction(*Function); @@ -453,14 +451,9 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) { // Cache the demangled names. unsigned I = 0; for (const auto &Function : Coverage.getCoveredFunctions()) - DemangledNames[Function.Name] = Symbols[I++]; -} - -StringRef CodeCoverageTool::getSymbolForHumans(StringRef Sym) const { - const auto DemangledName = DemangledNames.find(Sym); - if (DemangledName == DemangledNames.end()) - return Sym; - return DemangledName->getValue(); + // On Windows, lines in the demangler's output file end with "\r\n". + // Splitting by '\n' keeps '\r's, so cut them now. + DC.DemangledNames[Function.Name] = Symbols[I++].rtrim(); } void CodeCoverageTool::writeSourceFileView(StringRef SourceFile, @@ -817,22 +810,28 @@ int CodeCoverageTool::show(int argc, const char **argv, int CodeCoverageTool::report(int argc, const char **argv, CommandLineParserType commandLineParser) { + cl::opt<bool> ShowFunctionSummaries( + "show-functions", cl::Optional, cl::init(false), + cl::desc("Show coverage summaries for each function")); + auto Err = commandLineParser(argc, argv); if (Err) return Err; - if (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML) + if (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML) { error("HTML output for summary reports is not yet supported."); + return 1; + } auto Coverage = load(); if (!Coverage) return 1; CoverageReport Report(ViewOpts, *Coverage.get()); - if (SourceFiles.empty()) + if (!ShowFunctionSummaries) Report.renderFileReports(llvm::outs()); else - Report.renderFunctionReports(SourceFiles, llvm::outs()); + Report.renderFunctionReports(SourceFiles, DC, llvm::outs()); return 0; } @@ -843,6 +842,11 @@ int CodeCoverageTool::export_(int argc, const char **argv, if (Err) return Err; + if (ViewOpts.Format != CoverageViewOptions::OutputFormat::Text) { + error("Coverage data can only be exported as textual JSON."); + return 1; + } + auto Coverage = load(); if (!Coverage) { error("Could not load coverage information"); |