diff options
author | Kostya Serebryany <kcc@google.com> | 2017-08-28 22:52:22 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2017-08-28 22:52:22 +0000 |
commit | ebae6acb2bfef45b621788fba5e98a384a2477d6 (patch) | |
tree | 50471d46b24f09105366a5f8bdfabfb402a73d37 /lib/fuzzer | |
parent | 1cca2c591777ea1905f4a38165fafd5d6cd1057c (diff) |
[libFuzzer] allow -print_funcs=N: N is the max number of new covered function printed
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@311945 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer')
-rw-r--r-- | lib/fuzzer/FuzzerFlags.def | 3 | ||||
-rw-r--r-- | lib/fuzzer/FuzzerOptions.h | 2 | ||||
-rw-r--r-- | lib/fuzzer/FuzzerTracePC.cpp | 10 | ||||
-rw-r--r-- | lib/fuzzer/FuzzerTracePC.h | 4 |
4 files changed, 13 insertions, 6 deletions
diff --git a/lib/fuzzer/FuzzerFlags.def b/lib/fuzzer/FuzzerFlags.def index df52377bf..790b5783d 100644 --- a/lib/fuzzer/FuzzerFlags.def +++ b/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/lib/fuzzer/FuzzerOptions.h b/lib/fuzzer/FuzzerOptions.h index d38724209..bfac3b685 100644 --- a/lib/fuzzer/FuzzerOptions.h +++ b/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/lib/fuzzer/FuzzerTracePC.cpp b/lib/fuzzer/FuzzerTracePC.cpp index 831316aa3..78f0d4171 100644 --- a/lib/fuzzer/FuzzerTracePC.cpp +++ b/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/lib/fuzzer/FuzzerTracePC.h b/lib/fuzzer/FuzzerTracePC.h index 9c23ef6b5..54172608d 100644 --- a/lib/fuzzer/FuzzerTracePC.h +++ b/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; |