@@ -24,20 +24,6 @@ using namespace lldb_private;
24
24
#define LLDB_OPTIONS_mcp
25
25
#include " CommandOptions.inc"
26
26
27
- static std::vector<llvm::StringRef> GetSupportedProtocols () {
28
- std::vector<llvm::StringRef> supported_protocols;
29
- size_t i = 0 ;
30
-
31
- for (llvm::StringRef protocol_name =
32
- PluginManager::GetProtocolServerPluginNameAtIndex (i++);
33
- !protocol_name.empty ();
34
- protocol_name = PluginManager::GetProtocolServerPluginNameAtIndex (i++)) {
35
- supported_protocols.push_back (protocol_name);
36
- }
37
-
38
- return supported_protocols;
39
- }
40
-
41
27
class CommandObjectProtocolServerStart : public CommandObjectParsed {
42
28
public:
43
29
CommandObjectProtocolServerStart (CommandInterpreter &interpreter)
@@ -58,12 +44,11 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed {
58
44
}
59
45
60
46
llvm::StringRef protocol = args.GetArgumentAtIndex (0 );
61
- std::vector<llvm::StringRef> supported_protocols = GetSupportedProtocols ();
62
- if (llvm::find (supported_protocols, protocol) ==
63
- supported_protocols.end ()) {
47
+ ProtocolServer *server = ProtocolServer::GetOrCreate (protocol);
48
+ if (!server) {
64
49
result.AppendErrorWithFormatv (
65
50
" unsupported protocol: {0}. Supported protocols are: {1}" , protocol,
66
- llvm::join (GetSupportedProtocols (), " , " ));
51
+ llvm::join (ProtocolServer:: GetSupportedProtocols (), " , " ));
67
52
return ;
68
53
}
69
54
@@ -73,10 +58,6 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed {
73
58
}
74
59
llvm::StringRef connection_uri = args.GetArgumentAtIndex (1 );
75
60
76
- ProtocolServerSP server_sp = GetDebugger ().GetProtocolServer (protocol);
77
- if (!server_sp)
78
- server_sp = ProtocolServer::Create (protocol, GetDebugger ());
79
-
80
61
const char *connection_error =
81
62
" unsupported connection specifier, expected 'accept:///path' or "
82
63
" 'listen://[host]:port', got '{0}'." ;
@@ -99,14 +80,12 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed {
99
80
formatv (" [{0}]:{1}" , uri->hostname .empty () ? " 0.0.0.0" : uri->hostname ,
100
81
uri->port .value_or (0 ));
101
82
102
- if (llvm::Error error = server_sp ->Start (connection)) {
83
+ if (llvm::Error error = server ->Start (connection)) {
103
84
result.AppendErrorWithFormatv (" {0}" , llvm::fmt_consume (std::move (error)));
104
85
return ;
105
86
}
106
87
107
- GetDebugger ().AddProtocolServer (server_sp);
108
-
109
- if (Socket *socket = server_sp->GetSocket ()) {
88
+ if (Socket *socket = server->GetSocket ()) {
110
89
std::string address =
111
90
llvm::join (socket->GetListeningConnectionURI (), " , " );
112
91
result.AppendMessageWithFormatv (
@@ -135,30 +114,18 @@ class CommandObjectProtocolServerStop : public CommandObjectParsed {
135
114
}
136
115
137
116
llvm::StringRef protocol = args.GetArgumentAtIndex (0 );
138
- std::vector<llvm::StringRef> supported_protocols = GetSupportedProtocols ();
139
- if (llvm::find (supported_protocols, protocol) ==
140
- supported_protocols.end ()) {
117
+ ProtocolServer *server = ProtocolServer::GetOrCreate (protocol);
118
+ if (!server) {
141
119
result.AppendErrorWithFormatv (
142
120
" unsupported protocol: {0}. Supported protocols are: {1}" , protocol,
143
- llvm::join (GetSupportedProtocols (), " , " ));
121
+ llvm::join (ProtocolServer:: GetSupportedProtocols (), " , " ));
144
122
return ;
145
123
}
146
124
147
- Debugger &debugger = GetDebugger ();
148
-
149
- ProtocolServerSP server_sp = debugger.GetProtocolServer (protocol);
150
- if (!server_sp) {
151
- result.AppendError (
152
- llvm::formatv (" no {0} protocol server running" , protocol).str ());
153
- return ;
154
- }
155
-
156
- if (llvm::Error error = server_sp->Stop ()) {
125
+ if (llvm::Error error = server->Stop ()) {
157
126
result.AppendErrorWithFormatv (" {0}" , llvm::fmt_consume (std::move (error)));
158
127
return ;
159
128
}
160
-
161
- debugger.RemoveProtocolServer (server_sp);
162
129
}
163
130
};
164
131
0 commit comments