From 0b7f12521966e04bd60df3e7a5327556631d2057 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 10 Aug 2020 08:15:33 -0700 Subject: [PATCH] [llvm-symbolizer] Add back --version and add a -v alias The switch from llvm::cl to OptTable (D83530) dropped --version, which is needed by some users. This patch also adds a -v alias, which is available in GNU addr2line. The version dumping is similar to llvm-objcopy --version (exotic): ``` llvm-symbolizer LLVM (http://llvm.org/): LLVM version 12.0.0git Optimized build with assertions. Default target: x86_64-unknown-linux-gnu Host CPU: skylake-avx512 ``` Reviewed By: dyung, jhenderson Differential Revision: https://reviews.llvm.org/D85624 --- llvm/docs/CommandGuide/llvm-symbolizer.rst | 2 +- llvm/test/tools/llvm-symbolizer/version.test | 8 ++++++++ llvm/tools/llvm-symbolizer/Opts.td | 2 ++ llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp | 11 ++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 llvm/test/tools/llvm-symbolizer/version.test diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst index 5c6a9511353c..c5d094f9552d 100644 --- a/llvm/docs/CommandGuide/llvm-symbolizer.rst +++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst @@ -346,7 +346,7 @@ OPTIONS Line: 15 Column: 0 -.. option:: --version +.. option:: --version, -v Print version information for the tool. diff --git a/llvm/test/tools/llvm-symbolizer/version.test b/llvm/test/tools/llvm-symbolizer/version.test new file mode 100644 index 000000000000..3edae82538db --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/version.test @@ -0,0 +1,8 @@ +# RUN: llvm-symbolizer --version | FileCheck %s --check-prefixes=SYMBOLIZER,COMMON +# RUN: llvm-symbolizer -v | FileCheck %s --check-prefixes=SYMBOLIZER,COMMON +# RUN: llvm-addr2line --version | FileCheck %s --check-prefixes=ADDR2LINE,COMMON +# RUN: llvm-addr2line -v | FileCheck %s --check-prefixes=ADDR2LINE,COMMON + +# SYMBOLIZER: llvm-symbolizer{{$}} +# ADDR2LINE: llvm-addr2line{{$}} +# COMMON: LLVM version {{.*}} diff --git a/llvm/tools/llvm-symbolizer/Opts.td b/llvm/tools/llvm-symbolizer/Opts.td index 8be550983fe2..ea28d98cbe27 100644 --- a/llvm/tools/llvm-symbolizer/Opts.td +++ b/llvm/tools/llvm-symbolizer/Opts.td @@ -43,6 +43,7 @@ def relativenames : F<"relativenames", "Strip the compilation directory from pat defm untag_addresses : B<"untag-addresses", "", "Remove memory tags from addresses before symbolization">; def use_native_pdb_reader : F<"use-native-pdb-reader", "Use native PDB functionality">; def verbose : F<"verbose", "Print verbose line info">; +def version : F<"version", "Display the version">; def : Flag<["-"], "a">, Alias, HelpText<"Alias for --addresses">; def : F<"print-address", "Alias for --addresses">, Alias; @@ -58,6 +59,7 @@ def : Flag<["-"], "i">, Alias, HelpText<"Alias for --inlines">; def : F<"inlining", "Alias for --inlines">, Alias; def : Flag<["-"], "p">, Alias, HelpText<"Alias for --pretty-print">; def : Flag<["-"], "s">, Alias, HelpText<"Alias for --basenames">; +def : Flag<["-"], "v">, Alias, HelpText<"Alias for --version">; // Compatibility aliases for old asan_symbolize.py and sanitizer binaries (before 2020-08). def : Flag<["--"], "inlining=true">, Alias, HelpText<"Alias for --inlines">; diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp index 2101d645dffa..f57922b2c506 100644 --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -190,9 +190,8 @@ static void symbolizeInput(const opt::InputArgList &Args, uint64_t AdjustVMA, outs() << "\n"; } -static void printHelp(bool IsAddr2Line, const SymbolizerOptTable &Tbl, +static void printHelp(StringRef ToolName, const SymbolizerOptTable &Tbl, raw_ostream &OS) { - StringRef ToolName = IsAddr2Line ? "llvm-addr2line" : "llvm-symbolizer"; const char HelpText[] = " [options] addresses..."; Tbl.PrintHelp(OS, (ToolName + HelpText).str().c_str(), ToolName.str().c_str()); @@ -203,6 +202,7 @@ static void printHelp(bool IsAddr2Line, const SymbolizerOptTable &Tbl, static opt::InputArgList parseOptions(int Argc, char *Argv[], bool IsAddr2Line, StringSaver &Saver, SymbolizerOptTable &Tbl) { + StringRef ToolName = IsAddr2Line ? "llvm-addr2line" : "llvm-symbolizer"; Tbl.setGroupedShortOptions(true); // The environment variable specifies initial options which can be overridden // by commnad line options. @@ -217,7 +217,12 @@ static opt::InputArgList parseOptions(int Argc, char *Argv[], bool IsAddr2Line, if (HasError) exit(1); if (Args.hasArg(OPT_help)) { - printHelp(IsAddr2Line, Tbl, outs()); + printHelp(ToolName, Tbl, outs()); + exit(0); + } + if (Args.hasArg(OPT_version)) { + outs() << ToolName << '\n'; + cl::PrintVersionMessage(); exit(0); }