summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/fuzzer
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-08-28 22:52:22 +0000
committerKostya Serebryany <kcc@google.com>2017-08-28 22:52:22 +0000
commitc07008653c109345b1446f27f2ccc72dbfe5da41 (patch)
tree81266cbf90c7fea5aab081c4a1bd6a116e8950fb /compiler-rt/lib/fuzzer
parent4976d6a0c6d114adb4feb19195af42d0d835870f (diff)
downloadbcm5719-llvm-c07008653c109345b1446f27f2ccc72dbfe5da41.tar.gz
bcm5719-llvm-c07008653c109345b1446f27f2ccc72dbfe5da41.zip
[libFuzzer] allow -print_funcs=N: N is the max number of new covered function printed
llvm-svn: 311945
Diffstat (limited to 'compiler-rt/lib/fuzzer')
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerFlags.def3
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerOptions.h2
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerTracePC.cpp10
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerTracePC.h4
4 files changed, 13 insertions, 6 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerFlags.def b/compiler-rt/lib/fuzzer/FuzzerFlags.def
index df52377bf98..790b5783d37 100644
--- a/compiler-rt/lib/fuzzer/FuzzerFlags.def
+++ b/compiler-rt/lib/fuzzer/FuzzerFlags.def
@@ -91,7 +91,8 @@ FUZZER_FLAG_STRING(exact_artifact_path,
"and will not use checksum in the file name. Do not "
"use the same path for several parallel processes.")
FUZZER_FLAG_INT(print_pcs, 0, "If 1, print out newly covered PCs.")
-FUZZER_FLAG_INT(print_funcs, 1, "If 1, print out newly covered functions.")
+FUZZER_FLAG_INT(print_funcs, 2, "If >=1, print out at most this number of "
+ "newly covered functions.")
FUZZER_FLAG_INT(print_final_stats, 0, "If 1, print statistics at exit.")
FUZZER_FLAG_INT(print_corpus_stats, 0,
"If 1, print statistics on corpus elements at exit.")
diff --git a/compiler-rt/lib/fuzzer/FuzzerOptions.h b/compiler-rt/lib/fuzzer/FuzzerOptions.h
index d387242097d..bfac3b685e3 100644
--- a/compiler-rt/lib/fuzzer/FuzzerOptions.h
+++ b/compiler-rt/lib/fuzzer/FuzzerOptions.h
@@ -47,7 +47,7 @@ struct FuzzingOptions {
bool SaveArtifacts = true;
bool PrintNEW = true; // Print a status line when new units are found;
bool PrintNewCovPcs = false;
- bool PrintNewCovFuncs = false;
+ int PrintNewCovFuncs = 0;
bool PrintFinalStats = false;
bool PrintCorpusStats = false;
bool PrintCoverage = false;
diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
index 831316aa3f4..78f0d41715b 100644
--- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
@@ -143,6 +143,7 @@ void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) {
}
void TracePC::UpdateObservedPCs() {
+ Vector<uintptr_t> CoveredFuncs;
auto ObservePC = [&](uintptr_t PC) {
if (ObservedPCs.insert(PC).second && DoPrintNewPCs)
PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PC + 1);
@@ -150,8 +151,8 @@ void TracePC::UpdateObservedPCs() {
auto Observe = [&](const PCTableEntry &TE) {
if (TE.PCFlags & 1)
- if (ObservedFuncs.insert(TE.PC).second && DoPrintNewFuncs)
- PrintPC("\tNEW_FUNC: %p %F %L\n", "\tNEW_PC: %p\n", TE.PC + 1);
+ if (ObservedFuncs.insert(TE.PC).second && NumPrintNewFuncs)
+ CoveredFuncs.push_back(TE.PC);
ObservePC(TE.PC);
};
@@ -186,6 +187,11 @@ void TracePC::UpdateObservedPCs() {
if (P[Idx])
ObservePC((uintptr_t)Idx);
}
+
+ for (size_t i = 0, N = Min(CoveredFuncs.size(), NumPrintNewFuncs); i < N; i++) {
+ Printf("\tNEW_FUNC[%zd/%zd]: ", i, CoveredFuncs.size());
+ PrintPC("%p %F %L\n", "%p\n", CoveredFuncs[i] + 1);
+ }
}
inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(uintptr_t PC) {
diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.h b/compiler-rt/lib/fuzzer/FuzzerTracePC.h
index 9c23ef6b543..54172608d18 100644
--- a/compiler-rt/lib/fuzzer/FuzzerTracePC.h
+++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.h
@@ -82,7 +82,7 @@ class TracePC {
void SetUseCounters(bool UC) { UseCounters = UC; }
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
- void SetPrintNewFuncs(bool P) { DoPrintNewFuncs = P; }
+ void SetPrintNewFuncs(size_t P) { NumPrintNewFuncs = P; }
void UpdateObservedPCs();
template <class Callback> void CollectFeatures(Callback CB) const;
@@ -134,7 +134,7 @@ private:
bool UseCounters = false;
bool UseValueProfile = false;
bool DoPrintNewPCs = false;
- bool DoPrintNewFuncs = false;
+ size_t NumPrintNewFuncs = 0;
struct Module {
uint32_t *Start, *Stop;
OpenPOWER on IntegriCloud