annotate include/llvm/FuzzMutate/FuzzerCLI.h @ 125:56c5119fbcd2

fix
author mir3636
date Sun, 03 Dec 2017 20:09:16 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- FuzzerCLI.h - Common logic for CLIs of fuzzers ----------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // Common logic needed to implement LLVM's fuzz targets' CLIs - including LLVM
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 // concepts like cl::opt and libFuzzer concepts like -ignore_remaining_args=1.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #ifndef LLVM_FUZZMUTATE_FUZZER_CLI_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #define LLVM_FUZZMUTATE_FUZZER_CLI_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/ADT/StringRef.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/Support/DataTypes.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 /// Parse cl::opts from a fuzz target commandline.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 /// This handles all arguments after -ignore_remaining_args=1 as cl::opts.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 void parseFuzzerCLOpts(int ArgC, char *ArgV[]);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 /// Handle backend options that are encoded in the executable name.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 /// Parses some common backend options out of a specially crafted executable
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 /// name (argv[0]). For example, a name like llvm-foo-fuzzer--aarch64-gisel
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 /// might set up an AArch64 triple and the Global ISel selector. This should be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 /// called *before* parseFuzzerCLOpts if calling both.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 /// This is meant to be used for environments like OSS-Fuzz that aren't capable
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 /// of passing in command line arguments in the normal way.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 void handleExecNameEncodedBEOpts(StringRef ExecName);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 using FuzzerTestFun = int (*)(const uint8_t *Data, size_t Size);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 using FuzzerInitFun = int (*)(int *argc, char ***argv);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 /// Runs a fuzz target on the inputs specified on the command line.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 /// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 /// in the argument list in a libFuzzer compatible way.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 FuzzerInitFun Init = [](int *, char ***) { return 0; });
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 } // end llvm namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 #endif // LLVM_FUZZMUTATE_FUZZER_CLI_H