saschwartz updated this revision to Diff 367401.
saschwartz added a comment.

Also propagate platform mode return codes and add additional test cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108351/new/

https://reviews.llvm.org/D108351

Files:
  lldb/test/Shell/lldb-server/TestErrorMessages.test
  lldb/test/Shell/lldb-server/TestGdbserverPort.test
  lldb/tools/lldb-server/lldb-platform.cpp
  lldb/tools/lldb-server/lldb-server.cpp

Index: lldb/tools/lldb-server/lldb-server.cpp
===================================================================
--- lldb/tools/lldb-server/lldb-server.cpp
+++ lldb/tools/lldb-server/lldb-server.cpp
@@ -52,29 +52,32 @@
   llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);
   llvm::PrettyStackTraceProgram X(argc, argv);
 
-  int option_error = 0;
   const char *progname = argv[0];
   if (argc < 2) {
     display_usage(progname);
-    exit(option_error);
+    exit(1);
   }
 
+  int ret = 0;
   switch (argv[1][0]) {
   case 'g':
     llgs::initialize();
-    main_gdbserver(argc, argv);
+    ret = main_gdbserver(argc, argv);
     llgs::terminate_debugger();
     break;
   case 'p':
     llgs::initialize();
-    main_platform(argc, argv);
+    ret = main_platform(argc, argv);
     llgs::terminate_debugger();
     break;
   case 'v':
     fprintf(stderr, "%s\n", lldb_private::GetVersion());
+    ret = 0;
     break;
   default:
     display_usage(progname);
-    exit(option_error);
+    ret = 1;
+    break;
   }
+  return ret;
 }
Index: lldb/tools/lldb-server/lldb-platform.cpp
===================================================================
--- lldb/tools/lldb-server/lldb-platform.cpp
+++ lldb/tools/lldb-server/lldb-platform.cpp
@@ -92,7 +92,6 @@
                   "log-channel-list] [--port-file port-file-path] --server "
                   "--listen port\n",
           progname, subcommand);
-  exit(0);
 }
 
 static Status save_socket_id_to_file(const std::string &socket_id,
@@ -269,7 +268,7 @@
 
   if (show_usage || option_error) {
     display_usage(progname, subcommand);
-    exit(option_error);
+    return option_error;
   }
 
   // Skip any options we consumed with getopt_long_only.
@@ -288,13 +287,13 @@
       listen_host_port, children_inherit_listen_socket, error));
   if (error.Fail()) {
     fprintf(stderr, "failed to create acceptor: %s", error.AsCString());
-    exit(socket_error);
+    return socket_error;
   }
 
   error = acceptor_up->Listen(backlog);
   if (error.Fail()) {
     printf("failed to listen: %s\n", error.AsCString());
-    exit(socket_error);
+    return socket_error;
   }
   if (socket_file) {
     error =
@@ -322,7 +321,7 @@
     error = acceptor_up->Accept(children_inherit_accept_socket, conn);
     if (error.Fail()) {
       WithColor::error() << error.AsCString() << '\n';
-      exit(socket_error);
+      return socket_error;
     }
     printf("Connection established.\n");
     if (g_server) {
Index: lldb/test/Shell/lldb-server/TestGdbserverPort.test
===================================================================
--- lldb/test/Shell/lldb-server/TestGdbserverPort.test
+++ lldb/test/Shell/lldb-server/TestGdbserverPort.test
@@ -1,4 +1,4 @@
 # Windows does not build lldb-server.
 # UNSUPPORTED: system-windows
-# RUN: %platformserver --server --listen :1234 --min-gdbserver-port 1234 --max-gdbserver-port 1234 2>&1 | FileCheck %s
+# RUN: not %platformserver --server --listen :1234 --min-gdbserver-port 1234 --max-gdbserver-port 1234 2>&1 | FileCheck %s
 # CHECK: error: --min-gdbserver-port (1234) is not lower than --max-gdbserver-port (1234)
Index: lldb/test/Shell/lldb-server/TestErrorMessages.test
===================================================================
--- lldb/test/Shell/lldb-server/TestErrorMessages.test
+++ lldb/test/Shell/lldb-server/TestErrorMessages.test
@@ -1,14 +1,26 @@
-RUN: %lldb-server gdbserver --fd 2>&1 | FileCheck --check-prefixes=FD1,ALL %s
+RUN: not %lldb-server gdbserver --fd 2>&1 | FileCheck --check-prefixes=FD1,GDB_REMOTE_ALL %s
 FD1: error: --fd: missing argument
 
-RUN: %lldb-server gdbserver --fd three 2>&1 | FileCheck --check-prefixes=FD2,ALL %s
+RUN: not %lldb-server gdbserver --fd three 2>&1 | FileCheck --check-prefixes=FD2,GDB_REMOTE_ALL %s
 FD2: error: invalid '--fd' argument
 
-RUN: %lldb-server gdbserver --bogus 2>&1 | FileCheck --check-prefixes=BOGUS,ALL %s
+RUN: not %lldb-server gdbserver --bogus 2>&1 | FileCheck --check-prefixes=BOGUS,GDB_REMOTE_ALL %s
 BOGUS: error: unknown argument '--bogus'
 
-RUN: %lldb-server gdbserver 2>&1 | FileCheck --check-prefixes=CONN,ALL %s
+RUN: not %lldb-server gdbserver 2>&1 | FileCheck --check-prefixes=CONN,GDB_REMOTE_ALL %s
 CONN: error: no connection arguments
 
-ALL: Use '{{.*}} g[dbserver] --help' for a complete list of options.
+RUN: %lldb-server platform 2>&1 | FileCheck --check-prefixes=LLDB_PLATFORM_ALL %s
+
+RUN: %lldb-server platform --fd 2>&1 | FileCheck --check-prefixes=FD3,LLDB_PLATFORM_ALL %s
+FD3: lldb-server: unrecognized option `--fd'
+
+RUN: not %lldb-server platform --min-gdbserver-port 42 --max-gdbserver-port 43 2>&1 | FileCheck --check-prefixes=PORT1,LLDB_PLATFORM_ALL %s
+PORT1: error: port number 42 is not in the valid user port range of 1024 - 49152 
+
+RUN: %lldb-server version 2>&1 | FileCheck --check-prefixes=VERSION %s
+VERSION: lldb version
+
+GDB_REMOTE_ALL: Use '{{.*}} g[dbserver] --help' for a complete list of options.
+LLDB_PLATFORM_ALL: lldb-server platform [--log-file log-file-name] [--log-channels log-channel-list] [--port-file port-file-path] --server --listen port 
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to