https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/205618
>From 4f6f56a655cc463f694bdca9b6ac8396e62582fc Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Wed, 24 Jun 2026 18:49:32 +0100 Subject: [PATCH 1/3] [lldb][Windows] Support AF_UNIX domain sockets --- lldb/source/Host/CMakeLists.txt | 1 + lldb/source/Host/common/DomainSocket.cpp | 3 +++ lldb/source/Host/common/Socket.cpp | 2 +- lldb/tools/lldb-server/lldb-platform.cpp | 2 +- lldb/unittests/Host/SocketTest.cpp | 11 +++++++++-- .../TestingSupport/Host/SocketTestUtilities.cpp | 7 ++++--- .../TestingSupport/Host/SocketTestUtilities.h | 4 ++-- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 57a833af97184..96a1c4d865c79 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -74,6 +74,7 @@ endif() add_host_subdirectory(posix posix/ConnectionFileDescriptorPosix.cpp + posix/DomainSocket.cpp ) if (CMAKE_SYSTEM_NAME MATCHES "Windows") diff --git a/lldb/source/Host/common/DomainSocket.cpp b/lldb/source/Host/common/DomainSocket.cpp index 28ec1b7d25dae..b915009fbe93f 100644 --- a/lldb/source/Host/common/DomainSocket.cpp +++ b/lldb/source/Host/common/DomainSocket.cpp @@ -16,14 +16,17 @@ #include "llvm/Support/Errno.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include <algorithm> +#include <chrono> #include <cstddef> #include <memory> #ifdef _WIN32 #include <afunix.h> #else +#include <fcntl.h> #include <sys/socket.h> #include <sys/un.h> #endif diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index c0247509df1c1..629cb8a6f90cb 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -211,7 +211,7 @@ std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol, socket_up = std::make_unique<UDPSocket>(should_close); break; case ProtocolUnixDomain: -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) socket_up = std::make_unique<DomainSocket>(should_close); #else error = Status::FromErrorString( diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 88c10815afc24..1b13ca65b8318 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -537,7 +537,7 @@ int main_platform(int argc, char *argv[]) { if (gdbserver_port) { socket = std::make_unique<TCPSocket>(sockfd, /*should_close=*/true); } else { -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) llvm::Expected<std::unique_ptr<DomainSocket>> domain_socket = DomainSocket::FromBoundNativeSocket(sockfd, /*should_close=*/true); if (!domain_socket) { diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp index cdc02e96f40b7..0e2488107d6c1 100644 --- a/lldb/unittests/Host/SocketTest.cpp +++ b/lldb/unittests/Host/SocketTest.cpp @@ -93,6 +93,11 @@ TEST_F(SocketTest, CreatePair) { functional_protocols.push_back(Socket::ProtocolUnixDomain); functional_protocols.push_back(Socket::ProtocolUnixAbstract); } +#elif defined(_WIN32) + // Windows supports AF_UNIX domain sockets (Windows 10 1803+) but not the + // Linux abstract-namespace variant. + if (HostSupportsDomainSockets()) + functional_protocols.push_back(Socket::ProtocolUnixDomain); #endif for (auto p : functional_protocols) { @@ -111,7 +116,7 @@ TEST_F(SocketTest, CreatePair) { std::vector<Socket::SocketProtocol> erroring_protocols = { #if !LLDB_ENABLE_POSIX - Socket::ProtocolUnixDomain, + // Windows has AF_UNIX domain sockets but no abstract-namespace sockets. Socket::ProtocolUnixAbstract, #endif }; @@ -121,7 +126,7 @@ TEST_F(SocketTest, CreatePair) { } } -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) TEST_F(SocketTest, DomainListenConnectAccept) { if (!HostSupportsDomainSockets()) GTEST_SKIP() << "Domain sockets unavailable"; @@ -401,6 +406,7 @@ TEST_F(SocketTest, DomainGetConnectURI) { EXPECT_EQ(socket_b_up->GetRemoteConnectionURI(), ""); } +#endif TEST_F(SocketTest, DomainSocketPathURIConversion) { // Paths that are already valid URI paths (no drive letter) are unchanged. @@ -425,6 +431,7 @@ TEST_F(SocketTest, DomainSocketPathURIConversion) { "\\\\server\\share\\sock"); } +#if LLDB_ENABLE_POSIX || defined(_WIN32) TEST_F(SocketTest, DomainSocketFromBoundNativeSocket) { if (!HostSupportsDomainSockets()) GTEST_SKIP() << "Domain sockets unavailable"; diff --git a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp index 2c5e310ea9a9b..5b66004a7a33e 100644 --- a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp +++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp @@ -71,7 +71,7 @@ bool lldb_private::CreateTCPConnectedSockets( return true; } -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) void lldb_private::CreateDomainConnectedSockets( llvm::StringRef path, std::unique_ptr<DomainSocket> *socket_a_up, std::unique_ptr<DomainSocket> *socket_b_up) { @@ -148,16 +148,17 @@ llvm::Expected<std::string> lldb_private::GetLocalhostIP() { "Neither IPv4 nor IPv6 appear to be supported"); } -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) bool lldb_private::HostSupportsDomainSockets() { llvm::SmallString<64> Path; if (llvm::sys::fs::createUniqueDirectory("SocketTestCanary", Path)) return false; + auto cleanup_dir = Path; llvm::sys::path::append(Path, "test"); DomainSocket sock(true); Status status = sock.Listen(Path, 1); llvm::sys::fs::remove(Path); - llvm::sys::fs::remove(Path.str().rsplit('/').first); + llvm::sys::fs::remove(cleanup_dir); return status.Success(); } #endif diff --git a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h index a03baf190dd33..bde9b0a778789 100644 --- a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h +++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h @@ -34,7 +34,7 @@ void CreateConnectedSockets( bool CreateTCPConnectedSockets(std::string listen_remote_ip, std::unique_ptr<TCPSocket> *a_up, std::unique_ptr<TCPSocket> *b_up); -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) void CreateDomainConnectedSockets(llvm::StringRef path, std::unique_ptr<DomainSocket> *a_up, std::unique_ptr<DomainSocket> *b_up); @@ -42,7 +42,7 @@ void CreateDomainConnectedSockets(llvm::StringRef path, bool HostSupportsIPv6(); bool HostSupportsIPv4(); -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) bool HostSupportsDomainSockets(); #endif >From 785ee165cce0e60669d5113b851105d95956e0b7 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Mon, 29 Jun 2026 18:08:38 +0100 Subject: [PATCH 2/3] fixup! [lldb][Windows] Support AF_UNIX domain sockets --- lldb/source/Host/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 96a1c4d865c79..57a833af97184 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -74,7 +74,6 @@ endif() add_host_subdirectory(posix posix/ConnectionFileDescriptorPosix.cpp - posix/DomainSocket.cpp ) if (CMAKE_SYSTEM_NAME MATCHES "Windows") >From 8d58611d40214c8a7650fa7c3543f3bb62349a34 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Tue, 30 Jun 2026 14:08:13 +0100 Subject: [PATCH 3/3] fixup! [lldb][Windows] Support AF_UNIX domain sockets --- lldb/source/Host/common/Socket.cpp | 2 +- lldb/unittests/TestingSupport/Host/SocketTestUtilities.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 629cb8a6f90cb..a6d71cf1ec105 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -242,7 +242,7 @@ Socket::CreatePair(std::optional<SocketProtocol> protocol) { case ProtocolTcp: return TCPSocket::CreatePair(); case ProtocolUnixDomain: -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) return DomainSocketPlatform::CreatePair(); #else return llvm::createStringError("unsupported protocol"); diff --git a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h index bde9b0a778789..39995b0d4b5b9 100644 --- a/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h +++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h @@ -21,7 +21,7 @@ #include "llvm/Support/Path.h" #include "llvm/Testing/Support/Error.h" -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX || defined(_WIN32) #include "lldb/Host/common/DomainSocket.h" #endif _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
