diff options
author | Greg Clayton <gclayton@apple.com> | 2010-10-19 03:25:40 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-10-19 03:25:40 +0000 |
commit | 3fcbed6bda344dbf16dd0db8930b28d95bc4b4b4 (patch) | |
tree | 13e028c6e8f9439c1edb618d74f297c4068c53d6 /lldb/source/Core/ConnectionFileDescriptor.cpp | |
parent | 392f084f46f9b759f9aca3d429f681cb6b32f2e0 (diff) | |
download | bcm5719-llvm-3fcbed6bda344dbf16dd0db8930b28d95bc4b4b4.tar.gz bcm5719-llvm-3fcbed6bda344dbf16dd0db8930b28d95bc4b4b4.zip |
Stop the driver from handling SIGPIPE in case we communicate with stale
sockets so the driver doesn't just crash.
Added support for connecting to named sockets (unix IPC sockets) in
ConnectionFileDescriptor.
Modified the Host::LaunchInNewTerminal() for MacOSX to return the process
ID of the inferior process instead of the process ID of the Terminal.app. This
was done by modifying the "darwin-debug" executable to connect to lldb through
a named unix socket which is passed down as an argument. This allows a quick
handshake between "lldb" and "darwin-debug" so we can get the process ID
of the inferior and then attach by process ID and avoid attaching to the
inferior by process name since there could be more than one process with
that name. This still has possible race conditions, those will be fixed
in the near future. This fixes the SIGPIPE issues that were sometimes being
seen when task_for_pid was failing.
llvm-svn: 116792
Diffstat (limited to 'lldb/source/Core/ConnectionFileDescriptor.cpp')
-rw-r--r-- | lldb/source/Core/ConnectionFileDescriptor.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp index 292bc746b0b..dc190a1b781 100644 --- a/lldb/source/Core/ConnectionFileDescriptor.cpp +++ b/lldb/source/Core/ConnectionFileDescriptor.cpp @@ -18,6 +18,7 @@ #include <netinet/tcp.h> #include <sys/socket.h> #include <sys/types.h> +#include <sys/un.h> #include <string.h> #include <stdlib.h> @@ -85,6 +86,11 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr) unsigned long listen_port = ::strtoul(s + strlen("listen://"), &end, 0); return SocketListen (listen_port, error_ptr); } + else if (strstr(s, "unix-accept://")) + { + // unix://SOCKNAME + return NamedSocketAccept (s + strlen("unix-accept://"), error_ptr); + } else if (strstr(s, "connect://")) { return SocketConnect (s + strlen("connect://"), error_ptr); @@ -400,6 +406,53 @@ ConnectionFileDescriptor::Close (int& fd, Error *error_ptr) } ConnectionStatus +ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *error_ptr) +{ + ConnectionStatus result = eConnectionStatusError; + struct sockaddr_un saddr_un; + + m_is_socket = true; + + int listen_socket = ::socket (AF_UNIX, SOCK_STREAM, 0); + if (listen_socket == -1) + { + if (error_ptr) + error_ptr->SetErrorToErrno(); + return eConnectionStatusError; + } + + saddr_un.sun_family = AF_UNIX; + ::strncpy(saddr_un.sun_path, socket_name, sizeof(saddr_un.sun_path) - 1); + saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; + saddr_un.sun_len = SUN_LEN (&saddr_un); + + if (::bind (listen_socket, (struct sockaddr *)&saddr_un, SUN_LEN (&saddr_un)) == 0) + { + if (::listen (listen_socket, 5) == 0) + { + m_fd = ::accept (listen_socket, NULL, 0); + if (m_fd > 0) + { + m_should_close_fd = true; + + if (error_ptr) + error_ptr->Clear(); + result = eConnectionStatusSuccess; + } + } + } + + if (result != eConnectionStatusSuccess) + { + if (error_ptr) + error_ptr->SetErrorToErrno(); + } + // We are done with the listen port + Close (listen_socket, NULL); + return result; +} + +ConnectionStatus ConnectionFileDescriptor::SocketListen (uint16_t listen_port_num, Error *error_ptr) { lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION, |