aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-cov
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-cov')
-rw-r--r--tools/llvm-cov/CodeCoverage.cpp37
-rw-r--r--tools/llvm-cov/gcov.cpp7
-rw-r--r--tools/llvm-cov/llvm-cov.cpp34
3 files changed, 47 insertions, 31 deletions
diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp
index cf8ab33..0331a02 100644
--- a/tools/llvm-cov/CodeCoverage.cpp
+++ b/tools/llvm-cov/CodeCoverage.cpp
@@ -20,6 +20,7 @@
#include "SourceCoverageView.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ProfileData/CoverageMapping.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/CommandLine.h"
@@ -28,6 +29,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include <functional>
#include <system_error>
@@ -87,6 +89,7 @@ public:
LoadedSourceFiles;
bool CompareFilenamesOnly;
StringMap<std::string> RemappedFilenames;
+ llvm::Triple::ArchType CoverageArch;
};
}
@@ -193,7 +196,8 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
}
std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
- auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename);
+ auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename,
+ CoverageArch);
if (std::error_code EC = CoverageOrErr.getError()) {
colored_ostream(errs(), raw_ostream::RED)
<< "error: Failed to load coverage: " << EC.message();
@@ -242,6 +246,9 @@ 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::opt<bool> DebugDump("dump", cl::Optional,
cl::desc("Show internal debug dump"));
@@ -287,11 +294,19 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
"greater than the given threshold"),
cl::cat(FilteringCategory));
+ cl::opt<cl::boolOrDefault> UseColor(
+ "use-color", cl::desc("Emit colored output (default=autodetect)"),
+ cl::init(cl::BOU_UNSET));
+
auto commandLineParser = [&, this](int argc, const char **argv) -> int {
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
ViewOpts.Debug = DebugDump;
CompareFilenamesOnly = FilenameEquivalence;
+ ViewOpts.Colors = UseColor == cl::BOU_UNSET
+ ? sys::Process::StandardOutHasColors()
+ : UseColor == cl::BOU_TRUE;
+
// Create the function filters
if (!NameFilters.empty() || !NameRegexFilters.empty()) {
auto NameFilterer = new CoverageFilters;
@@ -322,6 +337,16 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
Filters.push_back(std::unique_ptr<CoverageFilter>(StatFilterer));
}
+ if (Arch.empty())
+ CoverageArch = llvm::Triple::ArchType::UnknownArch;
+ else {
+ CoverageArch = Triple(Arch).getArch();
+ if (CoverageArch == llvm::Triple::ArchType::UnknownArch) {
+ errs() << "error: Unknown architecture: " << Arch << "\n";
+ return 1;
+ }
+ }
+
for (const auto &File : InputSourceFiles) {
SmallString<128> Path(File);
if (!CompareFilenamesOnly)
@@ -372,15 +397,10 @@ int CodeCoverageTool::show(int argc, const char **argv,
cl::desc("Show function instantiations"),
cl::cat(ViewCategory));
- cl::opt<bool> NoColors("no-colors", cl::Optional,
- cl::desc("Don't show text colors"), cl::init(false),
- cl::cat(ViewCategory));
-
auto Err = commandLineParser(argc, argv);
if (Err)
return Err;
- ViewOpts.Colors = !NoColors;
ViewOpts.ShowLineNumbers = true;
ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
!ShowRegions || ShowBestLineRegionsCounts;
@@ -446,15 +466,10 @@ int CodeCoverageTool::show(int argc, const char **argv,
int CodeCoverageTool::report(int argc, const char **argv,
CommandLineParserType commandLineParser) {
- cl::opt<bool> NoColors("no-colors", cl::Optional,
- cl::desc("Don't show text colors"), cl::init(false));
-
auto Err = commandLineParser(argc, argv);
if (Err)
return Err;
- ViewOpts.Colors = !NoColors;
-
auto Coverage = load();
if (!Coverage)
return 1;
diff --git a/tools/llvm-cov/gcov.cpp b/tools/llvm-cov/gcov.cpp
index c0a48f8..4377a50 100644
--- a/tools/llvm-cov/gcov.cpp
+++ b/tools/llvm-cov/gcov.cpp
@@ -23,9 +23,10 @@
#include <system_error>
using namespace llvm;
-void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
- const std::string &InputGCNO, const std::string &InputGCDA,
- bool DumpGCOV, const GCOVOptions &Options) {
+static void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
+ const std::string &InputGCNO,
+ const std::string &InputGCDA, bool DumpGCOV,
+ const GCOVOptions &Options) {
SmallString<128> CoverageFileStem(ObjectDir);
if (CoverageFileStem.empty()) {
// If no directory was specified with -o, look next to the source file.
diff --git a/tools/llvm-cov/llvm-cov.cpp b/tools/llvm-cov/llvm-cov.cpp
index 86ec26d..bf66f58 100644
--- a/tools/llvm-cov/llvm-cov.cpp
+++ b/tools/llvm-cov/llvm-cov.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
@@ -32,9 +33,13 @@ int convertForTestingMain(int argc, const char *argv[]);
int gcovMain(int argc, const char *argv[]);
/// \brief Top level help.
-int helpMain(int argc, const char *argv[]) {
- errs() << "OVERVIEW: LLVM code coverage tool\n\n"
- << "USAGE: llvm-cov {gcov|report|show}\n";
+static int helpMain(int argc, const char *argv[]) {
+ errs() << "Usage: llvm-cov {gcov|report|show} [OPTION]...\n\n"
+ << "Shows code coverage information.\n\n"
+ << "Subcommands:\n"
+ << " gcov: Work with the gcov format.\n"
+ << " show: Annotate source files using instrprof style coverage.\n"
+ << " report: Summarize instrprof style coverage information.\n";
return 0;
}
@@ -61,18 +66,13 @@ int main(int argc, const char **argv) {
}
}
- // Give a warning and fall back to gcov
- errs().changeColor(raw_ostream::RED);
- errs() << "warning:";
- // Assume that argv[1] wasn't a command when it stats with a '-' or is a
- // filename (i.e. contains a '.')
- if (argc > 1 && !StringRef(argv[1]).startswith("-") &&
- StringRef(argv[1]).find(".") == StringRef::npos)
- errs() << " Unrecognized command '" << argv[1] << "'.";
- errs() << " Using the gcov compatible mode "
- "(this behaviour may be dropped in the future).";
- errs().resetColor();
- errs() << "\n";
-
- return gcovMain(argc, argv);
+ if (argc > 1) {
+ if (sys::Process::StandardErrHasColors())
+ errs().changeColor(raw_ostream::RED);
+ errs() << "Unrecognized command: " << argv[1] << ".\n\n";
+ if (sys::Process::StandardErrHasColors())
+ errs().resetColor();
+ }
+ helpMain(argc, argv);
+ return 1;
}