[llvm] r282222 - [libFuzzer] simplify the TracePC logic
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 18:20:08 PDT 2016
Author: kcc
Date: Thu Sep 22 20:20:07 2016
New Revision: 282222
URL: http://llvm.org/viewvc/llvm-project?rev=282222&view=rev
Log:
[libFuzzer] simplify the TracePC logic
Modified:
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=282222&r1=282221&r2=282222&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Thu Sep 22 20:20:07 2016
@@ -85,8 +85,7 @@ bool Fuzzer::RecordMaxCoverage(Fuzzer::C
TPC.FinalizeTrace();
- uint64_t NewBlockCoverage =
- EF->__sanitizer_get_total_unique_coverage() + TPC.GetTotalCoverage();
+ uint64_t NewBlockCoverage = EF->__sanitizer_get_total_unique_coverage();
if (NewBlockCoverage > C->BlockCoverage) {
Res = true;
C->BlockCoverage = NewBlockCoverage;
@@ -163,6 +162,7 @@ Fuzzer::Fuzzer(UserCallback CB, InputCor
InitializeTraceState();
assert(!F);
F = this;
+ TPC.ResetTotalPCCoverage();
ResetCoverage();
IsMyThread = true;
if (Options.DetectLeaks && EF->__sanitizer_install_malloc_and_free_hooks)
@@ -327,6 +327,8 @@ void Fuzzer::PrintStats(const char *Wher
Printf("#%zd\t%s", TotalNumberOfRuns, Where);
if (MaxCoverage.BlockCoverage)
Printf(" cov: %zd", MaxCoverage.BlockCoverage);
+ if (size_t N = TPC.GetTotalPCCoverage())
+ Printf(" cov: %zd", N);
if (MaxCoverage.VPMap.GetNumBitsSinceLastMerge())
Printf(" vp: %zd", MaxCoverage.VPMap.GetNumBitsSinceLastMerge());
if (auto TB = MaxCoverage.CounterBitmapBits)
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=282222&r1=282221&r2=282222&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Thu Sep 22 20:20:07 2016
@@ -19,31 +19,22 @@
namespace fuzzer {
TracePC TPC;
-const size_t TracePC::kNumCounters;
-const size_t TracePC::kNumPCs;
void TracePC::HandleTrace(uintptr_t *Guard, uintptr_t PC) {
uintptr_t Idx = *Guard;
if (!Idx) return;
- if (UseCounters) {
- uint8_t Counter = Counters[Idx % kNumCounters];
- if (Counter == 0) {
+ uint8_t Counter = Counters[Idx % kNumCounters];
+ if (Counter == 0) {
+ AddNewPCID(Idx);
+ if (!PCs[Idx]) {
+ TotalPCCoverage++;
PCs[Idx] = PC;
- if (TotalCoverageMap.AddValue(Idx)) {
- TotalCoverage++;
- AddNewPCID(Idx);
- }
}
- if (Counter < 128)
- Counters[Idx % kNumCounters] = Counter + 1;
- else
- *Guard = 0;
- } else {
- *Guard = 0;
- TotalCoverage++;
- AddNewPCID(Idx);
- PCs[Idx] = PC;
}
+ if (Counter < 128)
+ Counters[Idx % kNumCounters] = Counter + 1;
+ if (Counter >= 128 || !UseCounters)
+ *Guard = 0;
}
void TracePC::HandleInit(uintptr_t *Start, uintptr_t *Stop) {
@@ -72,8 +63,8 @@ void TracePC::ResetGuards() {
}
void TracePC::FinalizeTrace() {
- if (UseCounters && TotalCoverage) {
- for (size_t Idx = 1, N = std::min(kNumCounters, NumGuards); Idx < N;
+ if (TotalPCCoverage) {
+ for (size_t Idx = 1, N = Min(kNumCounters, NumGuards); Idx < N;
Idx++) {
uint8_t Counter = Counters[Idx];
if (!Counter) continue;
@@ -99,7 +90,7 @@ void TracePC::HandleCallerCallee(uintptr
void TracePC::PrintCoverage() {
Printf("COVERAGE:\n");
- for (size_t i = 0; i < std::min(NumGuards, kNumPCs); i++) {
+ for (size_t i = 0; i < Min(NumGuards, kNumPCs); i++) {
if (PCs[i])
PrintPC("COVERED: %p %F %L\n", "COVERED: %p\n", PCs[i]);
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=282222&r1=282221&r2=282222&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Thu Sep 22 20:20:07 2016
@@ -23,11 +23,12 @@ class TracePC {
void HandleInit(uintptr_t *start, uintptr_t *stop);
void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee);
void HandleValueProfile(size_t Value) { ValueProfileMap.AddValue(Value); }
- size_t GetTotalCoverage() { return TotalCoverage; }
+ size_t GetTotalPCCoverage() { return TotalPCCoverage; }
+ void ResetTotalPCCoverage() { TotalPCCoverage = 0; }
void SetUseCounters(bool UC) { UseCounters = UC; }
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
bool UpdateCounterMap(ValueBitMap *MaxCounterMap) {
- return UseCounters && MaxCounterMap->MergeFrom(CounterMap);
+ return MaxCounterMap->MergeFrom(CounterMap);
}
bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap) {
return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
@@ -43,10 +44,8 @@ class TracePC {
uintptr_t GetPCbyPCID(uintptr_t PCID) { return PCs[PCID]; }
void Reset() {
- TotalCoverage = 0;
NumNewPCIDs = 0;
CounterMap.Reset();
- TotalCoverageMap.Reset();
ResetGuards();
}
@@ -57,7 +56,7 @@ class TracePC {
private:
bool UseCounters = false;
bool UseValueProfile = false;
- size_t TotalCoverage = 0;
+ size_t TotalPCCoverage = 0;
static const size_t kMaxNewPCIDs = 64;
uintptr_t NewPCIDs[kMaxNewPCIDs];
@@ -84,7 +83,6 @@ private:
ValueBitMap CounterMap;
ValueBitMap ValueProfileMap;
- ValueBitMap TotalCoverageMap;
};
extern TracePC TPC;
More information about the llvm-commits
mailing list