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();
PrintPulseAndReportSlowInput(Data, Size);
size_t NumNewFeatures = Corpus.NumFeatureUpdates() - NumUpdatesBefore;
if (NumNewFeatures) {
+ TPC.UpdateObservedPCs();
Corpus.AddToCorpus({Data, Data + Size}, NumNewFeatures, MayDeleteFile,
UniqFeatureSetTmp);
return true;
"NEW ");
WriteToOutputCorpus(U);
NumberOfNewUnitsAdded++;
- TPC.PrintNewPCs();
CheckExitOnSrcPosOrItem(); // Check only after the unit is saved to corpus.
LastCorpusUpdateRun = TotalNumberOfRuns;
LastCorpusUpdateTime = system_clock::now();
}
void Fuzzer::Loop() {
- TPC.InitializePrintNewPCs();
+ TPC.SetPrintNewPCs(Options.PrintNewCovPcs);
system_clock::time_point LastCorpusReload = system_clock::now();
if (Options.DoCrossOver)
MD.SetCorpus(&Corpus);
}
size_t TracePC::GetTotalPCCoverage() {
+ if (ObservedPCs)
+ return ObservedPCs->size();
size_t Res = 0;
for (size_t i = 1, N = GetNumPCs(); i < N; i++)
if (PCs()[i])
ValueProfileMap.AddValueModPrime(Idx);
}
-void TracePC::InitializePrintNewPCs() {
- if (!DoPrintNewPCs) return;
- assert(!PrintedPCs);
- PrintedPCs = new std::set<uintptr_t>;
- for (size_t i = 1; i < GetNumPCs(); i++)
- if (PCs()[i])
- PrintedPCs->insert(PCs()[i]);
-}
-
-void TracePC::PrintNewPCs() {
- if (!DoPrintNewPCs) return;
- assert(PrintedPCs);
- for (size_t i = 1; i < GetNumPCs(); i++)
- if (PCs()[i] && PrintedPCs->insert(PCs()[i]).second)
- PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PCs()[i]);
+void TracePC::UpdateObservedPCs() {
+ if (NumPCsInPCTables) {
+ auto Observe = [&](uintptr_t PC) {
+ bool Inserted = ObservedPCs->insert(PC).second;
+ if (Inserted && DoPrintNewPCs)
+ PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PC + 1);
+ };
+
+ if (!ObservedPCs)
+ ObservedPCs = new std::set<uintptr_t>;
+
+ if (NumInline8bitCounters == NumPCsInPCTables) {
+ for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++) {
+ uint8_t *Beg = ModuleCounters[i].Start;
+ size_t Size = ModuleCounters[i].Stop - Beg;
+ assert(Size ==
+ (size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start));
+ for (size_t j = 0; j < Size; j++)
+ if (Beg[j])
+ Observe(ModulePCTable[i].Start[j]);
+ }
+ } else if (NumGuards == NumPCsInPCTables) {
+ size_t GuardIdx = 1;
+ for (size_t i = 0; i < NumModules; i++) {
+ uint32_t *Beg = Modules[i].Start;
+ size_t Size = Modules[i].Stop - Beg;
+ assert(Size ==
+ (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]);
+ }
+ }
+ }
}
void TracePC::PrintCoverage() {
void SetUseCounters(bool UC) { UseCounters = UC; }
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
+ void UpdateObservedPCs();
template <class Callback> void CollectFeatures(Callback CB) const;
void ResetMaps() {
TableOfRecentCompares<Word, 32> TORCW;
MemMemTable<1024> MMT;
- void PrintNewPCs();
- void InitializePrintNewPCs();
size_t GetNumPCs() const {
return NumGuards == 0 ? (1 << kTracePcBits) : Min(kNumPCs, NumGuards + 1);
}
uint8_t *Counters() const;
uintptr_t *PCs() const;
- std::set<uintptr_t> *PrintedPCs;
+ std::set<uintptr_t> *ObservedPCs;
ValueBitMap ValueProfileMap;
uintptr_t InitialStack, LowestStack; // Assume stack grows down.