[llvm] r298975 - [XRay][tools] Handle "no subcommand" case for llvm-xray
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 28 21:55:46 PDT 2017
Author: dberris
Date: Tue Mar 28 23:55:45 2017
New Revision: 298975
URL: http://llvm.org/viewvc/llvm-project?rev=298975&view=rev
Log:
[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
Added:
llvm/trunk/test/tools/llvm-xray/X86/no-subcommand-noassert.txt
Modified:
llvm/trunk/tools/llvm-xray/llvm-xray.cc
Added: llvm/trunk/test/tools/llvm-xray/X86/no-subcommand-noassert.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-xray/X86/no-subcommand-noassert.txt?rev=298975&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-xray/X86/no-subcommand-noassert.txt (added)
+++ llvm/trunk/test/tools/llvm-xray/X86/no-subcommand-noassert.txt Tue Mar 28 23:55:45 2017
@@ -0,0 +1,3 @@
+; RUN: llvm-xray | FileCheck %s
+
+; CHECK: OVERVIEW: XRay Tools
Modified: llvm/trunk/tools/llvm-xray/llvm-xray.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/llvm-xray.cc?rev=298975&r1=298974&r2=298975&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/llvm-xray.cc (original)
+++ llvm/trunk/tools/llvm-xray/llvm-xray.cc Tue Mar 28 23:55:45 2017
@@ -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);
}
More information about the llvm-commits
mailing list