Author: Jonas Devlieghere Date: 2025-04-02T18:40:37-07:00 New Revision: 18c43d01fc61648369fef50999e7df62b3ec292f
URL: https://github.com/llvm/llvm-project/commit/18c43d01fc61648369fef50999e7df62b3ec292f DIFF: https://github.com/llvm/llvm-project/commit/18c43d01fc61648369fef50999e7df62b3ec292f.diff LOG: [lldb-dap] Add a -v/--version command line argument (#134114) Add a -v/--version command line argument to print the version of both the lldb-dap binary and the liblldb it's linked against. This is motivated by me trying to figure out which lldb-dap I had in my PATH. Added: lldb/test/Shell/DAP/TestHelp.test lldb/test/Shell/DAP/TestVersion.test Modified: lldb/tools/lldb-dap/Options.td lldb/tools/lldb-dap/lldb-dap.cpp Removed: lldb/test/Shell/DAP/TestOptions.test ################################################################################ diff --git a/lldb/test/Shell/DAP/TestOptions.test b/lldb/test/Shell/DAP/TestHelp.test similarity index 88% rename from lldb/test/Shell/DAP/TestOptions.test rename to lldb/test/Shell/DAP/TestHelp.test index d290cdae590fd..6033cf15e3835 100644 --- a/lldb/test/Shell/DAP/TestOptions.test +++ b/lldb/test/Shell/DAP/TestHelp.test @@ -4,5 +4,5 @@ # CHECK: --help # CHECK: -h # CHECK: --repl-mode +# CHECK: --version # CHECK: --wait-for-debugger - diff --git a/lldb/test/Shell/DAP/TestVersion.test b/lldb/test/Shell/DAP/TestVersion.test new file mode 100644 index 0000000000000..ad3ff67e45d79 --- /dev/null +++ b/lldb/test/Shell/DAP/TestVersion.test @@ -0,0 +1,3 @@ +# RUN: lldb-dap --version | FileCheck %s +# CHECK: lldb-dap: +# CHECK: liblldb: diff --git a/lldb/tools/lldb-dap/Options.td b/lldb/tools/lldb-dap/Options.td index a1baf2f0370bd..aecf91797ac70 100644 --- a/lldb/tools/lldb-dap/Options.td +++ b/lldb/tools/lldb-dap/Options.td @@ -11,6 +11,12 @@ def: Flag<["-"], "h">, Alias<help>, HelpText<"Alias for --help">; +def version: F<"version">, + HelpText<"Prints out the lldb-dap version.">; +def: Flag<["-"], "v">, + Alias<version>, + HelpText<"Alias for --version">; + def wait_for_debugger: F<"wait-for-debugger">, HelpText<"Pause the program at startup.">; def: Flag<["-"], "g">, diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index b91c62e921428..ec87db6aab330 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -31,6 +31,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/InitLLVM.h" @@ -177,6 +178,12 @@ static void PrintHelp(LLDBDAPOptTable &table, llvm::StringRef tool_name) { )___"; } +static void PrintVersion() { + llvm::outs() << "lldb-dap: "; + llvm::cl::PrintVersionMessage(); + llvm::outs() << "liblldb: " << lldb::SBDebugger::GetVersionString() << '\n'; +} + // If --launch-target is provided, this instance of lldb-dap becomes a // runInTerminal launcher. It will ultimately launch the program specified in // the --launch-target argument, which is the original program the user wanted @@ -421,6 +428,11 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; } + if (input_args.hasArg(OPT_version)) { + PrintVersion(); + return EXIT_SUCCESS; + } + ReplMode default_repl_mode = ReplMode::Auto; if (input_args.hasArg(OPT_repl_mode)) { llvm::opt::Arg *repl_mode = input_args.getLastArg(OPT_repl_mode); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits