[libFuzzer] small refactoring in the driver; dummy implementation of collect_data_flow; attempt to fix the windows bot

llvm-svn: 360399
GitOrigin-RevId: da96d92175f716ba2dd219f937bb26bdea126cbc
diff --git a/FuzzerDataFlowTrace.cpp b/FuzzerDataFlowTrace.cpp
index 50ffa98..466312f 100644
--- a/FuzzerDataFlowTrace.cpp
+++ b/FuzzerDataFlowTrace.cpp
@@ -14,6 +14,7 @@
 
 #include <cstdlib>
 #include <fstream>
+#include <numeric>
 #include <sstream>
 #include <string>
 #include <vector>
@@ -195,5 +196,13 @@
          NumTraceFiles, NumFunctions, NumTracesWithFocusFunction);
 }
 
+int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath,
+                    const Vector<std::string> &CorpusDirs,
+                    const Vector<std::string> &ExtraSeeds) {
+  Printf("INFO: collecting data flow. DFTBinary: %s DirPath: %s\n",
+         DFTBinary.c_str(), DirPath.c_str());
+  return 0;
+}
+
 }  // namespace fuzzer
 
diff --git a/FuzzerDataFlowTrace.h b/FuzzerDataFlowTrace.h
index 4058451..a45cb58 100644
--- a/FuzzerDataFlowTrace.h
+++ b/FuzzerDataFlowTrace.h
@@ -36,6 +36,10 @@
 
 namespace fuzzer {
 
+int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath,
+                    const Vector<std::string> &CorpusDirs,
+                    const Vector<std::string> &ExtraSeeds);
+
 class BlockCoverage {
  public:
   bool AppendCoverage(std::istream &IN);
diff --git a/FuzzerDriver.cpp b/FuzzerDriver.cpp
index b9c8927..7a963ad 100644
--- a/FuzzerDriver.cpp
+++ b/FuzzerDriver.cpp
@@ -561,6 +561,29 @@
   return 0;
 }
 
+Vector<std::string> ParseSeedInuts(const char *seed_inputs) {
+  // Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file
+  Vector<std::string> Files;
+  if (!seed_inputs) return Files;
+  std::string SeedInputs;
+  if (Flags.seed_inputs[0] == '@')
+    SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list.
+  else
+    SeedInputs = Flags.seed_inputs; // seed_inputs contains the list.
+  if (SeedInputs.empty()) {
+    Printf("seed_inputs is empty or @file does not exist.\n");
+    exit(1);
+  }
+  // Parse SeedInputs.
+  size_t comma_pos = 0;
+  while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) {
+    Files.push_back(SeedInputs.substr(comma_pos + 1));
+    SeedInputs = SeedInputs.substr(0, comma_pos);
+  }
+  Files.push_back(SeedInputs);
+  return Files;
+}
+
 int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
   using namespace fuzzer;
   assert(argc && argv && "Argument pointers cannot be nullptr");
@@ -663,6 +686,8 @@
     Options.FeaturesDir = Flags.features_dir;
   Options.LazyCounters = Flags.lazy_counters;
 
+  auto ExtraSeedFiles = ParseSeedInuts(Flags.seed_inputs);
+
   unsigned Seed = Flags.seed;
   // Initialize Seed.
   if (Seed == 0)
@@ -671,6 +696,10 @@
   if (Flags.verbosity)
     Printf("INFO: Seed: %u\n", Seed);
 
+  if (Flags.collect_data_flow)
+    return CollectDataFlow(Flags.collect_data_flow, Flags.data_flow_trace,
+                           *Inputs, ExtraSeedFiles);
+
   Random Rand(Seed);
   auto *MD = new MutationDispatcher(Rand, Options);
   auto *Corpus = new InputCorpus(Options.OutputCorpus);
@@ -763,27 +792,6 @@
     exit(0);
   }
 
-  // Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file
-  Vector<std::string> ExtraSeedFiles;
-  if (Flags.seed_inputs) {
-    std::string SeedInputs;
-    if (Flags.seed_inputs[0] == '@')
-      SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list.
-    else
-      SeedInputs = Flags.seed_inputs; // seed_inputs contains the list.
-    if (SeedInputs.empty()) {
-      Printf("seed_inputs is empty or @file does not exist.\n");
-      exit(1);
-    }
-    // Parse SeedInputs.
-    size_t comma_pos = 0;
-    while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) {
-      ExtraSeedFiles.push_back(SeedInputs.substr(comma_pos + 1));
-      SeedInputs = SeedInputs.substr(0, comma_pos);
-    }
-    ExtraSeedFiles.push_back(SeedInputs);
-  }
-
   F->Loop(*Inputs, ExtraSeedFiles);
 
   if (Flags.verbosity)
diff --git a/FuzzerFlags.def b/FuzzerFlags.def
index 81d3f07..71f4990 100644
--- a/FuzzerFlags.def
+++ b/FuzzerFlags.def
@@ -158,3 +158,5 @@
 FUZZER_FLAG_INT(analyze_dict, 0, "Experimental")
 FUZZER_DEPRECATED_FLAG(use_clang_coverage)
 FUZZER_FLAG_STRING(data_flow_trace, "Experimental: use the data flow trace")
+FUZZER_FLAG_STRING(collect_data_flow,
+                   "Experimental: collect the data flow trace")