[compiler-rt] r311945 - [libFuzzer] allow -print_funcs=N: N is the max number of new covered function printed

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 15:52:22 PDT 2017


Author: kcc
Date: Mon Aug 28 15:52:22 2017
New Revision: 311945

URL: http://llvm.org/viewvc/llvm-project?rev=311945&view=rev
Log:
[libFuzzer] allow -print_funcs=N: N is the max number of new covered function printed

Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def
    compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h
    compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
    compiler-rt/trunk/test/fuzzer/print-func.test

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def?rev=311945&r1=311944&r2=311945&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerFlags.def Mon Aug 28 15:52:22 2017
@@ -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.")

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h?rev=311945&r1=311944&r2=311945&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h Mon Aug 28 15:52:22 2017
@@ -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;

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp?rev=311945&r1=311944&r2=311945&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp Mon Aug 28 15:52:22 2017
@@ -143,6 +143,7 @@ void TracePC::HandleCallerCallee(uintptr
 }
 
 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) {

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h?rev=311945&r1=311944&r2=311945&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h Mon Aug 28 15:52:22 2017
@@ -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;

Modified: compiler-rt/trunk/test/fuzzer/print-func.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/print-func.test?rev=311945&r1=311944&r2=311945&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/print-func.test (original)
+++ compiler-rt/trunk/test/fuzzer/print-func.test Mon Aug 28 15:52:22 2017
@@ -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




More information about the llvm-commits mailing list