Skip to content

Commit 4fdda4f

Browse files
committed
[lldb][fuzz] Allow expression fuzzer to be passed as a flag.
The expression fuzzer checks an environment variable, `LLDB_FUZZER_TARGET`, to get the fuzzer target binary. This is fine, but internally our tooling for running fuzz tests only has proper handling for flag values. It's surprisingly complicated to add support for that, and allowing it to be passed via flag seems reasonable anyway. Reviewed By: cassanova Differential Revision: https://reviews.llvm.org/D133546
1 parent 09d73fe commit 4fdda4f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using namespace lldb;
3535
using namespace llvm;
3636
using namespace clang_fuzzer;
3737

38-
char *target_path;
38+
const char *target_path = nullptr;
3939

4040
void ReportError(llvm::StringRef message) {
4141
WithColor::error() << message << '\n';
@@ -47,10 +47,24 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
4747
signal(SIGPIPE, SIG_IGN);
4848
#endif
4949

50-
target_path = ::getenv("LLDB_FUZZER_TARGET");
50+
// `target_path` can be set by either the "--lldb_fuzzer_target" commandline
51+
// flag or the "LLDB_FUZZER_TARGET" environment variable. Arbitrarily, we
52+
// always do flag parsing and only check the environment variable if the
53+
// commandline flag is not set.
54+
for (int i = 1; i < *argc; ++i) {
55+
auto this_arg = llvm::StringRef((*argv)[i]);
56+
WithColor::note() << "argv[" << i << "] = " << this_arg << "\n";
57+
if (this_arg.consume_front("--lldb_fuzzer_target="))
58+
target_path = this_arg.data();
59+
}
60+
61+
if (!target_path)
62+
target_path = ::getenv("LLDB_FUZZER_TARGET");
63+
5164
if (!target_path)
52-
ReportError(
53-
"no target path specified in with the LLDB_FUZZER_TARGET variable");
65+
ReportError("No target path specified. Set one either as an environment "
66+
"variable (i.e. LLDB_FUZZER_TARGET=target_path) or pass as a "
67+
"command line flag (i.e. --lldb_fuzzer_target=target_path).");
5468

5569
if (!sys::fs::exists(target_path))
5670
ReportError(formatv("target path '{0}' does not exist", target_path).str());

0 commit comments

Comments
 (0)