diff --git a/lldb/test/Shell/Driver/TestError.test b/lldb/test/Shell/Driver/TestError.test new file mode 100644 --- /dev/null +++ b/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 diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -853,10 +853,11 @@ // Parse arguments. LLDBOptTable T; - unsigned MAI; - unsigned MAC; + unsigned MissingArgIndex; + unsigned MissingArgCount; ArrayRef 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;