Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/lldb/source/Core/ProtocolServer.cpp
213764 views
1
//===-- ProtocolServer.cpp ------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Core/ProtocolServer.h"
10
#include "lldb/Core/PluginManager.h"
11
12
using namespace lldb_private;
13
using namespace lldb;
14
15
ProtocolServer *ProtocolServer::GetOrCreate(llvm::StringRef name) {
16
static std::mutex g_mutex;
17
static llvm::StringMap<ProtocolServerUP> g_protocol_server_instances;
18
19
std::lock_guard<std::mutex> guard(g_mutex);
20
21
auto it = g_protocol_server_instances.find(name);
22
if (it != g_protocol_server_instances.end())
23
return it->second.get();
24
25
if (ProtocolServerCreateInstance create_callback =
26
PluginManager::GetProtocolCreateCallbackForPluginName(name)) {
27
auto pair =
28
g_protocol_server_instances.try_emplace(name, create_callback());
29
return pair.first->second.get();
30
}
31
32
return nullptr;
33
}
34
35
std::vector<llvm::StringRef> ProtocolServer::GetSupportedProtocols() {
36
std::vector<llvm::StringRef> supported_protocols;
37
size_t i = 0;
38
39
for (llvm::StringRef protocol_name =
40
PluginManager::GetProtocolServerPluginNameAtIndex(i++);
41
!protocol_name.empty();
42
protocol_name = PluginManager::GetProtocolServerPluginNameAtIndex(i++)) {
43
supported_protocols.push_back(protocol_name);
44
}
45
46
return supported_protocols;
47
}
48
49