LLDB mainline
ProtocolServer.cpp
Go to the documentation of this file.
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
11#include "llvm/Support/Error.h"
12
13using namespace lldb_private;
14using namespace lldb;
15
16static std::pair<llvm::StringMap<ProtocolServerUP> &, std::mutex &> Servers() {
17 static llvm::StringMap<ProtocolServerUP> g_protocol_server_instances;
18 static std::mutex g_mutex;
19 return {g_protocol_server_instances, g_mutex};
20}
21
23 auto [protocol_server_instances, mutex] = Servers();
24
25 std::lock_guard<std::mutex> guard(mutex);
26
27 auto it = protocol_server_instances.find(name);
28 if (it != protocol_server_instances.end())
29 return it->second.get();
30
31 if (ProtocolServerCreateInstance create_callback =
33 auto pair = protocol_server_instances.try_emplace(name, create_callback());
34 return pair.first->second.get();
35 }
36
37 return nullptr;
38}
39
40std::vector<llvm::StringRef> ProtocolServer::GetSupportedProtocols() {
41 std::vector<llvm::StringRef> supported_protocols;
42 size_t i = 0;
43
44 for (llvm::StringRef protocol_name =
46 !protocol_name.empty();
48 supported_protocols.push_back(protocol_name);
49 }
50
51 return supported_protocols;
52}
53
55 llvm::Error error = llvm::Error::success();
56
57 auto [protocol_server_instances, mutex] = Servers();
58 std::lock_guard<std::mutex> guard(mutex);
59 for (auto &instance : protocol_server_instances) {
60 if (llvm::Error instance_error = instance.second->Stop())
61 error = llvm::joinErrors(std::move(error), std::move(instance_error));
62 }
63
64 protocol_server_instances.clear();
65
66 return error;
67}
static llvm::raw_ostream & error(Stream &strm)
static std::pair< llvm::StringMap< ProtocolServerUP > &, std::mutex & > Servers()
static llvm::StringRef GetProtocolServerPluginNameAtIndex(uint32_t idx)
static ProtocolServerCreateInstance GetProtocolCreateCallbackForPluginName(llvm::StringRef name)
static std::vector< llvm::StringRef > GetSupportedProtocols()
static llvm::Error Terminate()
static ProtocolServer * GetOrCreate(llvm::StringRef name)
A class that represents a running process on the host machine.
lldb::ProtocolServerUP(* ProtocolServerCreateInstance)()
Definition: SBAddress.h:15