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