diff options
| author | Kostya Serebryany <kcc@google.com> | 2016-10-26 00:42:52 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2016-10-26 00:42:52 +0000 |
| commit | 06b8757b574774e95a57df4affd965370cdaef54 (patch) | |
| tree | 3abdb17fa1856fea55591a01b72c00bc62a4a855 /llvm/lib/Fuzzer | |
| parent | a5b2e54fcb7d271ba2d92eda1d9c7cb9a4c4d6da (diff) | |
| download | bcm5719-llvm-06b8757b574774e95a57df4affd965370cdaef54.tar.gz bcm5719-llvm-06b8757b574774e95a57df4affd965370cdaef54.zip | |
[libFuzzer] simplify the code in TracePC::HandleTrace a bit more
llvm-svn: 285147
Diffstat (limited to 'llvm/lib/Fuzzer')
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerLoop.cpp | 17 | ||||
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerTracePC.cpp | 14 | ||||
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerTracePC.h | 20 |
3 files changed, 18 insertions, 33 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp index 0c587288876..1e67f93a8b1 100644 --- a/llvm/lib/Fuzzer/FuzzerLoop.cpp +++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp @@ -381,15 +381,14 @@ void Fuzzer::SetMaxMutationLen(size_t MaxMutationLen) { void Fuzzer::CheckExitOnSrcPosOrItem() { if (!Options.ExitOnSrcPos.empty()) { - uintptr_t *PCIDs; - if (size_t NumNewPCIDs = TPC.GetNewPCIDs(&PCIDs)) { - for (size_t i = 0; i < NumNewPCIDs; i++) { - std::string Descr = DescribePC("%L", TPC.GetPCbyPCID(PCIDs[i])); - if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) { - Printf("INFO: found line matching '%s', exiting.\n", - Options.ExitOnSrcPos.c_str()); - _Exit(0); - } + for (size_t i = 1, N = TPC.GetNumPCs(); i < N; i++) { + uintptr_t PC = TPC.GetPC(i); + if (!PC) continue; + std::string Descr = DescribePC("%L", PC); + if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) { + Printf("INFO: found line matching '%s', exiting.\n", + Options.ExitOnSrcPos.c_str()); + _Exit(0); } } } diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp index 9e612470874..dc39eedb2f5 100644 --- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp +++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp @@ -30,14 +30,10 @@ TracePC TPC; void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) { uint32_t Idx = *Guard; if (!Idx) return; + if (!PCs[Idx % kNumPCs]) + PCs[Idx % kNumPCs] = PC; uint8_t *CounterPtr = &Counters[Idx % kNumCounters]; uint8_t Counter = *CounterPtr; - if (Counter == 0) { - if (!PCs[Idx % kNumPCs]) { - AddNewPCID(Idx); - PCs[Idx % kNumPCs] = PC; - } - } if (UseCounters) { if (Counter < 128) *CounterPtr = Counter + 1; @@ -51,7 +47,7 @@ void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) { size_t TracePC::GetTotalPCCoverage() { size_t Res = 0; - for (size_t i = 0; i < Min(NumGuards+1, kNumPCs); i++) + for (size_t i = 1; i < GetNumPCs(); i++) if (PCs[i]) Res++; return Res; @@ -140,7 +136,7 @@ void TracePC::PrintNewPCs() { if (DoPrintNewPCs) { if (!PrintedPCs) PrintedPCs = new std::set<uintptr_t>; - for (size_t i = 0; i < Min(NumGuards + 1, kNumPCs); i++) + 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]); } @@ -156,7 +152,7 @@ void TracePC::PrintCoverage() { std::map<std::string, uintptr_t> ModuleOffsets; std::set<std::string> CoveredFiles, CoveredFunctions, CoveredLines; Printf("COVERAGE:\n"); - for (size_t i = 0; i < Min(NumGuards + 1, kNumPCs); i++) { + for (size_t i = 1; i < GetNumPCs(); i++) { if (!PCs[i]) continue; std::string FileStr = DescribePC("%s", PCs[i]); if (!IsInterestingCoverageFile(FileStr)) continue; diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.h b/llvm/lib/Fuzzer/FuzzerTracePC.h index 06db3d0dd42..f690bb48851 100644 --- a/llvm/lib/Fuzzer/FuzzerTracePC.h +++ b/llvm/lib/Fuzzer/FuzzerTracePC.h @@ -61,15 +61,7 @@ class TracePC { return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap); } - size_t GetNewPCIDs(uintptr_t **NewPCIDsPtr) { - *NewPCIDsPtr = NewPCIDs; - return Min(kMaxNewPCIDs, NumNewPCIDs); - } - - uintptr_t GetPCbyPCID(uintptr_t PCID) { return PCs[PCID]; } - void ResetMaps() { - NumNewPCIDs = 0; ValueProfileMap.Reset(); memset(Counters, 0, sizeof(Counters)); } @@ -95,19 +87,17 @@ class TracePC { TableOfRecentCompares<uint64_t, kTORCSize> TORC8; void PrintNewPCs(); + size_t GetNumPCs() const { return Min(kNumPCs, NumGuards + 1); } + uintptr_t GetPC(size_t Idx) { + assert(Idx < GetNumPCs()); + return PCs[Idx]; + } private: bool UseCounters = false; bool UseValueProfile = false; bool DoPrintNewPCs = false; - static const size_t kMaxNewPCIDs = 1024; - uintptr_t NewPCIDs[kMaxNewPCIDs]; - size_t NumNewPCIDs = 0; - void AddNewPCID(uintptr_t PCID) { - NewPCIDs[(NumNewPCIDs++) % kMaxNewPCIDs] = PCID; - } - struct Module { uint32_t *Start, *Stop; }; |

