================ @@ -393,125 +362,222 @@ int main_platform(int argc, char *argv[]) { lldb_private::Args inferior_arguments; inferior_arguments.SetArguments(argc, const_cast<const char **>(argv)); + Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain; + if (fd != SharedSocket::kInvalidFD) { // Child process will handle the connection and exit. + if (gdbserver_port) + protocol = Socket::ProtocolTcp; + Log *log = GetLog(LLDBLog::Platform); - if (!listen_host_port.empty()) { - LLDB_LOGF(log, "lldb-platform child: " - "ambiguous parameters --listen and --child-platform-fd"); - return socket_error; - } - NativeSocket socket; - error = SharedSocket::GetNativeSocket(fd, socket); + NativeSocket sockfd; + error = SharedSocket::GetNativeSocket(fd, sockfd); if (error.Fail()) { LLDB_LOGF(log, "lldb-platform child: %s", error.AsCString()); return socket_error; } - GDBRemoteCommunicationServerPlatform platform(Socket::ProtocolTcp, "tcp"); - if (port_offset > 0) - platform.SetPortOffset(port_offset); - platform.SetPortMap(std::move(gdbserver_portmap)); + GDBRemoteCommunicationServerPlatform platform(protocol, gdbserver_port); + Socket *socket; + if (protocol == Socket::ProtocolTcp) + socket = new TCPSocket(sockfd, /*should_close=*/true, + /*child_processes_inherit=*/false); + else { +#if LLDB_ENABLE_POSIX + socket = new DomainSocket(sockfd, /*should_close=*/true, + /*child_processes_inherit=*/false); +#else + LLDB_LOGF(log, + "lldb-platform child: Unix domain sockets are not supported on " + "this platform."); + return socket_error; +#endif + } platform.SetConnection( - std::unique_ptr<Connection>(new ConnectionFileDescriptor( - new TCPSocket(socket, /*should_close=*/true, - /*child_processes_inherit=*/false)))); + std::unique_ptr<Connection>(new ConnectionFileDescriptor(socket))); client_handle(platform, inferior_arguments); return 0; } - const bool children_inherit_listen_socket = false; - // the test suite makes many connections in parallel, let's not miss any. - // The highest this should get reasonably is a function of the number - // of target CPUs. For now, let's just use 100. - const int backlog = 100; + if (gdbserver_port != 0 && + (gdbserver_port < LOW_PORT || gdbserver_port > HIGH_PORT)) { + WithColor::error() << llvm::formatv("Port number {0} is not in the " + "valid user port range of {1} - {2}\n", + gdbserver_port, LOW_PORT, HIGH_PORT); + return 1; + } - std::unique_ptr<Acceptor> acceptor_up(Acceptor::Create( - listen_host_port, children_inherit_listen_socket, error)); - if (error.Fail()) { - fprintf(stderr, "failed to create acceptor: %s", error.AsCString()); - exit(socket_error); + std::string hostname; + uint16_t platform_port = 0; + + // Try to match socket name as URL - e.g., tcp://localhost:5555 + if (std::optional<URI> uri = URI::Parse(listen_host_port)) { + if (!Socket::FindProtocolByScheme(uri->scheme.str().c_str(), protocol)) { + fprintf(stderr, "Unknown protocol scheme \"%s\".", + uri->scheme.str().c_str()); + return socket_error; + } + if (protocol == Socket::ProtocolTcp) { + hostname = uri->hostname; + if (uri->port) { + platform_port = *(uri->port); + } + } else + hostname = listen_host_port.substr(uri->scheme.size() + strlen("://")); + } else { + // Try to match socket name as $host:port - e.g., localhost:5555 + llvm::Expected<Socket::HostAndPort> host_port = + Socket::DecodeHostAndPort(listen_host_port); + if (!llvm::errorToBool(host_port.takeError())) { + protocol = Socket::ProtocolTcp; + hostname = host_port->hostname; + platform_port = host_port->port; + } else + hostname = listen_host_port; } - error = acceptor_up->Listen(backlog); + if (protocol == Socket::ProtocolTcp) { + if (platform_port != 0 && platform_port == gdbserver_port) { + fprintf(stderr, "The same platform and gdb ports %u.", platform_port); + return socket_error; + } + } else { + if (gdbserver_port) { + fprintf(stderr, + "--gdbserver-port %u is redundant for non-tcp protocol %s.", + gdbserver_port, Socket::FindSchemeByProtocol(protocol)); + return socket_error; + } + if (g_server) { + fprintf(stderr, + "Ambiguous parameters --server --listen %s.\n" + "The protocol must be tcp for the server mode.", + listen_host_port.c_str()); + return socket_error; ---------------- labath wrote:
Why is that the case? I'd like the combination to work (it does right now). https://github.com/llvm/llvm-project/pull/104238 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits