summaryrefslogtreecommitdiff
path: root/lib/fuzzer
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2018-05-11 01:17:52 +0000
committerKostya Serebryany <kcc@google.com>2018-05-11 01:17:52 +0000
commitcb2d71ce010a8171c48fccbf48182ed54d8d75a0 (patch)
treee6e6599f2193c9b0e5190f669a84201caa40de2a /lib/fuzzer
parent782833e7099571a19d78cfb3f82205d8a86bca30 (diff)
[libFuzzer] refactor the implementation of -print_coverage
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer')
-rw-r--r--lib/fuzzer/FuzzerTracePC.cpp84
-rw-r--r--lib/fuzzer/FuzzerTracePC.h3
2 files changed, 43 insertions, 44 deletions
diff --git a/lib/fuzzer/FuzzerTracePC.cpp b/lib/fuzzer/FuzzerTracePC.cpp
index 4b106e572..20230d496 100644
--- a/lib/fuzzer/FuzzerTracePC.cpp
+++ b/lib/fuzzer/FuzzerTracePC.cpp
@@ -211,6 +211,24 @@ static std::string GetModuleName(uintptr_t PC) {
return ModulePathRaw;
}
+template<class CallBack>
+void TracePC::IterateCoveredFunctions(CallBack CB) {
+ for (size_t i = 0; i < NumPCTables; i++) {
+ auto &M = ModulePCTable[i];
+ assert(M.Start < M.Stop);
+ auto ModuleName = GetModuleName(M.Start->PC);
+ for (auto NextFE = M.Start; NextFE < M.Stop; ) {
+ auto FE = NextFE;
+ assert((FE->PCFlags & 1) && "Not a function entry point");
+ do {
+ NextFE++;
+ } while (NextFE < M.Stop && !(NextFE->PCFlags & 1));
+ if (ObservedFuncs.count(FE->PC))
+ CB(FE, NextFE);
+ }
+ }
+}
+
void TracePC::PrintCoverage() {
if (!EF->__sanitizer_symbolize_pc ||
!EF->__sanitizer_get_module_and_offset_for_pc) {
@@ -220,53 +238,31 @@ void TracePC::PrintCoverage() {
return;
}
Printf("COVERAGE:\n");
- std::string LastFunctionName = "";
- std::string LastFileStr = "";
- Set<size_t> UncoveredLines;
- Set<size_t> CoveredLines;
-
- auto FunctionEndCallback = [&](const std::string &CurrentFunc,
- const std::string &CurrentFile) {
- if (LastFunctionName != CurrentFunc) {
- if (CoveredLines.empty() && !UncoveredLines.empty()) {
- Printf("UNCOVERED_FUNC: %s\n", LastFunctionName.c_str());
- } else {
- for (auto Line : UncoveredLines) {
- if (!CoveredLines.count(Line))
- Printf("UNCOVERED_LINE: %s %s:%zd\n", LastFunctionName.c_str(),
- LastFileStr.c_str(), Line);
- }
- }
-
- UncoveredLines.clear();
- CoveredLines.clear();
- LastFunctionName = CurrentFunc;
- LastFileStr = CurrentFile;
+ auto CoveredFunctionCallback = [&](const PCTableEntry *First, const PCTableEntry *Last) {
+ assert(First < Last);
+ auto VisualizePC = GetNextInstructionPc(First->PC);
+ std::string FileStr = DescribePC("%s", VisualizePC);
+ if (!IsInterestingCoverageFile(FileStr)) return;
+ std::string FunctionStr = DescribePC("%F", VisualizePC);
+ std::string LineStr = DescribePC("%l", VisualizePC);
+ size_t Line = std::stoul(LineStr);
+ std::vector<uintptr_t> UncoveredPCs;
+ for (auto TE = First; TE < Last; TE++)
+ if (!ObservedPCs.count(TE->PC))
+ UncoveredPCs.push_back(TE->PC);
+ Printf("COVERED_FUNC: ");
+ UncoveredPCs.empty()
+ ? Printf("all")
+ : Printf("%zd/%zd", (Last - First) - UncoveredPCs.size(), Last - First);
+ Printf(" PCs covered %s %s:%zd\n", FunctionStr.c_str(), FileStr.c_str(),
+ Line);
+ for (auto PC: UncoveredPCs) {
+ Printf(" UNCOVERED_PC: %s\n",
+ DescribePC("%s:%l", GetNextInstructionPc(PC)).c_str());
}
};
- for (size_t i = 0; i < NumPCTables; i++) {
- auto &M = ModulePCTable[i];
- assert(M.Start < M.Stop);
- auto ModuleName = GetModuleName(M.Start->PC);
- for (auto Ptr = M.Start; Ptr < M.Stop; Ptr++) {
- auto PC = Ptr->PC;
- auto VisualizePC = GetNextInstructionPc(PC);
- bool IsObserved = ObservedPCs.count(PC);
- std::string FileStr = DescribePC("%s", VisualizePC);
- if (!IsInterestingCoverageFile(FileStr)) continue;
- std::string FunctionStr = DescribePC("%F", VisualizePC);
- FunctionEndCallback(FunctionStr, FileStr);
- std::string LineStr = DescribePC("%l", VisualizePC);
- size_t Line = std::stoul(LineStr);
- if (IsObserved && CoveredLines.insert(Line).second)
- Printf("COVERED: %s %s:%zd\n", FunctionStr.c_str(), FileStr.c_str(),
- Line);
- else
- UncoveredLines.insert(Line);
- }
- }
- FunctionEndCallback("", "");
+ IterateCoveredFunctions(CoveredFunctionCallback);
}
// Value profile.
diff --git a/lib/fuzzer/FuzzerTracePC.h b/lib/fuzzer/FuzzerTracePC.h
index 27ff47cd7..d68da76b2 100644
--- a/lib/fuzzer/FuzzerTracePC.h
+++ b/lib/fuzzer/FuzzerTracePC.h
@@ -103,6 +103,9 @@ class TracePC {
void PrintCoverage();
+ template<class CallBack>
+ void IterateCoveredFunctions(CallBack CB);
+
void AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2,
size_t n, bool StopAtZero);