[llvm] r285145 - [libFuzzer] simplify the code to print new PCs
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 17:20:51 PDT 2016
Author: kcc
Date: Tue Oct 25 19:20:51 2016
New Revision: 285145
URL: http://llvm.org/viewvc/llvm-project?rev=285145&view=rev
Log:
[libFuzzer] simplify the code to print new PCs
Modified:
llvm/trunk/lib/Fuzzer/FuzzerInternal.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=285145&r1=285144&r2=285145&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Tue Oct 25 19:20:51 2016
@@ -110,8 +110,6 @@ private:
void InterruptCallback();
void MutateAndTestOne();
void ReportNewCoverage(InputInfo *II, const Unit &U);
- void PrintNewPCs();
- void PrintOneNewPC(uintptr_t PC);
size_t RunOne(const Unit &U) { return RunOne(U.data(), U.size()); }
void WriteToOutputCorpus(const Unit &U);
void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=285145&r1=285144&r2=285145&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Tue Oct 25 19:20:51 2016
@@ -168,6 +168,7 @@ Fuzzer::Fuzzer(UserCallback CB, InputCor
EF->__sanitizer_install_malloc_and_free_hooks(MallocHook, FreeHook);
TPC.SetUseCounters(Options.UseCounters);
TPC.SetUseValueProfile(Options.UseValueProfile);
+ TPC.SetPrintNewPCs(Options.PrintNewCovPcs);
if (Options.Verbosity)
TPC.PrintModuleInfo();
@@ -556,26 +557,13 @@ void Fuzzer::PrintStatusForNewUnit(const
}
}
-void Fuzzer::PrintOneNewPC(uintptr_t PC) {
- PrintPC("\tNEW_PC: %p %F %L\n",
- "\tNEW_PC: %p\n", PC);
-}
-
-void Fuzzer::PrintNewPCs() {
- if (!Options.PrintNewCovPcs) return;
- uintptr_t *PCIDs;
- if (size_t NumNewPCIDs = TPC.GetNewPCIDs(&PCIDs))
- for (size_t i = 0; i < NumNewPCIDs; i++)
- PrintOneNewPC(TPC.GetPCbyPCID(PCIDs[i]));
-}
-
void Fuzzer::ReportNewCoverage(InputInfo *II, const Unit &U) {
II->NumSuccessfullMutations++;
MD.RecordSuccessfulMutationSequence();
PrintStatusForNewUnit(U);
WriteToOutputCorpus(U);
NumberOfNewUnitsAdded++;
- PrintNewPCs();
+ TPC.PrintNewPCs();
}
// Finds minimal number of units in 'Extra' that add coverage to 'Initial'.
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=285145&r1=285144&r2=285145&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Tue Oct 25 19:20:51 2016
@@ -136,6 +136,16 @@ static bool IsInterestingCoverageFile(st
return true;
}
+void TracePC::PrintNewPCs() {
+ if (DoPrintNewPCs) {
+ if (!PrintedPCs)
+ PrintedPCs = new std::set<uintptr_t>;
+ for (size_t i = 0; i < Min(NumGuards + 1, kNumPCs); i++)
+ if (PCs[i] && PrintedPCs->insert(PCs[i]).second)
+ PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PCs[i]);
+ }
+}
+
void TracePC::PrintCoverage() {
if (!EF->__sanitizer_symbolize_pc) {
Printf("INFO: __sanitizer_symbolize_pc is not available,"
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=285145&r1=285144&r2=285145&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Tue Oct 25 19:20:51 2016
@@ -12,6 +12,8 @@
#ifndef LLVM_FUZZER_TRACE_PC
#define LLVM_FUZZER_TRACE_PC
+#include <set>
+
#include "FuzzerDefs.h"
#include "FuzzerValueBitMap.h"
@@ -53,6 +55,7 @@ class TracePC {
size_t GetTotalPCCoverage();
void SetUseCounters(bool UC) { UseCounters = UC; }
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
+ void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
size_t FinalizeTrace(InputCorpus *C, size_t InputSize, bool Shrink);
bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap) {
return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
@@ -91,9 +94,12 @@ class TracePC {
TableOfRecentCompares<uint32_t, kTORCSize> TORC4;
TableOfRecentCompares<uint64_t, kTORCSize> TORC8;
+ void PrintNewPCs();
+
private:
bool UseCounters = false;
bool UseValueProfile = false;
+ bool DoPrintNewPCs = false;
static const size_t kMaxNewPCIDs = 1024;
uintptr_t NewPCIDs[kMaxNewPCIDs];
@@ -129,6 +135,8 @@ private:
static const size_t kNumPCs = 1 << 24;
uintptr_t PCs[kNumPCs];
+ std::set<uintptr_t> *PrintedPCs;
+
ValueBitMap ValueProfileMap;
};
More information about the llvm-commits
mailing list