Skip to content

Commit 18c43d0

Browse files
authored
[lldb-dap] Add a -v/--version command line argument (llvm#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.
1 parent ff0c2fb commit 18c43d0

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lldb/test/Shell/DAP/TestOptions.test renamed to lldb/test/Shell/DAP/TestHelp.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# CHECK: --help
55
# CHECK: -h
66
# CHECK: --repl-mode
7+
# CHECK: --version
78
# CHECK: --wait-for-debugger
8-

lldb/test/Shell/DAP/TestVersion.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# RUN: lldb-dap --version | FileCheck %s
2+
# CHECK: lldb-dap:
3+
# CHECK: liblldb:

lldb/tools/lldb-dap/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def: Flag<["-"], "h">,
1111
Alias<help>,
1212
HelpText<"Alias for --help">;
1313

14+
def version: F<"version">,
15+
HelpText<"Prints out the lldb-dap version.">;
16+
def: Flag<["-"], "v">,
17+
Alias<version>,
18+
HelpText<"Alias for --version">;
19+
1420
def wait_for_debugger: F<"wait-for-debugger">,
1521
HelpText<"Pause the program at startup.">;
1622
def: Flag<["-"], "g">,

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Option/ArgList.h"
3232
#include "llvm/Option/OptTable.h"
3333
#include "llvm/Option/Option.h"
34+
#include "llvm/Support/CommandLine.h"
3435
#include "llvm/Support/Error.h"
3536
#include "llvm/Support/FileSystem.h"
3637
#include "llvm/Support/InitLLVM.h"
@@ -177,6 +178,12 @@ static void PrintHelp(LLDBDAPOptTable &table, llvm::StringRef tool_name) {
177178
)___";
178179
}
179180

181+
static void PrintVersion() {
182+
llvm::outs() << "lldb-dap: ";
183+
llvm::cl::PrintVersionMessage();
184+
llvm::outs() << "liblldb: " << lldb::SBDebugger::GetVersionString() << '\n';
185+
}
186+
180187
// If --launch-target is provided, this instance of lldb-dap becomes a
181188
// runInTerminal launcher. It will ultimately launch the program specified in
182189
// the --launch-target argument, which is the original program the user wanted
@@ -421,6 +428,11 @@ int main(int argc, char *argv[]) {
421428
return EXIT_SUCCESS;
422429
}
423430

431+
if (input_args.hasArg(OPT_version)) {
432+
PrintVersion();
433+
return EXIT_SUCCESS;
434+
}
435+
424436
ReplMode default_repl_mode = ReplMode::Auto;
425437
if (input_args.hasArg(OPT_repl_mode)) {
426438
llvm::opt::Arg *repl_mode = input_args.getLastArg(OPT_repl_mode);

0 commit comments

Comments
 (0)