summaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectProtocolServer.cpp
diff options
context:
space:
mode:
authorLU-JOHN <John.Lu@amd.com>2025-08-01 08:38:29 +0000
committerAlexis Engelke <engelke@in.tum.de>2025-08-01 08:38:29 +0000
commite993e7b900cd00be42430c3dee0e5fa61aba5080 (patch)
treef7b4e1c57ea940ed2102c7fbacc79985ed0b5a35 /lldb/source/Commands/CommandObjectProtocolServer.cpp
parent36819eaed124d6a7339a151b6172cd543fe3579a (diff)
[𝘀𝗽𝗿] changes to main this commit is based onusers/aengelke/spr/main.ir-make-branchinst-operand-order-consistent
Created using spr 1.3.5-bogner [skip ci]
Diffstat (limited to 'lldb/source/Commands/CommandObjectProtocolServer.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectProtocolServer.cpp63
1 files changed, 17 insertions, 46 deletions
diff --git a/lldb/source/Commands/CommandObjectProtocolServer.cpp b/lldb/source/Commands/CommandObjectProtocolServer.cpp
index 115754769f3e..f11e27f01c8a 100644
--- a/lldb/source/Commands/CommandObjectProtocolServer.cpp
+++ b/lldb/source/Commands/CommandObjectProtocolServer.cpp
@@ -23,20 +23,6 @@ using namespace lldb_private;
#define LLDB_OPTIONS_mcp
#include "CommandOptions.inc"
-static std::vector<llvm::StringRef> GetSupportedProtocols() {
- std::vector<llvm::StringRef> supported_protocols;
- size_t i = 0;
-
- for (llvm::StringRef protocol_name =
- PluginManager::GetProtocolServerPluginNameAtIndex(i++);
- !protocol_name.empty();
- protocol_name = PluginManager::GetProtocolServerPluginNameAtIndex(i++)) {
- supported_protocols.push_back(protocol_name);
- }
-
- return supported_protocols;
-}
-
class CommandObjectProtocolServerStart : public CommandObjectParsed {
public:
CommandObjectProtocolServerStart(CommandInterpreter &interpreter)
@@ -57,12 +43,11 @@ protected:
}
llvm::StringRef protocol = args.GetArgumentAtIndex(0);
- std::vector<llvm::StringRef> supported_protocols = GetSupportedProtocols();
- if (llvm::find(supported_protocols, protocol) ==
- supported_protocols.end()) {
+ ProtocolServer *server = ProtocolServer::GetOrCreate(protocol);
+ if (!server) {
result.AppendErrorWithFormatv(
"unsupported protocol: {0}. Supported protocols are: {1}", protocol,
- llvm::join(GetSupportedProtocols(), ", "));
+ llvm::join(ProtocolServer::GetSupportedProtocols(), ", "));
return;
}
@@ -72,10 +57,6 @@ protected:
}
llvm::StringRef connection_uri = args.GetArgumentAtIndex(1);
- ProtocolServerSP server_sp = GetDebugger().GetProtocolServer(protocol);
- if (!server_sp)
- server_sp = ProtocolServer::Create(protocol, GetDebugger());
-
const char *connection_error =
"unsupported connection specifier, expected 'accept:///path' or "
"'listen://[host]:port', got '{0}'.";
@@ -94,23 +75,25 @@ protected:
ProtocolServer::Connection connection;
connection.protocol = protocol_and_mode->first;
- connection.name =
- formatv("[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
- uri->port.value_or(0));
-
- if (llvm::Error error = server_sp->Start(connection)) {
+ if (connection.protocol == Socket::SocketProtocol::ProtocolUnixDomain)
+ connection.name = uri->path;
+ else
+ connection.name = formatv(
+ "[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
+ uri->port.value_or(0));
+
+ if (llvm::Error error = server->Start(connection)) {
result.AppendErrorWithFormatv("{0}", llvm::fmt_consume(std::move(error)));
return;
}
- GetDebugger().AddProtocolServer(server_sp);
-
- if (Socket *socket = server_sp->GetSocket()) {
+ if (Socket *socket = server->GetSocket()) {
std::string address =
llvm::join(socket->GetListeningConnectionURI(), ", ");
result.AppendMessageWithFormatv(
"{0} server started with connection listeners: {1}", protocol,
address);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
}
};
@@ -134,30 +117,18 @@ protected:
}
llvm::StringRef protocol = args.GetArgumentAtIndex(0);
- std::vector<llvm::StringRef> supported_protocols = GetSupportedProtocols();
- if (llvm::find(supported_protocols, protocol) ==
- supported_protocols.end()) {
+ ProtocolServer *server = ProtocolServer::GetOrCreate(protocol);
+ if (!server) {
result.AppendErrorWithFormatv(
"unsupported protocol: {0}. Supported protocols are: {1}", protocol,
- llvm::join(GetSupportedProtocols(), ", "));
- return;
- }
-
- Debugger &debugger = GetDebugger();
-
- ProtocolServerSP server_sp = debugger.GetProtocolServer(protocol);
- if (!server_sp) {
- result.AppendError(
- llvm::formatv("no {0} protocol server running", protocol).str());
+ llvm::join(ProtocolServer::GetSupportedProtocols(), ", "));
return;
}
- if (llvm::Error error = server_sp->Stop()) {
+ if (llvm::Error error = server->Stop()) {
result.AppendErrorWithFormatv("{0}", llvm::fmt_consume(std::move(error)));
return;
}
-
- debugger.RemoveProtocolServer(server_sp);
}
};