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
4245#include " lldb/Utility/FileSpec.h"
4346#include " lldb/Utility/LLDBLog.h"
4447#include " lldb/Utility/Status.h"
4548#include " lldb/Utility/UriParser.h"
4649
50+ #if LLDB_ENABLE_POSIX
51+ #include < sys/socket.h>
52+ #include < sys/un.h>
53+ #endif
54+
4755using namespace lldb ;
4856using namespace lldb_private ;
4957using namespace lldb_private ::lldb_server;
@@ -455,14 +463,28 @@ int main_platform(int argc, char *argv[]) {
455463 lldb_private::Args inferior_arguments;
456464 inferior_arguments.SetArguments (argc, const_cast <const char **>(argv));
457465
466+ Log *log = GetLog (LLDBLog::Platform);
458467 Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain;
459468
460469 if (fd != SharedSocket::kInvalidFD ) {
461470 // Child process will handle the connection and exit.
462- if (gdbserver_port)
471+ if (gdbserver_port) {
463472 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+ }
464482
465- Log *log = GetLog (LLDBLog::Platform);
483+ if (addr.sun_family == AF_UNIX && addr.sun_path [0 ] == ' \0 ' ) {
484+ protocol = Socket::ProtocolUnixAbstract;
485+ }
486+ #endif
487+ }
466488
467489 NativeSocket sockfd;
468490 error = SharedSocket::GetNativeSocket (fd, sockfd);
@@ -473,17 +495,27 @@ int main_platform(int argc, char *argv[]) {
473495
474496 GDBRemoteCommunicationServerPlatform platform (protocol, gdbserver_port);
475497 Socket *socket;
476- if (protocol == Socket::ProtocolTcp)
498+ if (protocol == Socket::ProtocolTcp) {
477499 socket = new TCPSocket (sockfd, /* should_close=*/ true );
478- else {
500+ } else if (protocol == Socket::ProtocolUnixDomain) {
479501#if LLDB_ENABLE_POSIX
480502 socket = new DomainSocket (sockfd, /* should_close=*/ true );
481503#else
482504 WithColor::error () << " lldb-platform child: Unix domain sockets are not "
483505 " supported on this platform." ;
484506 return socket_error;
507+ #endif
508+ } 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;
485516#endif
486517 }
518+
487519 platform.SetConnection (
488520 std::unique_ptr<Connection>(new ConnectionFileDescriptor (socket)));
489521 client_handle (platform, inferior_arguments);
0 commit comments