Home | History | Annotate | Line # | Download | only in fuzzer
      1  1.1  kamil //===- FuzzerDataFlowTrace.h - Internal header for the Fuzzer ---*- C++ -* ===//
      2  1.1  kamil //
      3  1.1  kamil //                     The LLVM Compiler Infrastructure
      4  1.1  kamil //
      5  1.1  kamil // This file is distributed under the University of Illinois Open Source
      6  1.1  kamil // License. See LICENSE.TXT for details.
      7  1.1  kamil //
      8  1.1  kamil //===----------------------------------------------------------------------===//
      9  1.1  kamil // fuzzer::DataFlowTrace; reads and handles a data-flow trace.
     10  1.1  kamil //
     11  1.1  kamil // A data flow trace is generated by e.g. dataflow/DataFlow.cpp
     12  1.1  kamil // and is stored on disk in a separate directory.
     13  1.1  kamil //
     14  1.1  kamil // The trace dir contains a file 'functions.txt' which lists function names,
     15  1.1  kamil // oner per line, e.g.
     16  1.1  kamil // ==> functions.txt <==
     17  1.1  kamil // Func2
     18  1.1  kamil // LLVMFuzzerTestOneInput
     19  1.1  kamil // Func1
     20  1.1  kamil //
     21  1.1  kamil // All other files in the dir are the traces, see dataflow/DataFlow.cpp.
     22  1.1  kamil // The name of the file is sha1 of the input used to generate the trace.
     23  1.1  kamil //
     24  1.1  kamil // Current status:
     25  1.1  kamil //   the data is parsed and the summary is printed, but the data is not yet
     26  1.1  kamil //   used in any other way.
     27  1.1  kamil //===----------------------------------------------------------------------===//
     28  1.1  kamil 
     29  1.1  kamil #ifndef LLVM_FUZZER_DATA_FLOW_TRACE
     30  1.1  kamil #define LLVM_FUZZER_DATA_FLOW_TRACE
     31  1.1  kamil 
     32  1.1  kamil #include "FuzzerDefs.h"
     33  1.1  kamil 
     34  1.1  kamil #include <unordered_map>
     35  1.1  kamil #include <vector>
     36  1.1  kamil #include <string>
     37  1.1  kamil 
     38  1.1  kamil namespace fuzzer {
     39  1.1  kamil class DataFlowTrace {
     40  1.1  kamil  public:
     41  1.1  kamil   void Init(const std::string &DirPath, const std::string &FocusFunction);
     42  1.1  kamil   void Clear() { Traces.clear(); }
     43  1.1  kamil   const Vector<uint8_t> *Get(const std::string &InputSha1) const {
     44  1.1  kamil     auto It = Traces.find(InputSha1);
     45  1.1  kamil     if (It != Traces.end())
     46  1.1  kamil       return &It->second;
     47  1.1  kamil     return nullptr;
     48  1.1  kamil   }
     49  1.1  kamil 
     50  1.1  kamil  private:
     51  1.1  kamil   // Input's sha1 => DFT for the FocusFunction.
     52  1.1  kamil   std::unordered_map<std::string, Vector<uint8_t> > Traces;
     53  1.1  kamil };
     54  1.1  kamil }  // namespace fuzzer
     55  1.1  kamil 
     56  1.1  kamil #endif // LLVM_FUZZER_DATA_FLOW_TRACE
     57