diff options
| author | Kostya Serebryany <kcc@google.com> | 2017-08-25 20:09:25 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2017-08-25 20:09:25 +0000 |
| commit | 2eef816e6e5d8a45da77ba8f9df49ed372672585 (patch) | |
| tree | e44522292370bfbba72bebbbf1a74d6e98b3c385 /compiler-rt/lib/fuzzer | |
| parent | 1dbb7578fffa65ab1ee52be04b1ed30f530d8b0a (diff) | |
| download | bcm5719-llvm-2eef816e6e5d8a45da77ba8f9df49ed372672585.tar.gz bcm5719-llvm-2eef816e6e5d8a45da77ba8f9df49ed372672585.zip | |
[libFuzzer] add -print_funcs=1 (on bey default): print newly discovered functions during fuzzing
llvm-svn: 311797
Diffstat (limited to 'compiler-rt/lib/fuzzer')
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDriver.cpp | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerFlags.def | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerLoop.cpp | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerOptions.h | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 19 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.h | 3 |
6 files changed, 20 insertions, 6 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp index 17891d29c5d..d0d0f7dd005 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp @@ -603,6 +603,7 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { Options.SaveArtifacts = !DoPlainRun || Flags.minimize_crash_internal_step; Options.PrintNewCovPcs = Flags.print_pcs; + Options.PrintNewCovFuncs = Flags.print_funcs; Options.PrintFinalStats = Flags.print_final_stats; Options.PrintCorpusStats = Flags.print_corpus_stats; Options.PrintCoverage = Flags.print_coverage; diff --git a/compiler-rt/lib/fuzzer/FuzzerFlags.def b/compiler-rt/lib/fuzzer/FuzzerFlags.def index 2887fd24d48..6968c770a5d 100644 --- a/compiler-rt/lib/fuzzer/FuzzerFlags.def +++ b/compiler-rt/lib/fuzzer/FuzzerFlags.def @@ -91,6 +91,7 @@ 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_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/FuzzerLoop.cpp b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp index 234945932bb..d2d096af45a 100644 --- a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp @@ -626,6 +626,7 @@ void Fuzzer::MutateAndTestOne() { void Fuzzer::Loop() { TPC.SetPrintNewPCs(Options.PrintNewCovPcs); + TPC.SetPrintNewFuncs(Options.PrintNewCovFuncs); system_clock::time_point LastCorpusReload = system_clock::now(); if (Options.DoCrossOver) MD.SetCorpus(&Corpus); diff --git a/compiler-rt/lib/fuzzer/FuzzerOptions.h b/compiler-rt/lib/fuzzer/FuzzerOptions.h index 9500235e2b1..d387242097d 100644 --- a/compiler-rt/lib/fuzzer/FuzzerOptions.h +++ b/compiler-rt/lib/fuzzer/FuzzerOptions.h @@ -47,6 +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; 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 2df850b2cc1..812a6190a0e 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -143,11 +143,18 @@ void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) { } void TracePC::UpdateObservedPCs() { - auto Observe = [&](uintptr_t PC) { - bool Inserted = ObservedPCs.insert(PC).second; - if (Inserted && DoPrintNewPCs) + auto ObservePC = [&](uintptr_t PC) { + if (ObservedPCs.insert(PC).second && DoPrintNewPCs) PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PC + 1); }; + + 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); + ObservePC(TE.PC); + }; + if (NumPCsInPCTables) { if (NumInline8bitCounters == NumPCsInPCTables) { for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++) { @@ -157,7 +164,7 @@ void TracePC::UpdateObservedPCs() { (size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start)); for (size_t j = 0; j < Size; j++) if (Beg[j]) - Observe(ModulePCTable[i].Start[j].PC); + Observe(ModulePCTable[i].Start[j]); } } else if (NumGuards == NumPCsInPCTables) { size_t GuardIdx = 1; @@ -168,7 +175,7 @@ void TracePC::UpdateObservedPCs() { (size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start)); for (size_t j = 0; j < Size; j++, GuardIdx++) if (Counters()[GuardIdx]) - Observe(ModulePCTable[i].Start[j].PC); + Observe(ModulePCTable[i].Start[j]); } } } @@ -177,7 +184,7 @@ void TracePC::UpdateObservedPCs() { auto P = ClangCountersBegin(); for (size_t Idx = 0; Idx < NumClangCounters; Idx++) if (P[Idx]) - Observe((uintptr_t)Idx); + ObservePC((uintptr_t)Idx); } } diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.h b/compiler-rt/lib/fuzzer/FuzzerTracePC.h index 0c9d4b69b61..76aa0748f15 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.h +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.h @@ -82,6 +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 UpdateObservedPCs(); template <class Callback> void CollectFeatures(Callback CB) const; @@ -133,6 +134,7 @@ private: bool UseCounters = false; bool UseValueProfile = false; bool DoPrintNewPCs = false; + bool DoPrintNewFuncs = false; struct Module { uint32_t *Start, *Stop; @@ -158,6 +160,7 @@ private: uintptr_t *PCs() const; std::set<uintptr_t> ObservedPCs; + std::set<uintptr_t> ObservedFuncs; ValueBitMap ValueProfileMap; uintptr_t InitialStack; |

