diff options
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerFlags.def | 3 | ||||
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerOptions.h | 2 | ||||
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 10 | ||||
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.h | 4 | ||||
-rw-r--r-- | compiler-rt/test/fuzzer/print-func.test | 6 |
5 files changed, 16 insertions, 9 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; diff --git a/compiler-rt/test/fuzzer/print-func.test b/compiler-rt/test/fuzzer/print-func.test index 12d52cb0b8b..930e9992a2f 100644 --- a/compiler-rt/test/fuzzer/print-func.test +++ b/compiler-rt/test/fuzzer/print-func.test @@ -1,9 +1,9 @@ RUN: %cpp_compiler %S/PrintFuncTest.cpp -o %t RUN: %t -seed=1 -runs=100000 2>&1 | FileCheck %s RUN: %t -seed=1 -runs=100000 -print_funcs=0 2>&1 | FileCheck %s --check-prefix=NO -CHECK: NEW_FUNC: {{.*}} FunctionA -CHECK: NEW_FUNC: {{.*}} FunctionB -CHECK: NEW_FUNC: {{.*}} FunctionC +CHECK: NEW_FUNC{{.*}} FunctionA +CHECK: NEW_FUNC{{.*}} FunctionB +CHECK: NEW_FUNC{{.*}} FunctionC CHECK: BINGO NO-NOT: NEW_FUNC |