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);
}
}
}
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;
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;
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]);
}
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;
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));
}
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;
};