Skip to content

Commit

Permalink
[lldb/Driver] Print snippet before exiting with unknown argument.
Browse files Browse the repository at this point in the history
Print a little snippet before exiting when passed unrecognized
arguments. The goal is twofold:

 - Point users to lldb --help.
 - Make it clear that we exited the debugger.
  • Loading branch information
JDevlieghere committed May 20, 2020
1 parent 04daba9 commit ce19664
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions lldb/test/Shell/Driver/TestPositionalArgs.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ RUN: not %lldb -x -b -f %t.foo bar -baz --quux 2>&1 | FileCheck %s --check-prefi

UNKNOWN: error: unknown option: -baz
UNKNOWN: error: unknown option: --quux
UNKNOWN: Use 'lldb --help' for a complete list of options.
5 changes: 4 additions & 1 deletion lldb/tools/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,10 @@ int main(int argc, char const *argv[]) {
unsigned MAC;
ArrayRef<const char *> arg_arr = makeArrayRef(argv + 1, argc - 1);
opt::InputArgList input_args = T.ParseArgs(arg_arr, MAI, MAC);
llvm::StringRef argv0 = llvm::sys::path::filename(argv[0]);

if (input_args.hasArg(OPT_help)) {
printHelp(T, llvm::sys::path::filename(argv[0]));
printHelp(T, argv0);
return 0;
}

Expand All @@ -861,6 +862,8 @@ int main(int argc, char const *argv[]) {
for (auto *arg : input_args.filtered(OPT_UNKNOWN)) {
WithColor::error() << "unknown option: " << arg->getSpelling() << '\n';
}
llvm::errs() << "Use '" << argv0
<< " --help' for a complete list of options.\n";
return 1;
}

Expand Down

0 comments on commit ce19664

Please sign in to comment.