diff options
| author | Kostya Serebryany <kcc@google.com> | 2016-09-23 23:51:58 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2016-09-23 23:51:58 +0000 |
| commit | 0800b81a21c5e3967294851db9278fbd5a9dd340 (patch) | |
| tree | 7ec4ed29d3dbb16e97ad4c24764814da5b9aa6e9 /llvm/lib/Fuzzer/FuzzerTracePC.cpp | |
| parent | 5ab97ec2f6a67b42e7ab7c9f1164edbbb4831404 (diff) | |
| download | bcm5719-llvm-0800b81a21c5e3967294851db9278fbd5a9dd340.tar.gz bcm5719-llvm-0800b81a21c5e3967294851db9278fbd5a9dd340.zip | |
[libFuzzer] simplify HandleTrace again, start re-running interesting units and collecting their features.
llvm-svn: 282316
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerTracePC.cpp')
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerTracePC.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp index 0df8aba18f6..393470770c9 100644 --- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp +++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp @@ -23,18 +23,24 @@ TracePC TPC; void TracePC::HandleTrace(uintptr_t *Guard, uintptr_t PC) { uintptr_t Idx = *Guard; if (!Idx) return; - uint8_t Counter = Counters[Idx % kNumCounters]; + uint8_t *CounterPtr = &Counters[Idx % kNumCounters]; + uint8_t Counter = *CounterPtr; if (Counter == 0) { - AddNewPCID(Idx); if (!PCs[Idx]) { + AddNewPCID(Idx); TotalPCCoverage++; PCs[Idx] = PC; } } - if (Counter < 128) - Counters[Idx % kNumCounters] = Counter + 1; - if (Counter >= 128 || !UseCounters) + if (UseCounters) { + if (Counter < 128) + *CounterPtr = Counter + 1; + else + *Guard = 0; + } else { + *CounterPtr = 1; *Guard = 0; + } } void TracePC::HandleInit(uintptr_t *Start, uintptr_t *Stop) { @@ -96,6 +102,31 @@ void TracePC::PrintCoverage() { } } + +void TracePC::UpdateFeatureSet(size_t CurrentElementIdx, size_t CurrentElementSize) { + if (!CurrentElementSize) return; + for (size_t Idx = 0; Idx < kFeatureSetSize; Idx++) { + if (!CounterMap.Get(Idx)) continue; + Feature &Fe = FeatureSet[Idx]; + Fe.Count++; + if (!Fe.SmallestElementSize || Fe.SmallestElementSize > CurrentElementSize) { + Fe.SmallestElementIdx = CurrentElementIdx; + Fe.SmallestElementSize = CurrentElementSize; + } + } +} + +void TracePC::PrintFeatureSet() { + Printf("[id: cnt idx sz] "); + for (size_t i = 0; i < kFeatureSetSize; i++) { + auto &Fe = FeatureSet[i]; + if (!Fe.Count) continue; + Printf("[%zd: %zd %zd %zd] ", i, Fe.Count, Fe.SmallestElementIdx, + Fe.SmallestElementSize); + } + Printf("\n"); +} + } // namespace fuzzer extern "C" { |

