Skip to content

Commit 6134ff1

Browse files
committed
implement coverage dump
1 parent 0b41d4d commit 6134ff1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

fuzzer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ void Fuzzer::ParseOptions(int argc, char **argv) {
120120
incremental_coverage = GetBinaryOption("-incremental_coverage", argc, argv, true);
121121

122122
add_all_inputs = GetBinaryOption("-add_all_inputs", argc, argv, false);
123+
124+
dump_coverage = GetBinaryOption("-dump_coverage", argc, argv, false);
123125
}
124126

125127
void Fuzzer::SetupDirectories() {
@@ -807,6 +809,11 @@ void Fuzzer::RunFuzzerThread(ThreadContext *tc) {
807809
}
808810
}
809811

812+
void Fuzzer::DumpCoverage() {
813+
std::string out_file = DirJoin(out_dir, "coverage.txt");
814+
WriteCoverage(fuzzer_coverage, out_file.c_str());
815+
}
816+
810817
void Fuzzer::SaveState(ThreadContext *tc) {
811818
// don't save during input sample processing
812819
if(state == INPUT_SAMPLE_PROCESSING) return;
@@ -843,6 +850,8 @@ void Fuzzer::SaveState(ThreadContext *tc) {
843850
fwrite(&sentry, sizeof(sentry), 1, fp);
844851

845852
fclose(fp);
853+
854+
if(dump_coverage) DumpCoverage();
846855

847856
coverage_mutex.Unlock();
848857
output_mutex.Unlock();

fuzzer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class Fuzzer {
199199

200200
void SaveState(ThreadContext *tc);
201201
void RestoreState(ThreadContext *tc);
202+
void DumpCoverage();
202203

203204
std::string in_dir;
204205
std::string out_dir;
@@ -252,6 +253,8 @@ class Fuzzer {
252253

253254
bool add_all_inputs;
254255

256+
bool dump_coverage;
257+
255258
Mutex crash_mutex;
256259
std::unordered_map<std::string, int> unique_crashes;
257260

0 commit comments

Comments
 (0)