[Lldb-commits] [lldb] [lldb][Windows] Support AF_UNIX domain sockets (PR #205618)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 15 08:56:06 PDT 2026
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/205618
>From 02afdb53384a79219a58d0cb21ddc6974f122460 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 24 Jun 2026 18:49:32 +0100
Subject: [PATCH] [lldb][Windows] Support AF_UNIX domain sockets
---
lldb/source/Host/common/Socket.cpp | 4 ++--
lldb/tools/lldb-server/lldb-platform.cpp | 2 +-
lldb/unittests/Host/SocketTest.cpp | 11 +++++++++--
.../TestingSupport/Host/SocketTestUtilities.cpp | 7 ++++---
.../TestingSupport/Host/SocketTestUtilities.h | 6 +++---
5 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index c0247509df1c1..a6d71cf1ec105 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(
@@ -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/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..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
@@ -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
More information about the lldb-commits
mailing list