[debugserver] Add --version/-V command line option to debugserver.
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 27 Sep 2019 21:26:44 +0000 (21:26 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 27 Sep 2019 21:26:44 +0000 (21:26 +0000)
When not running under a TTY the output is buffered and not flushed
before debugserver exits which makes it impossible to parse the version
string. This adds a -V/--version command that just prints the version to
stdout and exits with an exit code zero.

Differential revision: https://reviews.llvm.org/D68156

llvm-svn: 373127

lldb/tools/debugserver/source/debugserver.cpp

index fa19bba..42205de 100644 (file)
@@ -789,6 +789,12 @@ void FileLogCallback(void *baton, uint32_t flags, const char *format,
   ::fflush((FILE *)baton);
 }
 
+void show_version_and_exit(int exit_code) {
+  printf("%s-%s for %s.\n", DEBUGSERVER_PROGRAM_NAME, DEBUGSERVER_VERSION_STR,
+         RNB_ARCH);
+  exit(exit_code);
+}
+
 void show_usage_and_exit(int exit_code) {
   RNBLogSTDERR(
       "Usage:\n  %s host:port [program-name program-arg1 program-arg2 ...]\n",
@@ -811,6 +817,7 @@ static struct option g_long_options[] = {
     {"debug", no_argument, NULL, 'g'},
     {"kill-on-error", no_argument, NULL, 'K'},
     {"verbose", no_argument, NULL, 'v'},
+    {"version", no_argument, NULL, 'V'},
     {"lockdown", no_argument, &g_lockdown_opt, 1}, // short option "-k"
     {"applist", no_argument, &g_applist_opt, 1},   // short option "-t"
     {"log-file", required_argument, NULL, 'l'},
@@ -1173,6 +1180,10 @@ int main(int argc, char *argv[]) {
       DNBLogSetVerbose(1);
       break;
 
+    case 'V':
+      show_version_and_exit(0);
+      break;
+
     case 's':
       ctx.GetSTDIN().assign(optarg);
       ctx.GetSTDOUT().assign(optarg);