[Lldb-commits] [PATCH] D84955: Report an error if a CLI option lacks an argument

Luboš Luňák via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 31 13:03:17 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG77d5a63c191c: [lldb] report an error if a CLI option lacks an argument (authored by llunak).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84955/new/

https://reviews.llvm.org/D84955

Files:
  lldb/test/Shell/Driver/TestError.test
  lldb/tools/driver/Driver.cpp


Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -853,10 +853,11 @@
 
   // Parse arguments.
   LLDBOptTable T;
-  unsigned MAI;
-  unsigned MAC;
+  unsigned MissingArgIndex;
+  unsigned MissingArgCount;
   ArrayRef<const char *> arg_arr = makeArrayRef(argv + 1, argc - 1);
-  opt::InputArgList input_args = T.ParseArgs(arg_arr, MAI, MAC);
+  opt::InputArgList input_args =
+      T.ParseArgs(arg_arr, MissingArgIndex, MissingArgCount);
   llvm::StringRef argv0 = llvm::sys::path::filename(argv[0]);
 
   if (input_args.hasArg(OPT_help)) {
@@ -864,11 +865,19 @@
     return 0;
   }
 
+  // Check for missing argument error.
+  if (MissingArgCount) {
+    WithColor::error() << "argument to '"
+                       << input_args.getArgString(MissingArgIndex)
+                       << "' is missing\n";
+  }
   // Error out on unknown options.
   if (input_args.hasArg(OPT_UNKNOWN)) {
     for (auto *arg : input_args.filtered(OPT_UNKNOWN)) {
       WithColor::error() << "unknown option: " << arg->getSpelling() << '\n';
     }
+  }
+  if (MissingArgCount || input_args.hasArg(OPT_UNKNOWN)) {
     llvm::errs() << "Use '" << argv0
                  << " --help' for a complete list of options.\n";
     return 1;
Index: lldb/test/Shell/Driver/TestError.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Driver/TestError.test
@@ -0,0 +1,2 @@
+RUN: not %lldb --arch 2>&1 | FileCheck %s
+CHECK: error: argument to '--arch' is missing


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84955.282301.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200731/a87a462b/attachment.bin>


More information about the lldb-commits mailing list