llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

<details>
<summary>Changes</summary>

A `"unix://"` / `"unix-connect://"` URI carries a filesystem path after 
`"://"`. On Windows that path has a drive letter and backslashes and is not a 
`host:port` authority, so it must not go through `URI::Parse`.

rdar://180736036

---
Full diff: https://github.com/llvm/llvm-project/pull/206985.diff


2 Files Affected:

- (modified) 
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (+18-6) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
(+7-5) 


``````````diff
diff --git 
a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 1f69ef5f3f6ca..55fdc94df4b99 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -19,6 +19,7 @@
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/PosixApi.h"
+#include "lldb/Host/Socket.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/FileSpec.h"
@@ -226,13 +227,24 @@ Status PlatformRemoteGDBServer::ConnectRemote(Args &args) 
{
   if (!url)
     return Status::FromErrorString("URL is null.");
 
-  std::optional<URI> parsed_url = URI::Parse(url);
-  if (!parsed_url)
-    return Status::FromErrorStringWithFormat("Invalid URL: %s", url);
+  // Parse the scheme manually because URI::parse does not handle Windows 
paths.
+  llvm::StringRef scheme = llvm::StringRef(url).split("://").first;
+  std::optional<Socket::ProtocolModePair> protocol_and_mode =
+      Socket::GetProtocolAndMode(scheme);
+  if (protocol_and_mode &&
+      (protocol_and_mode->first == Socket::ProtocolUnixDomain ||
+       protocol_and_mode->first == Socket::ProtocolUnixAbstract)) {
+    m_platform_scheme = scheme.str();
+    m_platform_hostname = "";
+  } else {
+    std::optional<URI> parsed_url = URI::Parse(url);
+    if (!parsed_url)
+      return Status::FromErrorStringWithFormat("Invalid URL: %s", url);
 
-  // We're going to reuse the hostname when we connect to the debugserver.
-  m_platform_scheme = parsed_url->scheme.str();
-  m_platform_hostname = parsed_url->hostname.str();
+    // We're going to reuse the hostname when we connect to the debugserver.
+    m_platform_scheme = parsed_url->scheme.str();
+    m_platform_hostname = parsed_url->hostname.str();
+  }
 
   auto client_up =
       std::make_unique<process_gdb_remote::GDBRemoteCommunicationClient>();
diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 769705588fbdf..948e939a02613 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -4560,20 +4560,22 @@ void 
GDBRemoteCommunicationServerLLGS::AppendThreadIDToResponse(
 std::string
 lldb_private::process_gdb_remote::LLGSArgToURL(llvm::StringRef url_arg,
                                                bool reverse_connect) {
-  // Try parsing the argument as URL.
-  if (std::optional<URI> url = URI::Parse(url_arg)) {
+  // Parse the scheme manually because URI::parse does not handle Windows 
paths.
+  constexpr llvm::StringRef kSchemeSep = "://";
+  if (size_t pos = url_arg.find(kSchemeSep); pos != llvm::StringRef::npos) {
     if (reverse_connect)
       return url_arg.str();
 
     // Translate the scheme from LLGS notation to ConnectionFileDescriptor.
     // If the scheme doesn't match any, pass it through to support using CFD
     // schemes directly.
-    std::string new_url = llvm::StringSwitch<std::string>(url->scheme)
+    llvm::StringRef scheme = url_arg.substr(0, pos);
+    std::string new_url = llvm::StringSwitch<std::string>(scheme)
                               .Case("tcp", "listen")
                               .Case("unix", "unix-accept")
                               .Case("unix-abstract", "unix-abstract-accept")
-                              .Default(url->scheme.str());
-    llvm::append_range(new_url, url_arg.substr(url->scheme.size()));
+                              .Default(scheme.str());
+    llvm::append_range(new_url, url_arg.substr(scheme.size()));
     return new_url;
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/206985
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to