summaryrefslogtreecommitdiff
path: root/tools/llvm-cov/CodeCoverage.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
commit044eb2f6afba375a914ac9d8024f8f5142bb912e (patch)
tree1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /tools/llvm-cov/CodeCoverage.cpp
parenteb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff)
Notes
Diffstat (limited to 'tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r--tools/llvm-cov/CodeCoverage.cpp358
1 files changed, 240 insertions, 118 deletions
diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp
index 3cbd6591134b..00258f2a1b33 100644
--- a/tools/llvm-cov/CodeCoverage.cpp
+++ b/tools/llvm-cov/CodeCoverage.cpp
@@ -35,13 +35,16 @@
#include "llvm/Support/Threading.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/ToolOutputFile.h"
+
#include <functional>
+#include <map>
#include <system_error>
using namespace llvm;
using namespace coverage;
void exportCoverageDataToJson(const coverage::CoverageMapping &CoverageMapping,
+ const CoverageViewOptions &Options,
raw_ostream &OS);
namespace {
@@ -94,6 +97,10 @@ private:
/// \brief Load the coverage mapping data. Return nullptr if an error occurred.
std::unique_ptr<CoverageMapping> load();
+ /// \brief Create a mapping from files in the Coverage data to local copies
+ /// (path-equivalence).
+ void remapPathNames(const CoverageMapping &Coverage);
+
/// \brief Remove input source files which aren't mapped by \p Coverage.
void removeUnmappedInputs(const CoverageMapping &Coverage);
@@ -125,15 +132,16 @@ private:
/// A list of input source files.
std::vector<std::string> SourceFiles;
- /// Whether or not we're in -filename-equivalence mode.
- bool CompareFilenamesOnly;
-
- /// In -filename-equivalence mode, this maps absolute paths from the
- /// coverage mapping data to input source files.
+ /// In -path-equivalence mode, this maps the absolute paths from the coverage
+ /// mapping data to the input source files.
StringMap<std::string> RemappedFilenames;
+ /// The coverage data path to be remapped from, and the source path to be
+ /// remapped to, when using -path-equivalence.
+ Optional<std::pair<std::string, std::string>> PathRemapping;
+
/// The architecture the coverage mapping data targets.
- std::string CoverageArch;
+ std::vector<StringRef> CoverageArches;
/// A cache for demangled symbols.
DemangleCache DC;
@@ -145,6 +153,9 @@ private:
std::mutex LoadedSourceFilesLock;
std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
LoadedSourceFiles;
+
+ /// Whitelist from -name-whitelist to be used for filtering.
+ std::unique_ptr<SpecialCaseList> NameWhitelist;
};
}
@@ -171,24 +182,20 @@ void CodeCoverageTool::warning(const Twine &Message, StringRef Whence) {
}
void CodeCoverageTool::addCollectedPath(const std::string &Path) {
- if (CompareFilenamesOnly) {
- SourceFiles.emplace_back(Path);
- } else {
- SmallString<128> EffectivePath(Path);
- if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) {
- error(EC.message(), Path);
- return;
- }
- sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
- SourceFiles.emplace_back(EffectivePath.str());
+ SmallString<128> EffectivePath(Path);
+ if (std::error_code EC = sys::fs::make_absolute(EffectivePath)) {
+ error(EC.message(), Path);
+ return;
}
+ sys::path::remove_dots(EffectivePath, /*remove_dot_dots=*/true);
+ SourceFiles.emplace_back(EffectivePath.str());
}
void CodeCoverageTool::collectPaths(const std::string &Path) {
llvm::sys::fs::file_status Status;
llvm::sys::fs::status(Path, Status);
if (!llvm::sys::fs::exists(Status)) {
- if (CompareFilenamesOnly)
+ if (PathRemapping)
addCollectedPath(Path);
else
error("Missing source file", Path);
@@ -288,26 +295,34 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
auto View = SourceCoverageView::create(SourceFile, SourceBuffer.get(),
ViewOpts, std::move(FileCoverage));
attachExpansionSubViews(*View, Expansions, Coverage);
+ if (!ViewOpts.ShowFunctionInstantiations)
+ return View;
- for (const auto *Function : Coverage.getInstantiations(SourceFile)) {
- std::unique_ptr<SourceCoverageView> SubView{nullptr};
+ for (const auto &Group : Coverage.getInstantiationGroups(SourceFile)) {
+ // Skip functions which have a single instantiation.
+ if (Group.size() < 2)
+ continue;
- StringRef Funcname = DC.demangle(Function->Name);
+ for (const FunctionRecord *Function : Group.getInstantiations()) {
+ std::unique_ptr<SourceCoverageView> SubView{nullptr};
- if (Function->ExecutionCount > 0) {
- auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
- auto SubViewExpansions = SubViewCoverage.getExpansions();
- SubView = SourceCoverageView::create(
- Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
- attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
- }
+ StringRef Funcname = DC.demangle(Function->Name);
- unsigned FileID = Function->CountedRegions.front().FileID;
- unsigned Line = 0;
- for (const auto &CR : Function->CountedRegions)
- if (CR.FileID == FileID)
- Line = std::max(CR.LineEnd, Line);
- View->addInstantiation(Funcname, Line, std::move(SubView));
+ if (Function->ExecutionCount > 0) {
+ auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
+ auto SubViewExpansions = SubViewCoverage.getExpansions();
+ SubView = SourceCoverageView::create(
+ Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
+ attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
+ }
+
+ unsigned FileID = Function->CountedRegions.front().FileID;
+ unsigned Line = 0;
+ for (const auto &CR : Function->CountedRegions)
+ if (CR.FileID == FileID)
+ Line = std::max(CR.LineEnd, Line);
+ View->addInstantiation(Funcname, Line, std::move(SubView));
+ }
}
return View;
}
@@ -329,7 +344,7 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
warning("profile data may be out of date - object is newer",
ObjectFilename);
auto CoverageOrErr =
- CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArch);
+ CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArches);
if (Error E = CoverageOrErr.takeError()) {
error("Failed to load coverage: " + toString(std::move(E)),
join(ObjectFilenames.begin(), ObjectFilenames.end(), ", "));
@@ -337,9 +352,25 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
}
auto Coverage = std::move(CoverageOrErr.get());
unsigned Mismatched = Coverage->getMismatchedCount();
- if (Mismatched)
+ if (Mismatched) {
warning(utostr(Mismatched) + " functions have mismatched data");
+ if (ViewOpts.Debug) {
+ for (const auto &HashMismatch : Coverage->getHashMismatches())
+ errs() << "hash-mismatch: "
+ << "No profile record found for '" << HashMismatch.first << "'"
+ << " with hash = 0x" << utohexstr(HashMismatch.second) << "\n";
+
+ for (const auto &CounterMismatch : Coverage->getCounterMismatches())
+ errs() << "counter-mismatch: "
+ << "Coverage mapping for " << CounterMismatch.first
+ << " only has " << CounterMismatch.second
+ << " valid counter expressions\n";
+ }
+ }
+
+ remapPathNames(*Coverage);
+
if (!SourceFiles.empty())
removeUnmappedInputs(*Coverage);
@@ -348,33 +379,58 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
return Coverage;
}
+void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) {
+ if (!PathRemapping)
+ return;
+
+ // Convert remapping paths to native paths with trailing seperators.
+ auto nativeWithTrailing = [](StringRef Path) -> std::string {
+ if (Path.empty())
+ return "";
+ SmallString<128> NativePath;
+ sys::path::native(Path, NativePath);
+ if (!sys::path::is_separator(NativePath.back()))
+ NativePath += sys::path::get_separator();
+ return NativePath.c_str();
+ };
+ std::string RemapFrom = nativeWithTrailing(PathRemapping->first);
+ std::string RemapTo = nativeWithTrailing(PathRemapping->second);
+
+ // Create a mapping from coverage data file paths to local paths.
+ for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
+ SmallString<128> NativeFilename;
+ sys::path::native(Filename, NativeFilename);
+ if (NativeFilename.startswith(RemapFrom)) {
+ RemappedFilenames[Filename] =
+ RemapTo + NativeFilename.substr(RemapFrom.size()).str();
+ }
+ }
+
+ // Convert input files from local paths to coverage data file paths.
+ StringMap<std::string> InvRemappedFilenames;
+ for (const auto &RemappedFilename : RemappedFilenames)
+ InvRemappedFilenames[RemappedFilename.getValue()] = RemappedFilename.getKey();
+
+ for (std::string &Filename : SourceFiles) {
+ SmallString<128> NativeFilename;
+ sys::path::native(Filename, NativeFilename);
+ auto CovFileName = InvRemappedFilenames.find(NativeFilename);
+ if (CovFileName != InvRemappedFilenames.end())
+ Filename = CovFileName->second;
+ }
+}
+
void CodeCoverageTool::removeUnmappedInputs(const CoverageMapping &Coverage) {
std::vector<StringRef> CoveredFiles = Coverage.getUniqueSourceFiles();
auto UncoveredFilesIt = SourceFiles.end();
- if (!CompareFilenamesOnly) {
- // The user may have specified source files which aren't in the coverage
- // mapping. Filter these files away.
- UncoveredFilesIt = std::remove_if(
- SourceFiles.begin(), SourceFiles.end(), [&](const std::string &SF) {
- return !std::binary_search(CoveredFiles.begin(), CoveredFiles.end(),
- SF);
- });
- } else {
- for (auto &SF : SourceFiles) {
- StringRef SFBase = sys::path::filename(SF);
- for (const auto &CF : CoveredFiles) {
- if (SFBase == sys::path::filename(CF)) {
- RemappedFilenames[CF] = SF;
- SF = CF;
- break;
- }
- }
- }
- UncoveredFilesIt = std::remove_if(
- SourceFiles.begin(), SourceFiles.end(),
- [&](const std::string &SF) { return !RemappedFilenames.count(SF); });
- }
+ // The user may have specified source files which aren't in the coverage
+ // mapping. Filter these files away.
+ UncoveredFilesIt = std::remove_if(
+ SourceFiles.begin(), SourceFiles.end(), [&](const std::string &SF) {
+ return !std::binary_search(CoveredFiles.begin(), CoveredFiles.end(),
+ SF);
+ });
SourceFiles.erase(UncoveredFilesIt, SourceFiles.end());
}
@@ -392,7 +448,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
error(InputPath, EC.message());
return;
}
- tool_output_file InputTOF{InputPath, InputFD};
+ ToolOutputFile InputTOF{InputPath, InputFD};
unsigned NumSymbols = 0;
for (const auto &Function : Coverage.getCoveredFunctions()) {
@@ -410,7 +466,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
error(OutputPath, EC.message());
return;
}
- tool_output_file OutputTOF{OutputPath, OutputFD};
+ ToolOutputFile OutputTOF{OutputPath, OutputFD};
OutputTOF.os().close();
// Invoke the demangler.
@@ -418,10 +474,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
for (const std::string &Arg : ViewOpts.DemanglerOpts)
ArgsV.push_back(Arg.c_str());
ArgsV.push_back(nullptr);
- StringRef InputPathRef = InputPath.str();
- StringRef OutputPathRef = OutputPath.str();
- StringRef StderrRef;
- const StringRef *Redirects[] = {&InputPathRef, &OutputPathRef, &StderrRef};
+ Optional<StringRef> Redirects[] = {InputPath.str(), OutputPath.str(), {""}};
std::string ErrMsg;
int RC = sys::ExecuteAndWait(ViewOpts.DemanglerOpts[0], ArgsV.data(),
/*env=*/nullptr, Redirects, /*secondsToWait=*/0,
@@ -475,7 +528,8 @@ void CodeCoverageTool::writeSourceFileView(StringRef SourceFile,
auto OS = std::move(OSOrErr.get());
View->print(*OS.get(), /*Wholefile=*/true,
- /*ShowSourceName=*/ShowFilenames);
+ /*ShowSourceName=*/ShowFilenames,
+ /*ShowTitle=*/ViewOpts.hasOutputDirectory());
Printer->closeViewFile(std::move(OS));
}
@@ -499,8 +553,8 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
cl::desc(
"File with the profile data obtained after an instrumented run"));
- cl::opt<std::string> Arch(
- "arch", cl::desc("architecture of the coverage mapping binary"));
+ cl::list<std::string> Arches(
+ "arch", cl::desc("architectures of the coverage mapping binaries"));
cl::opt<bool> DebugDump("dump", cl::Optional,
cl::desc("Show internal debug dump"));
@@ -513,10 +567,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
"HTML output")),
cl::init(CoverageViewOptions::OutputFormat::Text));
- cl::opt<bool> FilenameEquivalence(
- "filename-equivalence", cl::Optional,
- cl::desc("Treat source files as equivalent to paths in the coverage data "
- "when the file names match, even if the full paths do not"));
+ cl::opt<std::string> PathRemap(
+ "path-equivalence", cl::Optional,
+ cl::desc("<from>,<to> Map coverage data paths to local source file "
+ "paths"));
cl::OptionCategory FilteringCategory("Function filtering options");
@@ -525,6 +579,12 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
cl::desc("Show code coverage only for functions with the given name"),
cl::ZeroOrMore, cl::cat(FilteringCategory));
+ cl::list<std::string> NameFilterFiles(
+ "name-whitelist", cl::Optional,
+ cl::desc("Show code coverage only for functions listed in the given "
+ "file"),
+ cl::ZeroOrMore, cl::cat(FilteringCategory));
+
cl::list<std::string> NameRegexFilters(
"name-regex", cl::Optional,
cl::desc("Show code coverage only for functions that match the given "
@@ -562,10 +622,22 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
cl::list<std::string> DemanglerOpts(
"Xdemangler", cl::desc("<demangler-path>|<demangler-option>"));
+ cl::opt<bool> RegionSummary(
+ "show-region-summary", cl::Optional,
+ cl::desc("Show region statistics in summary table"),
+ cl::init(true));
+
+ cl::opt<bool> InstantiationSummary(
+ "show-instantiation-summary", cl::Optional,
+ cl::desc("Show instantiation statistics in summary table"));
+
+ cl::opt<bool> SummaryOnly(
+ "summary-only", cl::Optional,
+ cl::desc("Export only summary information for each source file"));
+
auto commandLineParser = [&, this](int argc, const char **argv) -> int {
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
ViewOpts.Debug = DebugDump;
- CompareFilenamesOnly = FilenameEquivalence;
if (!CovFilename.empty())
ObjectFilenames.emplace_back(CovFilename);
@@ -590,6 +662,12 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
break;
}
+ // If path-equivalence was given and is a comma seperated pair then set
+ // PathRemapping.
+ auto EquivPair = StringRef(PathRemap).split(',');
+ if (!(EquivPair.first.empty() && EquivPair.second.empty()))
+ PathRemapping = EquivPair;
+
// If a demangler is supplied, check if it exists and register it.
if (DemanglerOpts.size()) {
auto DemanglerPathOrErr = sys::findProgramByName(DemanglerOpts[0]);
@@ -602,21 +680,33 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
ViewOpts.DemanglerOpts.swap(DemanglerOpts);
}
+ // Read in -name-whitelist files.
+ if (!NameFilterFiles.empty()) {
+ std::string SpecialCaseListErr;
+ NameWhitelist =
+ SpecialCaseList::create(NameFilterFiles, SpecialCaseListErr);
+ if (!NameWhitelist)
+ error(SpecialCaseListErr);
+ }
+
// Create the function filters
- if (!NameFilters.empty() || !NameRegexFilters.empty()) {
- auto NameFilterer = new CoverageFilters;
+ if (!NameFilters.empty() || NameWhitelist || !NameRegexFilters.empty()) {
+ auto NameFilterer = llvm::make_unique<CoverageFilters>();
for (const auto &Name : NameFilters)
NameFilterer->push_back(llvm::make_unique<NameCoverageFilter>(Name));
+ if (NameWhitelist)
+ NameFilterer->push_back(
+ llvm::make_unique<NameWhitelistCoverageFilter>(*NameWhitelist));
for (const auto &Regex : NameRegexFilters)
NameFilterer->push_back(
llvm::make_unique<NameRegexCoverageFilter>(Regex));
- Filters.push_back(std::unique_ptr<CoverageFilter>(NameFilterer));
+ Filters.push_back(std::move(NameFilterer));
}
if (RegionCoverageLtFilter.getNumOccurrences() ||
RegionCoverageGtFilter.getNumOccurrences() ||
LineCoverageLtFilter.getNumOccurrences() ||
LineCoverageGtFilter.getNumOccurrences()) {
- auto StatFilterer = new CoverageFilters;
+ auto StatFilterer = llvm::make_unique<CoverageFilters>();
if (RegionCoverageLtFilter.getNumOccurrences())
StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
RegionCoverageFilter::LessThan, RegionCoverageLtFilter));
@@ -629,15 +719,22 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
if (LineCoverageGtFilter.getNumOccurrences())
StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
RegionCoverageFilter::GreaterThan, LineCoverageGtFilter));
- Filters.push_back(std::unique_ptr<CoverageFilter>(StatFilterer));
+ Filters.push_back(std::move(StatFilterer));
}
- if (!Arch.empty() &&
- Triple(Arch).getArch() == llvm::Triple::ArchType::UnknownArch) {
- error("Unknown architecture: " + Arch);
- return 1;
+ if (!Arches.empty()) {
+ for (const std::string &Arch : Arches) {
+ if (Triple(Arch).getArch() == llvm::Triple::ArchType::UnknownArch) {
+ error("Unknown architecture: " + Arch);
+ return 1;
+ }
+ CoverageArches.emplace_back(Arch);
+ }
+ if (CoverageArches.size() != ObjectFilenames.size()) {
+ error("Number of architectures doesn't match the number of objects");
+ return 1;
+ }
}
- CoverageArch = Arch;
for (const std::string &File : InputSourceFiles)
collectPaths(File);
@@ -648,6 +745,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
::exit(0);
}
+ ViewOpts.ShowRegionSummary = RegionSummary;
+ ViewOpts.ShowInstantiationSummary = InstantiationSummary;
+ ViewOpts.ExportSummaryOnly = SummaryOnly;
+
return 0;
};
@@ -689,7 +790,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
cl::opt<bool> ShowInstantiations("show-instantiations", cl::Optional,
cl::desc("Show function instantiations"),
- cl::cat(ViewCategory));
+ cl::init(true), cl::cat(ViewCategory));
cl::opt<std::string> ShowOutputDirectory(
"output-dir", cl::init(""),
@@ -720,7 +821,6 @@ int CodeCoverageTool::show(int argc, const char **argv,
ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
!ShowRegions || ShowBestLineRegionsCounts;
ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts;
- ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
ViewOpts.ShowExpandedRegions = ShowExpansions;
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
@@ -753,29 +853,54 @@ int CodeCoverageTool::show(int argc, const char **argv,
auto Printer = CoveragePrinter::create(ViewOpts);
- if (!Filters.empty()) {
- auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true);
- if (Error E = OSOrErr.takeError()) {
- error("Could not create view file!", toString(std::move(E)));
+ if (SourceFiles.empty())
+ // Get the source files from the function coverage mapping.
+ for (StringRef Filename : Coverage->getUniqueSourceFiles())
+ SourceFiles.push_back(Filename);
+
+ // Create an index out of the source files.
+ if (ViewOpts.hasOutputDirectory()) {
+ if (Error E = Printer->createIndexFile(SourceFiles, *Coverage, Filters)) {
+ error("Could not create index file!", toString(std::move(E)));
return 1;
}
- auto OS = std::move(OSOrErr.get());
-
- // Show functions.
- for (const auto &Function : Coverage->getCoveredFunctions()) {
- if (!Filters.matches(Function))
- continue;
+ }
- auto mainView = createFunctionView(Function, *Coverage);
- if (!mainView) {
- warning("Could not read coverage for '" + Function.Name + "'.");
- continue;
+ if (!Filters.empty()) {
+ // Build the map of filenames to functions.
+ std::map<llvm::StringRef, std::vector<const FunctionRecord *>>
+ FilenameFunctionMap;
+ for (const auto &SourceFile : SourceFiles)
+ for (const auto &Function : Coverage->getCoveredFunctions(SourceFile))
+ if (Filters.matches(*Coverage.get(), Function))
+ FilenameFunctionMap[SourceFile].push_back(&Function);
+
+ // Only print filter matching functions for each file.
+ for (const auto &FileFunc : FilenameFunctionMap) {
+ StringRef File = FileFunc.first;
+ const auto &Functions = FileFunc.second;
+
+ auto OSOrErr = Printer->createViewFile(File, /*InToplevel=*/false);
+ if (Error E = OSOrErr.takeError()) {
+ error("Could not create view file!", toString(std::move(E)));
+ return 1;
+ }
+ auto OS = std::move(OSOrErr.get());
+
+ bool ShowTitle = ViewOpts.hasOutputDirectory();
+ for (const auto *Function : Functions) {
+ auto FunctionView = createFunctionView(*Function, *Coverage);
+ if (!FunctionView) {
+ warning("Could not read coverage for '" + Function->Name + "'.");
+ continue;
+ }
+ FunctionView->print(*OS.get(), /*WholeFile=*/false,
+ /*ShowSourceName=*/true, ShowTitle);
+ ShowTitle = false;
}
- mainView->print(*OS.get(), /*WholeFile=*/false, /*ShowSourceName=*/true);
+ Printer->closeViewFile(std::move(OS));
}
-
- Printer->closeViewFile(std::move(OS));
return 0;
}
@@ -784,19 +909,6 @@ int CodeCoverageTool::show(int argc, const char **argv,
(SourceFiles.size() != 1) || ViewOpts.hasOutputDirectory() ||
(ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML);
- if (SourceFiles.empty())
- // Get the source files from the function coverage mapping.
- for (StringRef Filename : Coverage->getUniqueSourceFiles())
- SourceFiles.push_back(Filename);
-
- // Create an index out of the source files.
- if (ViewOpts.hasOutputDirectory()) {
- if (Error E = Printer->createIndexFile(SourceFiles, *Coverage)) {
- error("Could not create index file!", toString(std::move(E)));
- return 1;
- }
- }
-
// If NumThreads is not specified, auto-detect a good default.
if (NumThreads == 0)
NumThreads =
@@ -839,10 +951,20 @@ int CodeCoverageTool::report(int argc, const char **argv,
return 1;
CoverageReport Report(ViewOpts, *Coverage.get());
- if (!ShowFunctionSummaries)
- Report.renderFileReports(llvm::outs());
- else
+ if (!ShowFunctionSummaries) {
+ if (SourceFiles.empty())
+ Report.renderFileReports(llvm::outs());
+ else
+ Report.renderFileReports(llvm::outs(), SourceFiles);
+ } else {
+ if (SourceFiles.empty()) {
+ error("Source files must be specified when -show-functions=true is "
+ "specified");
+ return 1;
+ }
+
Report.renderFunctionReports(SourceFiles, DC, llvm::outs());
+ }
return 0;
}
@@ -864,7 +986,7 @@ int CodeCoverageTool::export_(int argc, const char **argv,
return 1;
}
- exportCoverageDataToJson(*Coverage.get(), outs());
+ exportCoverageDataToJson(*Coverage.get(), ViewOpts, outs());
return 0;
}