3939#if LLDB_ENABLE_POSIX
4040#include " lldb/Host/posix/DomainSocket.h"
4141#endif
42- #ifdef __linux__
43- #include " lldb/Host/linux/AbstractSocket.h"
44- #endif
4542#include " lldb/Utility/FileSpec.h"
4643#include " lldb/Utility/LLDBLog.h"
4744#include " lldb/Utility/Status.h"
4845#include " lldb/Utility/UriParser.h"
4946
50- #if LLDB_ENABLE_POSIX
51- #include < sys/socket.h>
52- #include < sys/un.h>
53- #endif
54-
5547using namespace lldb ;
5648using namespace lldb_private ;
5749using namespace lldb_private ::lldb_server;
@@ -464,58 +456,28 @@ int main_platform(int argc, char *argv[]) {
464456 inferior_arguments.SetArguments (argc, const_cast <const char **>(argv));
465457
466458 Log *log = GetLog (LLDBLog::Platform);
467- Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain;
468-
469459 if (fd != SharedSocket::kInvalidFD ) {
470460 // Child process will handle the connection and exit.
471- if (gdbserver_port) {
472- protocol = Socket::ProtocolTcp;
473- } else {
474- #ifdef LLDB_ENABLE_POSIX
475- // Check if fd represents domain socket or abstract socket.
476- struct sockaddr_un addr;
477- socklen_t addr_len = sizeof (addr);
478- if (getsockname (fd, (struct sockaddr *)&addr, &addr_len) == -1 ) {
479- LLDB_LOGF (log, " lldb-platform child: not a socket or error occurred" );
480- return socket_error;
481- }
482-
483- if (addr.sun_family == AF_UNIX && addr.sun_path [0 ] == ' \0 ' ) {
484- protocol = Socket::ProtocolUnixAbstract;
485- }
486- #endif
487- }
488-
489461 NativeSocket sockfd;
490462 error = SharedSocket::GetNativeSocket (fd, sockfd);
491463 if (error.Fail ()) {
492464 LLDB_LOGF (log, " lldb-platform child: %s" , error.AsCString ());
493465 return socket_error;
494466 }
495467
496- GDBRemoteCommunicationServerPlatform platform (protocol, gdbserver_port);
497468 Socket *socket;
498- if (protocol == Socket::ProtocolTcp ) {
469+ if (gdbserver_port ) {
499470 socket = new TCPSocket (sockfd, /* should_close=*/ true );
500- } else if (protocol == Socket::ProtocolUnixDomain) {
501- #if LLDB_ENABLE_POSIX
502- socket = new DomainSocket (sockfd, /* should_close=*/ true );
503- #else
504- WithColor::error () << " lldb-platform child: Unix domain sockets are not "
505- " supported on this platform." ;
506- return socket_error;
507- #endif
508471 } else {
509- #ifdef __linux__
510- socket = new AbstractSocket (sockfd, /* should_close=*/ true );
511- #else
512- WithColor::error ()
513- << " lldb-platform child: Abstract domain sockets are not "
514- " supported on this platform." ;
515- return socket_error;
516- #endif
472+ socket = DomainSocket::Create (sockfd, /* should_close=*/ true , error);
473+ if (error.Fail ()) {
474+ LLDB_LOGF (log, " Failed to create socket: %s\n " , error.AsCString ());
475+ return socket_error;
476+ }
517477 }
518478
479+ Socket::SocketProtocol protocol = socket->GetSocketProtocol ();
480+ GDBRemoteCommunicationServerPlatform platform (protocol, gdbserver_port);
519481 platform.SetConnection (
520482 std::unique_ptr<Connection>(new ConnectionFileDescriptor (socket)));
521483 client_handle (platform, inferior_arguments);
@@ -530,6 +492,7 @@ int main_platform(int argc, char *argv[]) {
530492 return 1 ;
531493 }
532494
495+ Socket::SocketProtocol protocol;
533496 std::string address;
534497 std::string gdb_address;
535498 uint16_t platform_port = 0 ;
0 commit comments