[Lldb-commits] [PATCH] D133546: [lldb][fuzz] Allow expression fuzzer to be passed as a flag.

Jordan Rupprecht via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 8 18:33:14 PDT 2022


rupprecht created this revision.
rupprecht added reviewers: cassanova, JDevlieghere, mib.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133546

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


Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
===================================================================
--- lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
@@ -35,7 +35,7 @@
 using namespace llvm;
 using namespace clang_fuzzer;
 
-char *target_path;
+const char *target_path = nullptr;
 
 void ReportError(llvm::StringRef message) {
   WithColor::error() << message << '\n';
@@ -47,7 +47,20 @@
   signal(SIGPIPE, SIG_IGN);
 #endif
 
-  target_path = ::getenv("LLDB_FUZZER_TARGET");
+  // `target_path` can be set by either the "--lldb_fuzzer_target" commandline
+  // flag or the "LLDB_FUZZER_TARGET" environment variable. Arbitrarily, we
+  // always do flag parsing and only check the environment variable if the
+  // commandline flag is not set.
+  for (int i = 1; i < *argc; ++i) {
+    auto this_arg = llvm::StringRef((*argv)[i]);
+    WithColor::note() << "argv[" << i << "] = " << this_arg << "\n";
+    if (this_arg.consume_front("--lldb_fuzzer_target="))
+      target_path = this_arg.data();
+  }
+
+  if (!target_path)
+    target_path = ::getenv("LLDB_FUZZER_TARGET");
+
   if (!target_path)
     ReportError(
         "no target path specified in with the LLDB_FUZZER_TARGET variable");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133546.458940.patch
Type: text/x-patch
Size: 1347 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220909/434d2b4a/attachment.bin>


More information about the lldb-commits mailing list