39
39
#if LLDB_ENABLE_POSIX
40
40
#include " lldb/Host/posix/DomainSocket.h"
41
41
#endif
42
- #ifdef __linux__
43
- #include " lldb/Host/linux/AbstractSocket.h"
44
- #endif
45
42
#include " lldb/Utility/FileSpec.h"
46
43
#include " lldb/Utility/LLDBLog.h"
47
44
#include " lldb/Utility/Status.h"
48
45
#include " lldb/Utility/UriParser.h"
49
46
50
- #if LLDB_ENABLE_POSIX
51
- #include < sys/socket.h>
52
- #include < sys/un.h>
53
- #endif
54
-
55
47
using namespace lldb ;
56
48
using namespace lldb_private ;
57
49
using namespace lldb_private ::lldb_server;
@@ -464,58 +456,28 @@ int main_platform(int argc, char *argv[]) {
464
456
inferior_arguments.SetArguments (argc, const_cast <const char **>(argv));
465
457
466
458
Log *log = GetLog (LLDBLog::Platform);
467
- Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain;
468
-
469
459
if (fd != SharedSocket::kInvalidFD ) {
470
460
// 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
-
489
461
NativeSocket sockfd;
490
462
error = SharedSocket::GetNativeSocket (fd, sockfd);
491
463
if (error.Fail ()) {
492
464
LLDB_LOGF (log , " lldb-platform child: %s" , error.AsCString ());
493
465
return socket_error;
494
466
}
495
467
496
- GDBRemoteCommunicationServerPlatform platform (protocol, gdbserver_port);
497
468
Socket *socket;
498
- if (protocol == Socket::ProtocolTcp ) {
469
+ if (gdbserver_port ) {
499
470
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
508
471
} 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
+ }
517
477
}
518
478
479
+ Socket::SocketProtocol protocol = socket->GetSocketProtocol ();
480
+ GDBRemoteCommunicationServerPlatform platform (protocol, gdbserver_port);
519
481
platform.SetConnection (
520
482
std::unique_ptr<Connection>(new ConnectionFileDescriptor (socket)));
521
483
client_handle (platform, inferior_arguments);
@@ -530,6 +492,7 @@ int main_platform(int argc, char *argv[]) {
530
492
return 1 ;
531
493
}
532
494
495
+ Socket::SocketProtocol protocol;
533
496
std::string address;
534
497
std::string gdb_address;
535
498
uint16_t platform_port = 0 ;
0 commit comments