From f454301b56e9dda8caecad727ba80797387abd3d Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Wed, 29 Mar 2017 04:55:45 +0000 Subject: [XRay][tools] Handle "no subcommand" case for llvm-xray Summary: Currently the llvm-xray commandline tool fails to handle the case for when no subcommand is provided in a graceful manner. This fixes that to print the help message explaining the subcommands and the available options. Reviewers: pcc, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31409 llvm-svn: 298975 --- llvm/tools/llvm-xray/llvm-xray.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'llvm/tools/llvm-xray') diff --git a/llvm/tools/llvm-xray/llvm-xray.cc b/llvm/tools/llvm-xray/llvm-xray.cc index ac5faaa408b..98303e7be15 100644 --- a/llvm/tools/llvm-xray/llvm-xray.cc +++ b/llvm/tools/llvm-xray/llvm-xray.cc @@ -30,12 +30,20 @@ int main(int argc, char *argv[]) { " This program consolidates multiple XRay trace " "processing tools for convenient access.\n"); for (auto *SC : cl::getRegisteredSubcommands()) { - if (*SC) + if (*SC) { + // If no subcommand was provided, we need to explicitly check if this is + // the top-level subcommand. + if (SC == &*cl::TopLevelSubCommand) { + cl::PrintHelpMessage(false, true); + return 0; + } if (auto C = dispatch(SC)) { ExitOnError("llvm-xray: ")(C()); return 0; } + } } + // If all else fails, we still print the usage message. cl::PrintHelpMessage(false, true); } -- cgit v1.2.3