aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
diff options
context:
space:
mode:
authorMichał Górny <mgorny@moritz.systems>2021-10-22 17:42:23 +0200
committerMichał Górny <mgorny@moritz.systems>2021-10-26 13:06:19 +0200
commit58d28b931f92f5ea2a6a01e088b794ee6ebd05e7 (patch)
tree6be42ab06638c62e0469fa604100b0c150ec0e5d /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
parent93c7ed8c3f8e2b2966e565758d0992ec1b07a11f (diff)
downloadllvm-58d28b931f92f5ea2a6a01e088b794ee6ebd05e7.zip
llvm-58d28b931f92f5ea2a6a01e088b794ee6ebd05e7.tar.gz
llvm-58d28b931f92f5ea2a6a01e088b794ee6ebd05e7.tar.bz2
[lldb] [lldb-gdbserver] Unify listen/connect code to use ConnectionFileDescriptor
Unify the listen and connect code inside lldb-server to use ConnectionFileDescriptor uniformly rather than a mix of it and Acceptor. This involves: - adding a function to map legacy values of host:port parameter (including legacy server URLs) into CFD-style URLs - adding a callback to return "local socket id" (i.e. UNIX socket path or TCP port number) between listen() and accept() calls in CFD - adding a "unix-abstract-accept" scheme to CFD As an additional advantage, this permits lldb-server to accept any URL known to CFD including the new serial:// scheme. Effectively, lldb-server can now listen on the serial port. Tests for connecting over a pty are added to test that. Differential Revision: https://reviews.llvm.org/D111964
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index b1e9e3c..27acf7e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -25,6 +25,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/PosixApi.h"
+#include "lldb/Host/Socket.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Host/common/NativeRegisterContext.h"
#include "lldb/Host/common/NativeThreadProtocol.h"
@@ -39,6 +40,7 @@
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/UnimplementedError.h"
+#include "lldb/Utility/UriParser.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -3888,3 +3890,42 @@ void GDBRemoteCommunicationServerLLGS::SetEnabledExtensions(
assert(!bool(flags & ~m_process_factory.GetSupportedExtensions()));
process.SetEnabledExtensions(flags);
}
+
+std::string
+lldb_private::process_gdb_remote::LLGSArgToURL(llvm::StringRef url_arg,
+ bool reverse_connect) {
+ // Try parsing the argument as URL.
+ if (llvm::Optional<URI> url = URI::Parse(url_arg)) {
+ 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)
+ .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()));
+ return new_url;
+ }
+
+ std::string host_port = url_arg.str();
+ // If host_and_port starts with ':', default the host to be "localhost" and
+ // expect the remainder to be the port.
+ if (url_arg.startswith(":"))
+ host_port.insert(0, "localhost");
+
+ std::string host_str;
+ std::string port_str;
+ uint16_t port;
+ // Try parsing the (preprocessed) argument as host:port pair.
+ if (!llvm::errorToBool(
+ Socket::DecodeHostAndPort(host_port, host_str, port_str, port)))
+ return (reverse_connect ? "connect://" : "listen://") + host_port;
+
+ // If none of the above applied, interpret the argument as UNIX socket path.
+ return (reverse_connect ? "unix-connect://" : "unix-accept://") +
+ url_arg.str();
+}