blob: ad4faeab7b2feaa2826b3e3d0f802b111af527a9 [file] [log] [blame]
kcc86e43882018-06-06 01:23:29 +00001//===- 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
kccadf188b2018-06-07 01:40:20 +000034#include <unordered_map>
35#include <vector>
36#include <string>
37
kcc86e43882018-06-06 01:23:29 +000038namespace fuzzer {
kccadf188b2018-06-07 01:40:20 +000039class DataFlowTrace {
40 public:
kcc86e43882018-06-06 01:23:29 +000041 void Init(const std::string &DirPath, const std::string &FocusFunction);
kccadf188b2018-06-07 01:40:20 +000042 void Clear() { Traces.clear(); }
kcc0cab3f02018-07-19 01:23:32 +000043 const Vector<uint8_t> *Get(const std::string &InputSha1) const {
kccadf188b2018-06-07 01:40:20 +000044 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.
kcc0cab3f02018-07-19 01:23:32 +000052 std::unordered_map<std::string, Vector<uint8_t> > Traces;
kcc86e43882018-06-06 01:23:29 +000053};
54} // namespace fuzzer
55
56#endif // LLVM_FUZZER_DATA_FLOW_TRACE