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