@@ -77,7 +77,7 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
77
77
const size_t kInvalidStartMarker = -1 ;
78
78
size_t LastSeenStartMarker = kInvalidStartMarker ;
79
79
Vector<uint32_t > TmpFeatures;
80
- Set<uintptr_t > PCs;
80
+ Set<uint32_t > PCs;
81
81
while (std::getline (IS, Line, ' \n ' )) {
82
82
std::istringstream ISS1 (Line);
83
83
std::string Marker;
@@ -106,10 +106,11 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
106
106
Files[CurrentFileIdx].Features = TmpFeatures;
107
107
}
108
108
} else if (Marker == " COV" ) {
109
+ size_t CurrentFileIdx = N;
109
110
if (ParseCoverage)
110
111
while (ISS1 >> std::hex >> N)
111
112
if (PCs.insert (N).second )
112
- NumCoveredPCs++ ;
113
+ Files[CurrentFileIdx]. Cov . push_back (N) ;
113
114
} else {
114
115
return false ;
115
116
}
@@ -130,9 +131,9 @@ size_t Merger::ApproximateMemoryConsumption() const {
130
131
131
132
// Decides which files need to be merged (add those to NewFiles).
132
133
// Returns the number of new features added.
133
- size_t Merger::Merge (const Set<uint32_t > &InitialFeatures,
134
- Set<uint32_t > *NewFeatures,
135
- Vector<std::string> *NewFiles) {
134
+ void Merger::Merge (const Set<uint32_t > &InitialFeatures,
135
+ Set<uint32_t > *NewFeatures, const Set< uint32_t > &InitialCov ,
136
+ Set< uint32_t > *NewCov, Vector<std::string> *NewFiles) {
136
137
NewFiles->clear ();
137
138
assert (NumFilesInFirstCorpus <= Files.size ());
138
139
Set<uint32_t > AllFeatures = InitialFeatures;
@@ -142,8 +143,6 @@ size_t Merger::Merge(const Set<uint32_t> &InitialFeatures,
142
143
auto &Cur = Files[i].Features ;
143
144
AllFeatures.insert (Cur.begin (), Cur.end ());
144
145
}
145
- size_t InitialNumFeatures = AllFeatures.size ();
146
-
147
146
// Remove all features that we already know from all other inputs.
148
147
for (size_t i = NumFilesInFirstCorpus; i < Files.size (); i++) {
149
148
auto &Cur = Files[i].Features ;
@@ -178,8 +177,10 @@ size_t Merger::Merge(const Set<uint32_t> &InitialFeatures,
178
177
}
179
178
if (FoundNewFeatures)
180
179
NewFiles->push_back (Files[i].Name );
180
+ for (auto Cov : Files[i].Cov )
181
+ if (InitialCov.find (Cov) == InitialCov.end ())
182
+ NewCov->insert (Cov);
181
183
}
182
- return AllFeatures.size () - InitialNumFeatures;
183
184
}
184
185
185
186
Set<uint32_t > Merger::AllFeatures () const {
@@ -241,7 +242,7 @@ void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) {
241
242
for (size_t F : UniqFeatures)
242
243
OF << " " << std::hex << F;
243
244
OF << " \n " ;
244
- OF << " COV " << i;
245
+ OF << " COV " << std::dec << i;
245
246
TPC.ForEachObservedPC ([&](const TracePC::PCTableEntry *TE) {
246
247
if (AllPCs.insert (TE).second )
247
248
OF << " " << TPC.PCTableEntryIdx (TE);
@@ -276,7 +277,10 @@ void CrashResistantMerge(const Vector<std::string> &Args,
276
277
const Vector<SizedFile> &NewCorpus,
277
278
Vector<std::string> *NewFiles,
278
279
const Set<uint32_t > &InitialFeatures,
279
- Set<uint32_t > *NewFeatures, const std::string &CFPath,
280
+ Set<uint32_t > *NewFeatures,
281
+ const Set<uint32_t > &InitialCov,
282
+ Set<uint32_t > *NewCov,
283
+ const std::string &CFPath,
280
284
bool V /* Verbose*/ ) {
281
285
if (NewCorpus.empty () && OldCorpus.empty ()) return ; // Nothing to merge.
282
286
size_t NumAttempts = 0 ;
@@ -346,9 +350,10 @@ void CrashResistantMerge(const Vector<std::string> &Args,
346
350
VPrintf (V,
347
351
" MERGE-OUTER: consumed %zdMb (%zdMb rss) to parse the control file\n " ,
348
352
M.ApproximateMemoryConsumption () >> 20 , GetPeakRSSMb ());
349
- size_t NumNewFeatures = M.Merge (InitialFeatures, NewFeatures, NewFiles);
350
- VPrintf (V, " MERGE-OUTER: %zd new files with %zd new features added\n " ,
351
- NewFiles->size (), NumNewFeatures);
353
+ M.Merge (InitialFeatures, NewFeatures, InitialCov, NewCov, NewFiles);
354
+ VPrintf (V, " MERGE-OUTER: %zd new files with %zd new features added; "
355
+ " %zd new coverage edges\n " ,
356
+ NewFiles->size (), NewFeatures->size (), NewCov->size ());
352
357
}
353
358
354
359
} // namespace fuzzer
0 commit comments