[Lldb-commits] [lldb] [lldb] Updated lldb-server to spawn the child process and share socket (PR #101283)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 05:22:45 PDT 2024


================
@@ -44,6 +47,112 @@ using namespace llvm;
 
 // option descriptors for getopt_long_only()
 
+#ifdef _WIN32
+typedef pipe_t fd_t;
+const fd_t kInvalidSharedFD = LLDB_INVALID_PIPE;
+#else
+typedef NativeSocket fd_t;
+const fd_t kInvalidSharedFD = Socket::kInvalidSocketValue;
+#endif
+
+class SharedSocket {
+public:
+  // Used by the parent process.
+  SharedSocket(Connection *conn, Status &error) {
+    m_fd = kInvalidSharedFD;
+
+    const Socket *socket =
+        static_cast<const Socket *>(conn->GetReadObject().get());
+    if (socket == nullptr) {
+      error = Status("invalid conn socket");
+      return;
+    }
+
+#ifdef _WIN32
+    m_socket = socket->GetNativeSocket();
+
+    // Create a pipe to transfer WSAPROTOCOL_INFO to the child process.
+    error = m_socket_pipe.CreateNew(true);
+    if (error.Fail())
+      return;
+
+    m_fd = m_socket_pipe.GetReadPipe();
+#else
+    m_fd = socket->GetNativeSocket();
+    error = Status();
+#endif
+  }
+
+  // Used by the child process.
+  SharedSocket(fd_t fd) : m_fd(fd) {}
----------------
labath wrote:

```suggestion
  explicit SharedSocket(fd_t fd) : m_fd(fd) {}
```

https://github.com/llvm/llvm-project/pull/101283


More information about the lldb-commits mailing list