Skip to content

[lldb-dap] Add a -v/--version command line argument #134114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

JDevlieghere
Copy link
Member

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/134114.diff

4 Files Affected:

  • (renamed) lldb/test/Shell/DAP/TestHelp.test (+1-1)
  • (added) lldb/test/Shell/DAP/TestVersion.test (+3)
  • (modified) lldb/tools/lldb-dap/Options.td (+6)
  • (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+12)
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);
@JDevlieghere
Copy link
Member Author

ToT output:

❯ ./bin/lldb-dap -v
lldb-dap: LLVM (http://llvm.org/):
  LLVM version 21.0.0git
  Optimized build with assertions.
liblldb: lldb version 21.0.0git (git@github.com:llvm/llvm-project.git revision 90f1e4fc39e4601285538d0df4b6984c27545b41)
  clang revision 90f1e4fc39e4601285538d0df4b6984c27545b41
  llvm revision 90f1e4fc39e4601285538d0df4b6984c27545b41
@JDevlieghere JDevlieghere merged commit 18c43d0 into llvm:main Apr 3, 2025
13 checks passed
@JDevlieghere JDevlieghere deleted the lldb-dap-version branch April 3, 2025 01:40
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request May 8, 2025
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.

(cherry picked from commit 18c43d0)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request May 9, 2025
…-18c43d01fc61

[lldb-dap] Add a -v/--version command line argument (llvm#134114)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants