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