summaryrefslogtreecommitdiff
path: root/tools/sancov/sancov.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/sancov/sancov.cc')
-rw-r--r--tools/sancov/sancov.cc40
1 files changed, 34 insertions, 6 deletions
diff --git a/tools/sancov/sancov.cc b/tools/sancov/sancov.cc
index ff2039de35eb..7f103ebb904b 100644
--- a/tools/sancov/sancov.cc
+++ b/tools/sancov/sancov.cc
@@ -96,7 +96,8 @@ cl::opt<ActionType> Action(
static cl::list<std::string>
ClInputFiles(cl::Positional, cl::OneOrMore,
- cl::desc("(<binary file>|<.sancov file>)..."));
+ cl::desc("<action> <binary files...> <.sancov files...> "
+ "<.symcov files...>"));
static cl::opt<bool> ClDemangle("demangle", cl::init(true),
cl::desc("Print demangled function name."));
@@ -179,7 +180,7 @@ struct CoverageStats {
// --------- ERROR HANDLING ---------
static void fail(const llvm::Twine &E) {
- errs() << "Error: " << E << "\n";
+ errs() << "ERROR: " << E << "\n";
exit(1);
}
@@ -191,7 +192,7 @@ static void failIf(bool B, const llvm::Twine &E) {
static void failIfError(std::error_code Error) {
if (!Error)
return;
- errs() << "Error: " << Error.message() << "(" << Error.value() << ")\n";
+ errs() << "ERROR: " << Error.message() << "(" << Error.value() << ")\n";
exit(1);
}
@@ -201,7 +202,7 @@ template <typename T> static void failIfError(const ErrorOr<T> &E) {
static void failIfError(Error Err) {
if (Err) {
- logAllUnhandledErrors(std::move(Err), errs(), "Error: ");
+ logAllUnhandledErrors(std::move(Err), errs(), "ERROR: ");
exit(1);
}
}
@@ -946,7 +947,15 @@ symbolize(const RawCoverage &Data, const std::string ObjectFile) {
Hasher.update((*BufOrErr)->getBuffer());
Coverage->BinaryHash = toHex(Hasher.final());
+ Blacklists B;
+ auto Symbolizer(createSymbolizer());
+
for (uint64_t Addr : *Data.Addrs) {
+ auto LineInfo = Symbolizer->symbolizeCode(ObjectFile, Addr);
+ failIfError(LineInfo);
+ if (B.isBlacklisted(*LineInfo))
+ continue;
+
Coverage->CoveredIds.insert(utohexstr(Addr, true));
}
@@ -1077,6 +1086,9 @@ static void readAndPrintRawCoverage(const std::vector<std::string> &FileNames,
static std::unique_ptr<SymbolizedCoverage>
merge(const std::vector<std::unique_ptr<SymbolizedCoverage>> &Coverages) {
+ if (Coverages.empty())
+ return nullptr;
+
auto Result = make_unique<SymbolizedCoverage>();
for (size_t I = 0; I < Coverages.size(); ++I) {
@@ -1159,11 +1171,17 @@ readSymbolizeAndMergeCmdArguments(std::vector<std::string> FileNames) {
CoverageByObjFile[Iter->second].push_back(FileName);
};
+ for (const auto &Pair : ObjFiles) {
+ auto FileName = Pair.second;
+ if (CoverageByObjFile.find(FileName) == CoverageByObjFile.end())
+ errs() << "WARNING: No coverage file for " << FileName << "\n";
+ }
+
// Read raw coverage and symbolize it.
for (const auto &Pair : CoverageByObjFile) {
if (findSanitizerCovFunctions(Pair.first).empty()) {
errs()
- << "Ignoring " << Pair.first
+ << "WARNING: Ignoring " << Pair.first
<< " and its coverage because __sanitizer_cov* functions were not "
"found.\n";
continue;
@@ -1192,7 +1210,17 @@ int main(int Argc, char **Argv) {
llvm::InitializeAllTargetMCs();
llvm::InitializeAllDisassemblers();
- cl::ParseCommandLineOptions(Argc, Argv, "Sanitizer Coverage Processing Tool");
+ cl::ParseCommandLineOptions(Argc, Argv,
+ "Sanitizer Coverage Processing Tool (sancov)\n\n"
+ " This tool can extract various coverage-related information from: \n"
+ " coverage-instrumented binary files, raw .sancov files and their "
+ "symbolized .symcov version.\n"
+ " Depending on chosen action the tool expects different input files:\n"
+ " -print-coverage-pcs - coverage-instrumented binary files\n"
+ " -print-coverage - .sancov files\n"
+ " <other actions> - .sancov files & corresponding binary "
+ "files, .symcov files\n"
+ );
// -print doesn't need object files.
if (Action == PrintAction) {