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;
InitializeTraceState();
assert(!F);
F = this;
+ TPC.ResetTotalPCCoverage();
ResetCoverage();
IsMyThread = true;
if (Options.DetectLeaks && EF->__sanitizer_install_malloc_and_free_hooks)
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)
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) {
}
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;
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]);
}
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);
uintptr_t GetPCbyPCID(uintptr_t PCID) { return PCs[PCID]; }
void Reset() {
- TotalCoverage = 0;
NumNewPCIDs = 0;
CounterMap.Reset();
- TotalCoverageMap.Reset();
ResetGuards();
}
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];
ValueBitMap CounterMap;
ValueBitMap ValueProfileMap;
- ValueBitMap TotalCoverageMap;
};
extern TracePC TPC;