[Lldb-commits] [lldb] [lldb] Removed gdbserver ports map from lldb-server (PR #104238)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 4 01:12:20 PDT 2024


================
@@ -666,7 +756,23 @@ ConnectionStatus
 ConnectionFileDescriptor::ConnectFD(llvm::StringRef s,
                                     socket_id_callback_type socket_id_callback,
                                     Status *error_ptr) {
-#if LLDB_ENABLE_POSIX
+#ifdef _WIN32
+  int64_t fd = -1;
+  if (!s.getAsInteger(0, fd)) {
+    // Assume we own fd.
+    std::unique_ptr<TCPSocket> tcp_socket =
+        std::make_unique<TCPSocket>((NativeSocket)fd, true, false);
+    m_io_sp = std::move(tcp_socket);
+    m_uri = s.str();
+    return eConnectionStatusSuccess;
+  }
----------------
labath wrote:

Reducing the number of ifdefs is great, but it also must be balanced with considerations like code readability and user confusion. I don't think this strikes the right balance as FD's are a thing on windows as well, and so this could be very surprising. Handles are windows-specific, but we are already using them in lldb as a generic concept of an object identifier. E.g. Socket::GetWaitableHandle returns the fd (`int`) on posix and the socket handle (`SOCKET`) on windows.

Here's a specific suggestion: We can sidestep this problem by not roundtripping the socket through a string URL. ConnectionFileDescriptor has a constructor which takes a `Socket` argument, so I think we could use that. If we also make `SharedSocket::GetNativeSocket` (`GetSocket` ?) return a Socket object, then we can also reduce the usage of raw NativeSocket values.

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


More information about the lldb-commits mailing list