blob: 9523a01e120ea6604d8432b27c87ee9fb214ce86 [file] [log] [blame]
kcc86e43882018-06-06 01:23:29 +00001//===- FuzzerDataFlowTrace.h - Internal header for the Fuzzer ---*- C++ -* ===//
2//
chandlerc40284492019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
kcc86e43882018-06-06 01:23:29 +00006//
7//===----------------------------------------------------------------------===//
8// fuzzer::DataFlowTrace; reads and handles a data-flow trace.
9//
10// A data flow trace is generated by e.g. dataflow/DataFlow.cpp
11// and is stored on disk in a separate directory.
12//
13// The trace dir contains a file 'functions.txt' which lists function names,
14// oner per line, e.g.
15// ==> functions.txt <==
16// Func2
17// LLVMFuzzerTestOneInput
18// Func1
19//
20// All other files in the dir are the traces, see dataflow/DataFlow.cpp.
21// The name of the file is sha1 of the input used to generate the trace.
22//
23// Current status:
24// the data is parsed and the summary is printed, but the data is not yet
25// used in any other way.
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_FUZZER_DATA_FLOW_TRACE
29#define LLVM_FUZZER_DATA_FLOW_TRACE
30
31#include "FuzzerDefs.h"
32
kccadf188b2018-06-07 01:40:20 +000033#include <unordered_map>
34#include <vector>
35#include <string>
36
kcc86e43882018-06-06 01:23:29 +000037namespace fuzzer {
kccadf188b2018-06-07 01:40:20 +000038class DataFlowTrace {
39 public:
kcc86e43882018-06-06 01:23:29 +000040 void Init(const std::string &DirPath, const std::string &FocusFunction);
kccadf188b2018-06-07 01:40:20 +000041 void Clear() { Traces.clear(); }
kcc0cab3f02018-07-19 01:23:32 +000042 const Vector<uint8_t> *Get(const std::string &InputSha1) const {
kccadf188b2018-06-07 01:40:20 +000043 auto It = Traces.find(InputSha1);
44 if (It != Traces.end())
45 return &It->second;
46 return nullptr;
47 }
48
49 private:
50 // Input's sha1 => DFT for the FocusFunction.
kcc0cab3f02018-07-19 01:23:32 +000051 std::unordered_map<std::string, Vector<uint8_t> > Traces;
kcc86e43882018-06-06 01:23:29 +000052};
53} // namespace fuzzer
54
55#endif // LLVM_FUZZER_DATA_FLOW_TRACE