blob: 8a03ca1fae0ad55be550bff5e178bc0f49d97885 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- PluginManager.cpp ---------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Core/PluginManager.h"
10
Greg Claytone8cd0c92012-10-19 18:02:49 +000011#include "lldb/Core/Debugger.h"
Jonas Devlieghere35e4c842018-11-01 00:33:27 +000012#include "lldb/Host/FileSystem.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000013#include "lldb/Host/HostInfo.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000014#include "lldb/Interpreter/OptionValueProperties.h"
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000015#include "lldb/Utility/ConstString.h"
Zachary Turner5713a052017-03-22 18:40:07 +000016#include "lldb/Utility/FileSpec.h"
Zachary Turner97206d52017-05-12 04:51:55 +000017#include "lldb/Utility/Status.h"
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000018#include "lldb/Utility/StringList.h"
Zachary Turner2f3df612017-04-06 21:28:29 +000019
Nico Weberb1cb0b792018-04-10 13:33:45 +000020#if defined(_WIN32)
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000021#include "lldb/Host/windows/PosixApi.h"
Zachary Turner2f3df612017-04-06 21:28:29 +000022#endif
23
24#include "llvm/ADT/StringRef.h"
25#include "llvm/Support/DynamicLibrary.h"
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000026#include "llvm/Support/FileSystem.h"
27#include "llvm/Support/raw_ostream.h"
Zachary Turner2f3df612017-04-06 21:28:29 +000028
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000029#include <map>
30#include <memory>
Zachary Turner2f3df612017-04-06 21:28:29 +000031#include <mutex>
32#include <string>
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000033#include <utility>
Zachary Turner2f3df612017-04-06 21:28:29 +000034#include <vector>
35
Jonas Devlieghere672d2c12018-11-11 23:16:43 +000036#include <assert.h>
Zachary Turner2f3df612017-04-06 21:28:29 +000037
38namespace lldb_private {
39class CommandInterpreter;
40}
Greg Clayton4272cc72011-02-02 02:24:04 +000041
42using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043using namespace lldb_private;
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045enum PluginAction {
46 ePluginRegisterInstance,
47 ePluginUnregisterInstance,
48 ePluginGetInstanceAtIndex
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049};
50
Eugene Zelenko89183722016-03-11 21:55:47 +000051typedef bool (*PluginInitCallback)();
52typedef void (*PluginTermCallback)();
Greg Clayton03da4cc2013-04-19 21:31:16 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054struct PluginInfo {
55 PluginInfo() : plugin_init_callback(nullptr), plugin_term_callback(nullptr) {}
Zachary Turner58a559c2014-08-27 20:15:09 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 llvm::sys::DynamicLibrary library;
58 PluginInitCallback plugin_init_callback;
59 PluginTermCallback plugin_term_callback;
Greg Clayton4272cc72011-02-02 02:24:04 +000060};
61
62typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064static std::recursive_mutex &GetPluginMapMutex() {
65 static std::recursive_mutex g_plugin_map_mutex;
66 return g_plugin_map_mutex;
Greg Clayton4272cc72011-02-02 02:24:04 +000067}
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069static PluginTerminateMap &GetPluginMap() {
70 static PluginTerminateMap g_plugin_map;
71 return g_plugin_map;
Greg Clayton4272cc72011-02-02 02:24:04 +000072}
73
Kate Stoneb9c1b512016-09-06 20:57:50 +000074static bool PluginIsLoaded(const FileSpec &plugin_file_spec) {
75 std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
76 PluginTerminateMap &plugin_map = GetPluginMap();
77 return plugin_map.find(plugin_file_spec) != plugin_map.end();
Greg Clayton4272cc72011-02-02 02:24:04 +000078}
79
Kate Stoneb9c1b512016-09-06 20:57:50 +000080static void SetPluginInfo(const FileSpec &plugin_file_spec,
81 const PluginInfo &plugin_info) {
82 std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
83 PluginTerminateMap &plugin_map = GetPluginMap();
84 assert(plugin_map.find(plugin_file_spec) == plugin_map.end());
85 plugin_map[plugin_file_spec] = plugin_info;
David Majnemer5ff02782014-07-22 21:59:22 +000086}
Greg Clayton4272cc72011-02-02 02:24:04 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) {
89 return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
90}
Greg Clayton45319462011-02-08 00:35:34 +000091
Jonas Devlieghere35e4c842018-11-01 00:33:27 +000092static FileSystem::EnumerateDirectoryResult
Zachary Turner7d86ee52017-03-08 17:56:08 +000093LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
Jonas Devlieghere35e4c842018-11-01 00:33:27 +000094 llvm::StringRef path) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 // PluginManager *plugin_manager = (PluginManager *)baton;
Zachary Turner97206d52017-05-12 04:51:55 +000096 Status error;
Greg Clayton4272cc72011-02-02 02:24:04 +000097
Zachary Turner7d86ee52017-03-08 17:56:08 +000098 namespace fs = llvm::sys::fs;
Adrian Prantl05097242018-04-30 16:49:04 +000099 // If we have a regular file, a symbolic link or unknown file type, try and
100 // process the file. We must handle unknown as sometimes the directory
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 // enumeration might be enumerating a file system that doesn't have correct
102 // file type information.
Zachary Turner7d86ee52017-03-08 17:56:08 +0000103 if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
104 ft == fs::file_type::type_unknown) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000105 FileSpec plugin_file_spec(path);
106 FileSystem::Instance().Resolve(plugin_file_spec);
Greg Clayton4272cc72011-02-02 02:24:04 +0000107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 if (PluginIsLoaded(plugin_file_spec))
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000109 return FileSystem::eEnumerateDirectoryResultNext;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 else {
111 PluginInfo plugin_info;
Greg Clayton4272cc72011-02-02 02:24:04 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 std::string pluginLoadError;
114 plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary(
115 plugin_file_spec.GetPath().c_str(), &pluginLoadError);
116 if (plugin_info.library.isValid()) {
117 bool success = false;
118 plugin_info.plugin_init_callback = CastToFPtr<PluginInitCallback>(
119 plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
120 if (plugin_info.plugin_init_callback) {
121 // Call the plug-in "bool LLDBPluginInitialize(void)" function
122 success = plugin_info.plugin_init_callback();
Greg Clayton4272cc72011-02-02 02:24:04 +0000123 }
Greg Clayton4272cc72011-02-02 02:24:04 +0000124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 if (success) {
126 // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
127 plugin_info.plugin_term_callback = CastToFPtr<PluginTermCallback>(
128 plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate"));
129 } else {
130 // The initialize function returned FALSE which means the plug-in
Adrian Prantl05097242018-04-30 16:49:04 +0000131 // might not be compatible, or might be too new or too old, or might
132 // not want to run on this machine. Set it to a default-constructed
133 // instance to invalidate it.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134 plugin_info = PluginInfo();
135 }
136
Adrian Prantl05097242018-04-30 16:49:04 +0000137 // Regardless of success or failure, cache the plug-in load in our
138 // plug-in info so we don't try to load it again and again.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 SetPluginInfo(plugin_file_spec, plugin_info);
140
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000141 return FileSystem::eEnumerateDirectoryResultNext;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142 }
143 }
144 }
145
Zachary Turner7d86ee52017-03-08 17:56:08 +0000146 if (ft == fs::file_type::directory_file ||
147 ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) {
Adrian Prantl05097242018-04-30 16:49:04 +0000148 // Try and recurse into anything that a directory or symbolic link. We must
149 // also do this for unknown as sometimes the directory enumeration might be
150 // enumerating a file system that doesn't have correct file type
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151 // information.
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000152 return FileSystem::eEnumerateDirectoryResultEnter;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 }
154
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000155 return FileSystem::eEnumerateDirectoryResultNext;
Greg Clayton4272cc72011-02-02 02:24:04 +0000156}
157
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158void PluginManager::Initialize() {
Greg Clayton1cb64962011-03-24 04:28:38 +0000159#if 1
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160 const bool find_directories = true;
161 const bool find_files = true;
162 const bool find_other = true;
163 char dir_path[PATH_MAX];
Pavel Labath60f028f2018-06-19 15:09:07 +0000164 if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
Jonas Devliegheredbd7fab2018-11-01 17:09:25 +0000165 if (FileSystem::Instance().Exists(dir_spec) &&
166 dir_spec.GetPath(dir_path, sizeof(dir_path))) {
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000167 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
168 find_files, find_other,
169 LoadPluginCallback, nullptr);
Greg Clayton4272cc72011-02-02 02:24:04 +0000170 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 }
Greg Clayton4272cc72011-02-02 02:24:04 +0000172
Pavel Labath60f028f2018-06-19 15:09:07 +0000173 if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
Jonas Devliegheredbd7fab2018-11-01 17:09:25 +0000174 if (FileSystem::Instance().Exists(dir_spec) &&
175 dir_spec.GetPath(dir_path, sizeof(dir_path))) {
Jonas Devlieghere35e4c842018-11-01 00:33:27 +0000176 FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
177 find_files, find_other,
178 LoadPluginCallback, nullptr);
Greg Clayton4272cc72011-02-02 02:24:04 +0000179 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000181#endif
Greg Clayton4272cc72011-02-02 02:24:04 +0000182}
183
Kate Stoneb9c1b512016-09-06 20:57:50 +0000184void PluginManager::Terminate() {
185 std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
186 PluginTerminateMap &plugin_map = GetPluginMap();
187
188 PluginTerminateMap::const_iterator pos, end = plugin_map.end();
189 for (pos = plugin_map.begin(); pos != end; ++pos) {
Adrian Prantl05097242018-04-30 16:49:04 +0000190 // Call the plug-in "void LLDBPluginTerminate (void)" function if there is
191 // one (if the symbol was not nullptr).
Kate Stoneb9c1b512016-09-06 20:57:50 +0000192 if (pos->second.library.isValid()) {
193 if (pos->second.plugin_term_callback)
194 pos->second.plugin_term_callback();
Greg Clayton4272cc72011-02-02 02:24:04 +0000195 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000196 }
197 plugin_map.clear();
Greg Clayton4272cc72011-02-02 02:24:04 +0000198}
199
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200#pragma mark ABI
201
Kate Stoneb9c1b512016-09-06 20:57:50 +0000202struct ABIInstance {
203 ABIInstance() : name(), description(), create_callback(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204
Kate Stoneb9c1b512016-09-06 20:57:50 +0000205 ConstString name;
206 std::string description;
207 ABICreateInstance create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208};
209
210typedef std::vector<ABIInstance> ABIInstances;
211
Kate Stoneb9c1b512016-09-06 20:57:50 +0000212static std::recursive_mutex &GetABIInstancesMutex() {
213 static std::recursive_mutex g_instances_mutex;
214 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215}
216
Kate Stoneb9c1b512016-09-06 20:57:50 +0000217static ABIInstances &GetABIInstances() {
218 static ABIInstances g_instances;
219 return g_instances;
Greg Claytonded470d2011-03-19 01:12:21 +0000220}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222bool PluginManager::RegisterPlugin(const ConstString &name,
223 const char *description,
224 ABICreateInstance create_callback) {
225 if (create_callback) {
226 ABIInstance instance;
227 assert((bool)name);
228 instance.name = name;
229 if (description && description[0])
230 instance.description = description;
231 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000232 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233 GetABIInstances().push_back(instance);
234 return true;
235 }
236 return false;
237}
238
239bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) {
240 if (create_callback) {
241 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
242 ABIInstances &instances = GetABIInstances();
243
244 ABIInstances::iterator pos, end = instances.end();
245 for (pos = instances.begin(); pos != end; ++pos) {
246 if (pos->create_callback == create_callback) {
247 instances.erase(pos);
248 return true;
249 }
250 }
251 }
252 return false;
253}
254
255ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) {
256 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
257 ABIInstances &instances = GetABIInstances();
258 if (idx < instances.size())
259 return instances[idx].create_callback;
260 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261}
262
263ABICreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000264PluginManager::GetABICreateCallbackForPluginName(const ConstString &name) {
265 if (name) {
266 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
267 ABIInstances &instances = GetABIInstances();
Greg Claytonded470d2011-03-19 01:12:21 +0000268
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269 ABIInstances::iterator pos, end = instances.end();
270 for (pos = instances.begin(); pos != end; ++pos) {
271 if (name == pos->name)
272 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274 }
275 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276}
277
Pavel Labath13e37d42017-10-25 21:05:31 +0000278#pragma mark Architecture
279
280struct ArchitectureInstance {
281 ConstString name;
282 std::string description;
283 PluginManager::ArchitectureCreateInstance create_callback;
284};
285
286typedef std::vector<ArchitectureInstance> ArchitectureInstances;
287
Kuba Mracekb2413ea2018-11-12 16:52:58 +0000288static std::mutex &GetArchitectureMutex() {
289 static std::mutex g_architecture_mutex;
290 return g_architecture_mutex;
291}
Pavel Labath13e37d42017-10-25 21:05:31 +0000292
293static ArchitectureInstances &GetArchitectureInstances() {
294 static ArchitectureInstances g_instances;
295 return g_instances;
296}
297
298void PluginManager::RegisterPlugin(const ConstString &name,
299 llvm::StringRef description,
300 ArchitectureCreateInstance create_callback) {
Kuba Mracekb2413ea2018-11-12 16:52:58 +0000301 std::lock_guard<std::mutex> guard(GetArchitectureMutex());
Pavel Labath13e37d42017-10-25 21:05:31 +0000302 GetArchitectureInstances().push_back({name, description, create_callback});
303}
304
305void PluginManager::UnregisterPlugin(
306 ArchitectureCreateInstance create_callback) {
Kuba Mracekb2413ea2018-11-12 16:52:58 +0000307 std::lock_guard<std::mutex> guard(GetArchitectureMutex());
Pavel Labath13e37d42017-10-25 21:05:31 +0000308 auto &instances = GetArchitectureInstances();
309
310 for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) {
311 if (pos->create_callback == create_callback) {
312 instances.erase(pos);
313 return;
314 }
315 }
316 llvm_unreachable("Plugin not found");
317}
318
319std::unique_ptr<Architecture>
320PluginManager::CreateArchitectureInstance(const ArchSpec &arch) {
Kuba Mracekb2413ea2018-11-12 16:52:58 +0000321 std::lock_guard<std::mutex> guard(GetArchitectureMutex());
Pavel Labath13e37d42017-10-25 21:05:31 +0000322 for (const auto &instances : GetArchitectureInstances()) {
323 if (auto plugin_up = instances.create_callback(arch))
324 return plugin_up;
325 }
326 return nullptr;
327}
328
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329#pragma mark Disassembler
330
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331struct DisassemblerInstance {
332 DisassemblerInstance() : name(), description(), create_callback(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 ConstString name;
335 std::string description;
336 DisassemblerCreateInstance create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337};
338
339typedef std::vector<DisassemblerInstance> DisassemblerInstances;
340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341static std::recursive_mutex &GetDisassemblerMutex() {
342 static std::recursive_mutex g_instances_mutex;
343 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344}
345
Kate Stoneb9c1b512016-09-06 20:57:50 +0000346static DisassemblerInstances &GetDisassemblerInstances() {
347 static DisassemblerInstances g_instances;
348 return g_instances;
Greg Claytonab65b342011-04-13 22:47:15 +0000349}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351bool PluginManager::RegisterPlugin(const ConstString &name,
352 const char *description,
353 DisassemblerCreateInstance create_callback) {
354 if (create_callback) {
355 DisassemblerInstance instance;
356 assert((bool)name);
357 instance.name = name;
358 if (description && description[0])
359 instance.description = description;
360 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000361 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000362 GetDisassemblerInstances().push_back(instance);
363 return true;
364 }
365 return false;
366}
367
368bool PluginManager::UnregisterPlugin(
369 DisassemblerCreateInstance create_callback) {
370 if (create_callback) {
371 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
372 DisassemblerInstances &instances = GetDisassemblerInstances();
373
374 DisassemblerInstances::iterator pos, end = instances.end();
375 for (pos = instances.begin(); pos != end; ++pos) {
376 if (pos->create_callback == create_callback) {
377 instances.erase(pos);
378 return true;
379 }
380 }
381 }
382 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383}
384
385DisassemblerCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) {
387 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
388 DisassemblerInstances &instances = GetDisassemblerInstances();
389 if (idx < instances.size())
390 return instances[idx].create_callback;
391 return nullptr;
392}
393
394DisassemblerCreateInstance
395PluginManager::GetDisassemblerCreateCallbackForPluginName(
396 const ConstString &name) {
397 if (name) {
398 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
399 DisassemblerInstances &instances = GetDisassemblerInstances();
400
401 DisassemblerInstances::iterator pos, end = instances.end();
402 for (pos = instances.begin(); pos != end; ++pos) {
403 if (name == pos->name)
404 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406 }
407 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408}
409
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410#pragma mark DynamicLoader
411
Kate Stoneb9c1b512016-09-06 20:57:50 +0000412struct DynamicLoaderInstance {
413 DynamicLoaderInstance()
414 : name(), description(), create_callback(nullptr),
415 debugger_init_callback(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416
Kate Stoneb9c1b512016-09-06 20:57:50 +0000417 ConstString name;
418 std::string description;
419 DynamicLoaderCreateInstance create_callback;
420 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421};
422
423typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances;
424
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425static std::recursive_mutex &GetDynamicLoaderMutex() {
426 static std::recursive_mutex g_instances_mutex;
427 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +0000428}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430static DynamicLoaderInstances &GetDynamicLoaderInstances() {
431 static DynamicLoaderInstances g_instances;
432 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433}
434
Kate Stoneb9c1b512016-09-06 20:57:50 +0000435bool PluginManager::RegisterPlugin(
436 const ConstString &name, const char *description,
437 DynamicLoaderCreateInstance create_callback,
438 DebuggerInitializeCallback debugger_init_callback) {
439 if (create_callback) {
440 DynamicLoaderInstance instance;
441 assert((bool)name);
442 instance.name = name;
443 if (description && description[0])
444 instance.description = description;
445 instance.create_callback = create_callback;
446 instance.debugger_init_callback = debugger_init_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000447 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000448 GetDynamicLoaderInstances().push_back(instance);
449 }
450 return false;
451}
452
453bool PluginManager::UnregisterPlugin(
454 DynamicLoaderCreateInstance create_callback) {
455 if (create_callback) {
456 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
457 DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
458
459 DynamicLoaderInstances::iterator pos, end = instances.end();
460 for (pos = instances.begin(); pos != end; ++pos) {
461 if (pos->create_callback == create_callback) {
462 instances.erase(pos);
463 return true;
464 }
465 }
466 }
467 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468}
469
470DynamicLoaderCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000471PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) {
472 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
473 DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
474 if (idx < instances.size())
475 return instances[idx].create_callback;
476 return nullptr;
477}
478
479DynamicLoaderCreateInstance
480PluginManager::GetDynamicLoaderCreateCallbackForPluginName(
481 const ConstString &name) {
482 if (name) {
483 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
484 DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
485
486 DynamicLoaderInstances::iterator pos, end = instances.end();
487 for (pos = instances.begin(); pos != end; ++pos) {
488 if (name == pos->name)
489 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000491 }
492 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
Andrew MacPherson17220c12014-03-05 10:12:43 +0000495#pragma mark JITLoader
496
Kate Stoneb9c1b512016-09-06 20:57:50 +0000497struct JITLoaderInstance {
498 JITLoaderInstance()
499 : name(), description(), create_callback(nullptr),
500 debugger_init_callback(nullptr) {}
Andrew MacPherson17220c12014-03-05 10:12:43 +0000501
Kate Stoneb9c1b512016-09-06 20:57:50 +0000502 ConstString name;
503 std::string description;
504 JITLoaderCreateInstance create_callback;
505 DebuggerInitializeCallback debugger_init_callback;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000506};
507
508typedef std::vector<JITLoaderInstance> JITLoaderInstances;
509
Kate Stoneb9c1b512016-09-06 20:57:50 +0000510static std::recursive_mutex &GetJITLoaderMutex() {
511 static std::recursive_mutex g_instances_mutex;
512 return g_instances_mutex;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000513}
514
Kate Stoneb9c1b512016-09-06 20:57:50 +0000515static JITLoaderInstances &GetJITLoaderInstances() {
516 static JITLoaderInstances g_instances;
517 return g_instances;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000518}
519
Kate Stoneb9c1b512016-09-06 20:57:50 +0000520bool PluginManager::RegisterPlugin(
521 const ConstString &name, const char *description,
522 JITLoaderCreateInstance create_callback,
523 DebuggerInitializeCallback debugger_init_callback) {
524 if (create_callback) {
525 JITLoaderInstance instance;
526 assert((bool)name);
527 instance.name = name;
528 if (description && description[0])
529 instance.description = description;
530 instance.create_callback = create_callback;
531 instance.debugger_init_callback = debugger_init_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000532 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000533 GetJITLoaderInstances().push_back(instance);
534 }
535 return false;
536}
537
538bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) {
539 if (create_callback) {
540 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
541 JITLoaderInstances &instances = GetJITLoaderInstances();
542
543 JITLoaderInstances::iterator pos, end = instances.end();
544 for (pos = instances.begin(); pos != end; ++pos) {
545 if (pos->create_callback == create_callback) {
546 instances.erase(pos);
547 return true;
548 }
549 }
550 }
551 return false;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000552}
553
554JITLoaderCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000555PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) {
556 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
557 JITLoaderInstances &instances = GetJITLoaderInstances();
558 if (idx < instances.size())
559 return instances[idx].create_callback;
560 return nullptr;
561}
562
563JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackForPluginName(
564 const ConstString &name) {
565 if (name) {
566 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
567 JITLoaderInstances &instances = GetJITLoaderInstances();
568
569 JITLoaderInstances::iterator pos, end = instances.end();
570 for (pos = instances.begin(); pos != end; ++pos) {
571 if (name == pos->name)
572 return pos->create_callback;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000573 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000574 }
575 return nullptr;
Andrew MacPherson17220c12014-03-05 10:12:43 +0000576}
577
Greg Claytonf03bbe22011-02-01 01:37:45 +0000578#pragma mark EmulateInstruction
579
Kate Stoneb9c1b512016-09-06 20:57:50 +0000580struct EmulateInstructionInstance {
581 EmulateInstructionInstance()
582 : name(), description(), create_callback(nullptr) {}
583
584 ConstString name;
585 std::string description;
586 EmulateInstructionCreateInstance create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000587};
588
589typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances;
590
Kate Stoneb9c1b512016-09-06 20:57:50 +0000591static std::recursive_mutex &GetEmulateInstructionMutex() {
592 static std::recursive_mutex g_instances_mutex;
593 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +0000594}
595
Kate Stoneb9c1b512016-09-06 20:57:50 +0000596static EmulateInstructionInstances &GetEmulateInstructionInstances() {
597 static EmulateInstructionInstances g_instances;
598 return g_instances;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000599}
600
Kate Stoneb9c1b512016-09-06 20:57:50 +0000601bool PluginManager::RegisterPlugin(
602 const ConstString &name, const char *description,
603 EmulateInstructionCreateInstance create_callback) {
604 if (create_callback) {
605 EmulateInstructionInstance instance;
606 assert((bool)name);
607 instance.name = name;
608 if (description && description[0])
609 instance.description = description;
610 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000611 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000612 GetEmulateInstructionInstances().push_back(instance);
613 }
614 return false;
615}
616
617bool PluginManager::UnregisterPlugin(
618 EmulateInstructionCreateInstance create_callback) {
619 if (create_callback) {
620 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
621 EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
622
623 EmulateInstructionInstances::iterator pos, end = instances.end();
624 for (pos = instances.begin(); pos != end; ++pos) {
625 if (pos->create_callback == create_callback) {
626 instances.erase(pos);
627 return true;
628 }
629 }
630 }
631 return false;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000632}
633
634EmulateInstructionCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000635PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) {
636 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
637 EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
638 if (idx < instances.size())
639 return instances[idx].create_callback;
640 return nullptr;
641}
642
643EmulateInstructionCreateInstance
644PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
645 const ConstString &name) {
646 if (name) {
647 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
648 EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
649
650 EmulateInstructionInstances::iterator pos, end = instances.end();
651 for (pos = instances.begin(); pos != end; ++pos) {
652 if (name == pos->name)
653 return pos->create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000654 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000655 }
656 return nullptr;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000657}
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000658
Eugene Zelenko89183722016-03-11 21:55:47 +0000659#pragma mark OperatingSystem
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000660
Kate Stoneb9c1b512016-09-06 20:57:50 +0000661struct OperatingSystemInstance {
662 OperatingSystemInstance()
663 : name(), description(), create_callback(nullptr),
664 debugger_init_callback(nullptr) {}
665
666 ConstString name;
667 std::string description;
668 OperatingSystemCreateInstance create_callback;
669 DebuggerInitializeCallback debugger_init_callback;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000670};
671
672typedef std::vector<OperatingSystemInstance> OperatingSystemInstances;
673
Kate Stoneb9c1b512016-09-06 20:57:50 +0000674static std::recursive_mutex &GetOperatingSystemMutex() {
675 static std::recursive_mutex g_instances_mutex;
676 return g_instances_mutex;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000677}
678
Kate Stoneb9c1b512016-09-06 20:57:50 +0000679static OperatingSystemInstances &GetOperatingSystemInstances() {
680 static OperatingSystemInstances g_instances;
681 return g_instances;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000682}
683
Kate Stoneb9c1b512016-09-06 20:57:50 +0000684bool PluginManager::RegisterPlugin(
685 const ConstString &name, const char *description,
686 OperatingSystemCreateInstance create_callback,
687 DebuggerInitializeCallback debugger_init_callback) {
688 if (create_callback) {
689 OperatingSystemInstance instance;
690 assert((bool)name);
691 instance.name = name;
692 if (description && description[0])
693 instance.description = description;
694 instance.create_callback = create_callback;
695 instance.debugger_init_callback = debugger_init_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000696 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000697 GetOperatingSystemInstances().push_back(instance);
698 }
699 return false;
700}
701
702bool PluginManager::UnregisterPlugin(
703 OperatingSystemCreateInstance create_callback) {
704 if (create_callback) {
705 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
706 OperatingSystemInstances &instances = GetOperatingSystemInstances();
707
708 OperatingSystemInstances::iterator pos, end = instances.end();
709 for (pos = instances.begin(); pos != end; ++pos) {
710 if (pos->create_callback == create_callback) {
711 instances.erase(pos);
712 return true;
713 }
714 }
715 }
716 return false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000717}
718
719OperatingSystemCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000720PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
721 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
722 OperatingSystemInstances &instances = GetOperatingSystemInstances();
723 if (idx < instances.size())
724 return instances[idx].create_callback;
725 return nullptr;
726}
727
728OperatingSystemCreateInstance
729PluginManager::GetOperatingSystemCreateCallbackForPluginName(
730 const ConstString &name) {
731 if (name) {
732 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
733 OperatingSystemInstances &instances = GetOperatingSystemInstances();
734
735 OperatingSystemInstances::iterator pos, end = instances.end();
736 for (pos = instances.begin(); pos != end; ++pos) {
737 if (name == pos->name)
738 return pos->create_callback;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000739 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000740 }
741 return nullptr;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000742}
Greg Claytonf03bbe22011-02-01 01:37:45 +0000743
Enrico Granata5f9d3102015-08-27 21:33:50 +0000744#pragma mark Language
745
Kate Stoneb9c1b512016-09-06 20:57:50 +0000746struct LanguageInstance {
747 LanguageInstance() : name(), description(), create_callback(nullptr) {}
748
749 ConstString name;
750 std::string description;
751 LanguageCreateInstance create_callback;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000752};
753
754typedef std::vector<LanguageInstance> LanguageInstances;
755
Kate Stoneb9c1b512016-09-06 20:57:50 +0000756static std::recursive_mutex &GetLanguageMutex() {
757 static std::recursive_mutex g_instances_mutex;
758 return g_instances_mutex;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000759}
760
Kate Stoneb9c1b512016-09-06 20:57:50 +0000761static LanguageInstances &GetLanguageInstances() {
762 static LanguageInstances g_instances;
763 return g_instances;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000764}
765
Kate Stoneb9c1b512016-09-06 20:57:50 +0000766bool PluginManager::RegisterPlugin(const ConstString &name,
767 const char *description,
768 LanguageCreateInstance create_callback) {
769 if (create_callback) {
770 LanguageInstance instance;
771 assert((bool)name);
772 instance.name = name;
773 if (description && description[0])
774 instance.description = description;
775 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000776 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000777 GetLanguageInstances().push_back(instance);
778 }
779 return false;
780}
781
782bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
783 if (create_callback) {
784 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
785 LanguageInstances &instances = GetLanguageInstances();
786
787 LanguageInstances::iterator pos, end = instances.end();
788 for (pos = instances.begin(); pos != end; ++pos) {
789 if (pos->create_callback == create_callback) {
790 instances.erase(pos);
791 return true;
792 }
793 }
794 }
795 return false;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000796}
797
798LanguageCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000799PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) {
800 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
801 LanguageInstances &instances = GetLanguageInstances();
802 if (idx < instances.size())
803 return instances[idx].create_callback;
804 return nullptr;
805}
806
807LanguageCreateInstance
808PluginManager::GetLanguageCreateCallbackForPluginName(const ConstString &name) {
809 if (name) {
810 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
811 LanguageInstances &instances = GetLanguageInstances();
812
813 LanguageInstances::iterator pos, end = instances.end();
814 for (pos = instances.begin(); pos != end; ++pos) {
815 if (name == pos->name)
816 return pos->create_callback;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000817 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000818 }
819 return nullptr;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000820}
821
Jim Ingham22777012010-09-23 02:01:19 +0000822#pragma mark LanguageRuntime
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823
Kate Stoneb9c1b512016-09-06 20:57:50 +0000824struct LanguageRuntimeInstance {
825 LanguageRuntimeInstance() : name(), description(), create_callback(nullptr) {}
Jim Ingham22777012010-09-23 02:01:19 +0000826
Kate Stoneb9c1b512016-09-06 20:57:50 +0000827 ConstString name;
828 std::string description;
829 LanguageRuntimeCreateInstance create_callback;
830 LanguageRuntimeGetCommandObject command_callback;
Jim Ingham22777012010-09-23 02:01:19 +0000831};
832
833typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances;
834
Kate Stoneb9c1b512016-09-06 20:57:50 +0000835static std::recursive_mutex &GetLanguageRuntimeMutex() {
836 static std::recursive_mutex g_instances_mutex;
837 return g_instances_mutex;
Jim Ingham22777012010-09-23 02:01:19 +0000838}
839
Kate Stoneb9c1b512016-09-06 20:57:50 +0000840static LanguageRuntimeInstances &GetLanguageRuntimeInstances() {
841 static LanguageRuntimeInstances g_instances;
842 return g_instances;
Greg Claytonab65b342011-04-13 22:47:15 +0000843}
Jim Ingham22777012010-09-23 02:01:19 +0000844
Kate Stoneb9c1b512016-09-06 20:57:50 +0000845bool PluginManager::RegisterPlugin(
846 const ConstString &name, const char *description,
847 LanguageRuntimeCreateInstance create_callback,
848 LanguageRuntimeGetCommandObject command_callback) {
849 if (create_callback) {
850 LanguageRuntimeInstance instance;
851 assert((bool)name);
852 instance.name = name;
853 if (description && description[0])
854 instance.description = description;
855 instance.create_callback = create_callback;
856 instance.command_callback = command_callback;
857 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
858 GetLanguageRuntimeInstances().push_back(instance);
859 }
860 return false;
861}
862
863bool PluginManager::UnregisterPlugin(
864 LanguageRuntimeCreateInstance create_callback) {
865 if (create_callback) {
866 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
867 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
868
869 LanguageRuntimeInstances::iterator pos, end = instances.end();
870 for (pos = instances.begin(); pos != end; ++pos) {
871 if (pos->create_callback == create_callback) {
872 instances.erase(pos);
873 return true;
874 }
Jim Ingham22777012010-09-23 02:01:19 +0000875 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000876 }
877 return false;
Jim Ingham22777012010-09-23 02:01:19 +0000878}
879
880LanguageRuntimeCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000881PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
882 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
883 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
884 if (idx < instances.size())
885 return instances[idx].create_callback;
886 return nullptr;
Jim Ingham22777012010-09-23 02:01:19 +0000887}
888
Colin Rileyc9c55a22015-05-04 18:39:38 +0000889LanguageRuntimeGetCommandObject
Kate Stoneb9c1b512016-09-06 20:57:50 +0000890PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
891 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
892 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
893 if (idx < instances.size())
894 return instances[idx].command_callback;
895 return nullptr;
Colin Rileyc9c55a22015-05-04 18:39:38 +0000896}
897
Jim Ingham22777012010-09-23 02:01:19 +0000898LanguageRuntimeCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000899PluginManager::GetLanguageRuntimeCreateCallbackForPluginName(
900 const ConstString &name) {
901 if (name) {
902 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
903 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
904
905 LanguageRuntimeInstances::iterator pos, end = instances.end();
906 for (pos = instances.begin(); pos != end; ++pos) {
907 if (name == pos->name)
908 return pos->create_callback;
Jim Ingham22777012010-09-23 02:01:19 +0000909 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000910 }
911 return nullptr;
Jim Ingham22777012010-09-23 02:01:19 +0000912}
913
Jason Molendaeef51062013-11-05 03:57:19 +0000914#pragma mark SystemRuntime
915
Kate Stoneb9c1b512016-09-06 20:57:50 +0000916struct SystemRuntimeInstance {
917 SystemRuntimeInstance() : name(), description(), create_callback(nullptr) {}
Jason Molendaeef51062013-11-05 03:57:19 +0000918
Kate Stoneb9c1b512016-09-06 20:57:50 +0000919 ConstString name;
920 std::string description;
921 SystemRuntimeCreateInstance create_callback;
Jason Molendaeef51062013-11-05 03:57:19 +0000922};
923
924typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances;
925
Kate Stoneb9c1b512016-09-06 20:57:50 +0000926static std::recursive_mutex &GetSystemRuntimeMutex() {
927 static std::recursive_mutex g_instances_mutex;
928 return g_instances_mutex;
Jason Molendaeef51062013-11-05 03:57:19 +0000929}
930
Kate Stoneb9c1b512016-09-06 20:57:50 +0000931static SystemRuntimeInstances &GetSystemRuntimeInstances() {
932 static SystemRuntimeInstances g_instances;
933 return g_instances;
Jason Molendaeef51062013-11-05 03:57:19 +0000934}
935
Kate Stoneb9c1b512016-09-06 20:57:50 +0000936bool PluginManager::RegisterPlugin(
937 const ConstString &name, const char *description,
938 SystemRuntimeCreateInstance create_callback) {
939 if (create_callback) {
940 SystemRuntimeInstance instance;
941 assert((bool)name);
942 instance.name = name;
943 if (description && description[0])
944 instance.description = description;
945 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000946 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000947 GetSystemRuntimeInstances().push_back(instance);
948 }
949 return false;
950}
951
952bool PluginManager::UnregisterPlugin(
953 SystemRuntimeCreateInstance create_callback) {
954 if (create_callback) {
955 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
956 SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
957
958 SystemRuntimeInstances::iterator pos, end = instances.end();
959 for (pos = instances.begin(); pos != end; ++pos) {
960 if (pos->create_callback == create_callback) {
961 instances.erase(pos);
962 return true;
963 }
964 }
965 }
966 return false;
Jason Molendaeef51062013-11-05 03:57:19 +0000967}
968
969SystemRuntimeCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +0000970PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) {
971 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
972 SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
973 if (idx < instances.size())
974 return instances[idx].create_callback;
975 return nullptr;
976}
977
978SystemRuntimeCreateInstance
979PluginManager::GetSystemRuntimeCreateCallbackForPluginName(
980 const ConstString &name) {
981 if (name) {
982 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
983 SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
984
985 SystemRuntimeInstances::iterator pos, end = instances.end();
986 for (pos = instances.begin(); pos != end; ++pos) {
987 if (name == pos->name)
988 return pos->create_callback;
Jason Molendaeef51062013-11-05 03:57:19 +0000989 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000990 }
991 return nullptr;
Jason Molendaeef51062013-11-05 03:57:19 +0000992}
993
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000994#pragma mark ObjectFile
995
Kate Stoneb9c1b512016-09-06 20:57:50 +0000996struct ObjectFileInstance {
997 ObjectFileInstance()
998 : name(), description(), create_callback(nullptr),
999 create_memory_callback(nullptr), get_module_specifications(nullptr),
1000 save_core(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001
Kate Stoneb9c1b512016-09-06 20:57:50 +00001002 ConstString name;
1003 std::string description;
1004 ObjectFileCreateInstance create_callback;
1005 ObjectFileCreateMemoryInstance create_memory_callback;
1006 ObjectFileGetModuleSpecifications get_module_specifications;
1007 ObjectFileSaveCore save_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001008};
1009
1010typedef std::vector<ObjectFileInstance> ObjectFileInstances;
1011
Kate Stoneb9c1b512016-09-06 20:57:50 +00001012static std::recursive_mutex &GetObjectFileMutex() {
1013 static std::recursive_mutex g_instances_mutex;
1014 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +00001015}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016
Kate Stoneb9c1b512016-09-06 20:57:50 +00001017static ObjectFileInstances &GetObjectFileInstances() {
1018 static ObjectFileInstances g_instances;
1019 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020}
1021
Kate Stoneb9c1b512016-09-06 20:57:50 +00001022bool PluginManager::RegisterPlugin(
1023 const ConstString &name, const char *description,
1024 ObjectFileCreateInstance create_callback,
1025 ObjectFileCreateMemoryInstance create_memory_callback,
1026 ObjectFileGetModuleSpecifications get_module_specifications,
1027 ObjectFileSaveCore save_core) {
1028 if (create_callback) {
1029 ObjectFileInstance instance;
1030 assert((bool)name);
1031 instance.name = name;
1032 if (description && description[0])
1033 instance.description = description;
1034 instance.create_callback = create_callback;
1035 instance.create_memory_callback = create_memory_callback;
1036 instance.save_core = save_core;
1037 instance.get_module_specifications = get_module_specifications;
1038 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1039 GetObjectFileInstances().push_back(instance);
1040 }
1041 return false;
1042}
1043
1044bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
1045 if (create_callback) {
1046 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1047 ObjectFileInstances &instances = GetObjectFileInstances();
1048
1049 ObjectFileInstances::iterator pos, end = instances.end();
1050 for (pos = instances.begin(); pos != end; ++pos) {
1051 if (pos->create_callback == create_callback) {
1052 instances.erase(pos);
1053 return true;
1054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001056 }
1057 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001058}
1059
1060ObjectFileCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001061PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
1062 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1063 ObjectFileInstances &instances = GetObjectFileInstances();
1064 if (idx < instances.size())
1065 return instances[idx].create_callback;
1066 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001067}
Greg Claytonab65b342011-04-13 22:47:15 +00001068
Greg Claytonc9660542012-02-05 02:38:54 +00001069ObjectFileCreateMemoryInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001070PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) {
1071 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1072 ObjectFileInstances &instances = GetObjectFileInstances();
1073 if (idx < instances.size())
1074 return instances[idx].create_memory_callback;
1075 return nullptr;
Greg Claytonc9660542012-02-05 02:38:54 +00001076}
1077
Greg Claytonf4d6de62013-04-24 22:29:28 +00001078ObjectFileGetModuleSpecifications
Kate Stoneb9c1b512016-09-06 20:57:50 +00001079PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
1080 uint32_t idx) {
1081 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1082 ObjectFileInstances &instances = GetObjectFileInstances();
1083 if (idx < instances.size())
1084 return instances[idx].get_module_specifications;
1085 return nullptr;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001086}
1087
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088ObjectFileCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001089PluginManager::GetObjectFileCreateCallbackForPluginName(
1090 const ConstString &name) {
1091 if (name) {
1092 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1093 ObjectFileInstances &instances = GetObjectFileInstances();
1094
1095 ObjectFileInstances::iterator pos, end = instances.end();
1096 for (pos = instances.begin(); pos != end; ++pos) {
1097 if (name == pos->name)
1098 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001100 }
1101 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102}
1103
Greg Claytonc9660542012-02-05 02:38:54 +00001104ObjectFileCreateMemoryInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001105PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
1106 const ConstString &name) {
1107 if (name) {
1108 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1109 ObjectFileInstances &instances = GetObjectFileInstances();
1110
1111 ObjectFileInstances::iterator pos, end = instances.end();
1112 for (pos = instances.begin(); pos != end; ++pos) {
1113 if (name == pos->name)
1114 return pos->create_memory_callback;
Greg Claytonc9660542012-02-05 02:38:54 +00001115 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001116 }
1117 return nullptr;
Greg Claytonc9660542012-02-05 02:38:54 +00001118}
1119
Zachary Turner97206d52017-05-12 04:51:55 +00001120Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
1121 const FileSpec &outfile) {
1122 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001123 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
1124 ObjectFileInstances &instances = GetObjectFileInstances();
1125
1126 ObjectFileInstances::iterator pos, end = instances.end();
1127 for (pos = instances.begin(); pos != end; ++pos) {
1128 if (pos->save_core && pos->save_core(process_sp, outfile, error))
1129 return error;
1130 }
1131 error.SetErrorString(
1132 "no ObjectFile plugins were able to save a core for this process");
1133 return error;
Greg Claytona2715cf2014-06-13 00:54:12 +00001134}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135
1136#pragma mark ObjectContainer
1137
Kate Stoneb9c1b512016-09-06 20:57:50 +00001138struct ObjectContainerInstance {
1139 ObjectContainerInstance()
1140 : name(), description(), create_callback(nullptr),
1141 get_module_specifications(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142
Kate Stoneb9c1b512016-09-06 20:57:50 +00001143 ConstString name;
1144 std::string description;
1145 ObjectContainerCreateInstance create_callback;
1146 ObjectFileGetModuleSpecifications get_module_specifications;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147};
1148
1149typedef std::vector<ObjectContainerInstance> ObjectContainerInstances;
1150
Kate Stoneb9c1b512016-09-06 20:57:50 +00001151static std::recursive_mutex &GetObjectContainerMutex() {
1152 static std::recursive_mutex g_instances_mutex;
1153 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154}
1155
Kate Stoneb9c1b512016-09-06 20:57:50 +00001156static ObjectContainerInstances &GetObjectContainerInstances() {
1157 static ObjectContainerInstances g_instances;
1158 return g_instances;
Greg Claytonab65b342011-04-13 22:47:15 +00001159}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160
Kate Stoneb9c1b512016-09-06 20:57:50 +00001161bool PluginManager::RegisterPlugin(
1162 const ConstString &name, const char *description,
1163 ObjectContainerCreateInstance create_callback,
1164 ObjectFileGetModuleSpecifications get_module_specifications) {
1165 if (create_callback) {
1166 ObjectContainerInstance instance;
1167 assert((bool)name);
1168 instance.name = name;
1169 if (description && description[0])
1170 instance.description = description;
1171 instance.create_callback = create_callback;
1172 instance.get_module_specifications = get_module_specifications;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001173 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001174 GetObjectContainerInstances().push_back(instance);
1175 }
1176 return false;
1177}
1178
1179bool PluginManager::UnregisterPlugin(
1180 ObjectContainerCreateInstance create_callback) {
1181 if (create_callback) {
1182 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
1183 ObjectContainerInstances &instances = GetObjectContainerInstances();
1184
1185 ObjectContainerInstances::iterator pos, end = instances.end();
1186 for (pos = instances.begin(); pos != end; ++pos) {
1187 if (pos->create_callback == create_callback) {
1188 instances.erase(pos);
1189 return true;
1190 }
1191 }
1192 }
1193 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194}
Greg Claytonab65b342011-04-13 22:47:15 +00001195
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196ObjectContainerCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001197PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
1198 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
1199 ObjectContainerInstances &instances = GetObjectContainerInstances();
1200 if (idx < instances.size())
1201 return instances[idx].create_callback;
1202 return nullptr;
1203}
1204
1205ObjectContainerCreateInstance
1206PluginManager::GetObjectContainerCreateCallbackForPluginName(
1207 const ConstString &name) {
1208 if (name) {
1209 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
1210 ObjectContainerInstances &instances = GetObjectContainerInstances();
1211
1212 ObjectContainerInstances::iterator pos, end = instances.end();
1213 for (pos = instances.begin(); pos != end; ++pos) {
1214 if (name == pos->name)
1215 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001217 }
1218 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219}
1220
Greg Claytonf4d6de62013-04-24 22:29:28 +00001221ObjectFileGetModuleSpecifications
Kate Stoneb9c1b512016-09-06 20:57:50 +00001222PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
1223 uint32_t idx) {
1224 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
1225 ObjectContainerInstances &instances = GetObjectContainerInstances();
1226 if (idx < instances.size())
1227 return instances[idx].get_module_specifications;
1228 return nullptr;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001229}
1230
Greg Claytone996fd32011-03-08 22:40:15 +00001231#pragma mark Platform
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232
Kate Stoneb9c1b512016-09-06 20:57:50 +00001233struct PlatformInstance {
1234 PlatformInstance()
1235 : name(), description(), create_callback(nullptr),
1236 debugger_init_callback(nullptr) {}
1237
1238 ConstString name;
1239 std::string description;
1240 PlatformCreateInstance create_callback;
1241 DebuggerInitializeCallback debugger_init_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001242};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243
Greg Claytone996fd32011-03-08 22:40:15 +00001244typedef std::vector<PlatformInstance> PlatformInstances;
1245
Kate Stoneb9c1b512016-09-06 20:57:50 +00001246static std::recursive_mutex &GetPlatformInstancesMutex() {
1247 static std::recursive_mutex g_platform_instances_mutex;
1248 return g_platform_instances_mutex;
Greg Claytone996fd32011-03-08 22:40:15 +00001249}
1250
Kate Stoneb9c1b512016-09-06 20:57:50 +00001251static PlatformInstances &GetPlatformInstances() {
1252 static PlatformInstances g_platform_instances;
1253 return g_platform_instances;
Greg Claytonded470d2011-03-19 01:12:21 +00001254}
Greg Claytone996fd32011-03-08 22:40:15 +00001255
Kate Stoneb9c1b512016-09-06 20:57:50 +00001256bool PluginManager::RegisterPlugin(
1257 const ConstString &name, const char *description,
1258 PlatformCreateInstance create_callback,
1259 DebuggerInitializeCallback debugger_init_callback) {
1260 if (create_callback) {
1261 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001262
Kate Stoneb9c1b512016-09-06 20:57:50 +00001263 PlatformInstance instance;
1264 assert((bool)name);
1265 instance.name = name;
1266 if (description && description[0])
1267 instance.description = description;
1268 instance.create_callback = create_callback;
1269 instance.debugger_init_callback = debugger_init_callback;
1270 GetPlatformInstances().push_back(instance);
1271 return true;
1272 }
1273 return false;
1274}
1275
1276const char *PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) {
1277 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1278 PlatformInstances &instances = GetPlatformInstances();
1279 if (idx < instances.size())
1280 return instances[idx].name.GetCString();
1281 return nullptr;
1282}
1283
1284const char *PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) {
1285 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1286 PlatformInstances &instances = GetPlatformInstances();
1287 if (idx < instances.size())
1288 return instances[idx].description.c_str();
1289 return nullptr;
1290}
1291
1292bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) {
1293 if (create_callback) {
1294 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1295 PlatformInstances &instances = GetPlatformInstances();
1296
1297 PlatformInstances::iterator pos, end = instances.end();
1298 for (pos = instances.begin(); pos != end; ++pos) {
1299 if (pos->create_callback == create_callback) {
1300 instances.erase(pos);
Greg Claytonded470d2011-03-19 01:12:21 +00001301 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001302 }
Greg Claytone996fd32011-03-08 22:40:15 +00001303 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001304 }
1305 return false;
Greg Claytone996fd32011-03-08 22:40:15 +00001306}
1307
1308PlatformCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001309PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) {
1310 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1311 PlatformInstances &instances = GetPlatformInstances();
1312 if (idx < instances.size())
1313 return instances[idx].create_callback;
1314 return nullptr;
Greg Claytone996fd32011-03-08 22:40:15 +00001315}
1316
1317PlatformCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001318PluginManager::GetPlatformCreateCallbackForPluginName(const ConstString &name) {
1319 if (name) {
1320 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1321 PlatformInstances &instances = GetPlatformInstances();
Greg Claytonded470d2011-03-19 01:12:21 +00001322
Kate Stoneb9c1b512016-09-06 20:57:50 +00001323 PlatformInstances::iterator pos, end = instances.end();
1324 for (pos = instances.begin(); pos != end; ++pos) {
1325 if (name == pos->name)
1326 return pos->create_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001327 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001328 }
1329 return nullptr;
Greg Claytone996fd32011-03-08 22:40:15 +00001330}
1331
Zachary Turner4aa87532016-11-17 01:37:42 +00001332size_t PluginManager::AutoCompletePlatformName(llvm::StringRef name,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001333 StringList &matches) {
Zachary Turner4aa87532016-11-17 01:37:42 +00001334 if (name.empty())
1335 return matches.GetSize();
Greg Claytonab65b342011-04-13 22:47:15 +00001336
Zachary Turner4aa87532016-11-17 01:37:42 +00001337 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
1338 PlatformInstances &instances = GetPlatformInstances();
1339 llvm::StringRef name_sref(name);
1340
1341 PlatformInstances::iterator pos, end = instances.end();
1342 for (pos = instances.begin(); pos != end; ++pos) {
1343 llvm::StringRef plugin_name(pos->name.GetCString());
1344 if (plugin_name.startswith(name_sref))
1345 matches.AppendString(plugin_name.data());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001346 }
1347 return matches.GetSize();
Greg Claytonab65b342011-04-13 22:47:15 +00001348}
Eugene Zelenko89183722016-03-11 21:55:47 +00001349
Greg Claytone996fd32011-03-08 22:40:15 +00001350#pragma mark Process
1351
Kate Stoneb9c1b512016-09-06 20:57:50 +00001352struct ProcessInstance {
1353 ProcessInstance()
1354 : name(), description(), create_callback(nullptr),
1355 debugger_init_callback(nullptr) {}
1356
1357 ConstString name;
1358 std::string description;
1359 ProcessCreateInstance create_callback;
1360 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361};
1362
1363typedef std::vector<ProcessInstance> ProcessInstances;
1364
Kate Stoneb9c1b512016-09-06 20:57:50 +00001365static std::recursive_mutex &GetProcessMutex() {
1366 static std::recursive_mutex g_instances_mutex;
1367 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +00001368}
1369
Kate Stoneb9c1b512016-09-06 20:57:50 +00001370static ProcessInstances &GetProcessInstances() {
1371 static ProcessInstances g_instances;
1372 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001373}
1374
Kate Stoneb9c1b512016-09-06 20:57:50 +00001375bool PluginManager::RegisterPlugin(
1376 const ConstString &name, const char *description,
1377 ProcessCreateInstance create_callback,
1378 DebuggerInitializeCallback debugger_init_callback) {
1379 if (create_callback) {
1380 ProcessInstance instance;
1381 assert((bool)name);
1382 instance.name = name;
1383 if (description && description[0])
1384 instance.description = description;
1385 instance.create_callback = create_callback;
1386 instance.debugger_init_callback = debugger_init_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001387 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001388 GetProcessInstances().push_back(instance);
1389 }
1390 return false;
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001391}
1392
Kate Stoneb9c1b512016-09-06 20:57:50 +00001393const char *PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) {
1394 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
1395 ProcessInstances &instances = GetProcessInstances();
1396 if (idx < instances.size())
1397 return instances[idx].name.GetCString();
1398 return nullptr;
1399}
1400
1401const char *PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) {
1402 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
1403 ProcessInstances &instances = GetProcessInstances();
1404 if (idx < instances.size())
1405 return instances[idx].description.c_str();
1406 return nullptr;
1407}
1408
1409bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) {
1410 if (create_callback) {
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001411 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001412 ProcessInstances &instances = GetProcessInstances();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001413
Kate Stoneb9c1b512016-09-06 20:57:50 +00001414 ProcessInstances::iterator pos, end = instances.end();
1415 for (pos = instances.begin(); pos != end; ++pos) {
1416 if (pos->create_callback == create_callback) {
1417 instances.erase(pos);
1418 return true;
1419 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001420 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001421 }
1422 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423}
1424
1425ProcessCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001426PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) {
1427 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
1428 ProcessInstances &instances = GetProcessInstances();
1429 if (idx < instances.size())
1430 return instances[idx].create_callback;
1431 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001432}
1433
1434ProcessCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001435PluginManager::GetProcessCreateCallbackForPluginName(const ConstString &name) {
1436 if (name) {
1437 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
1438 ProcessInstances &instances = GetProcessInstances();
1439
1440 ProcessInstances::iterator pos, end = instances.end();
1441 for (pos = instances.begin(); pos != end; ++pos) {
1442 if (name == pos->name)
1443 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001445 }
1446 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447}
1448
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001449#pragma mark ScriptInterpreter
1450
Kate Stoneb9c1b512016-09-06 20:57:50 +00001451struct ScriptInterpreterInstance {
1452 ScriptInterpreterInstance()
1453 : name(), language(lldb::eScriptLanguageNone), description(),
1454 create_callback(nullptr) {}
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001455
Kate Stoneb9c1b512016-09-06 20:57:50 +00001456 ConstString name;
1457 lldb::ScriptLanguage language;
1458 std::string description;
1459 ScriptInterpreterCreateInstance create_callback;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001460};
1461
1462typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances;
1463
Kate Stoneb9c1b512016-09-06 20:57:50 +00001464static std::recursive_mutex &GetScriptInterpreterMutex() {
1465 static std::recursive_mutex g_instances_mutex;
1466 return g_instances_mutex;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001467}
1468
Kate Stoneb9c1b512016-09-06 20:57:50 +00001469static ScriptInterpreterInstances &GetScriptInterpreterInstances() {
1470 static ScriptInterpreterInstances g_instances;
1471 return g_instances;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001472}
1473
Kate Stoneb9c1b512016-09-06 20:57:50 +00001474bool PluginManager::RegisterPlugin(
1475 const ConstString &name, const char *description,
1476 lldb::ScriptLanguage script_language,
1477 ScriptInterpreterCreateInstance create_callback) {
1478 if (!create_callback)
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001479 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001480 ScriptInterpreterInstance instance;
1481 assert((bool)name);
1482 instance.name = name;
1483 if (description && description[0])
1484 instance.description = description;
1485 instance.create_callback = create_callback;
1486 instance.language = script_language;
1487 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
1488 GetScriptInterpreterInstances().push_back(instance);
1489 return false;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001490}
1491
Kate Stoneb9c1b512016-09-06 20:57:50 +00001492bool PluginManager::UnregisterPlugin(
1493 ScriptInterpreterCreateInstance create_callback) {
1494 if (!create_callback)
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001495 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001496 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
1497 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
1498
1499 ScriptInterpreterInstances::iterator pos, end = instances.end();
1500 for (pos = instances.begin(); pos != end; ++pos) {
1501 if (pos->create_callback != create_callback)
1502 continue;
1503
1504 instances.erase(pos);
1505 return true;
1506 }
1507 return false;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001508}
1509
1510ScriptInterpreterCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001511PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
1512 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
1513 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
1514 if (idx < instances.size())
1515 return instances[idx].create_callback;
1516 return nullptr;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001517}
1518
Kate Stoneb9c1b512016-09-06 20:57:50 +00001519lldb::ScriptInterpreterSP PluginManager::GetScriptInterpreterForLanguage(
1520 lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) {
1521 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
1522 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001523
Kate Stoneb9c1b512016-09-06 20:57:50 +00001524 ScriptInterpreterInstances::iterator pos, end = instances.end();
1525 ScriptInterpreterCreateInstance none_instance = nullptr;
1526 for (pos = instances.begin(); pos != end; ++pos) {
1527 if (pos->language == lldb::eScriptLanguageNone)
1528 none_instance = pos->create_callback;
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001529
Kate Stoneb9c1b512016-09-06 20:57:50 +00001530 if (script_lang == pos->language)
1531 return pos->create_callback(interpreter);
1532 }
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001533
Kate Stoneb9c1b512016-09-06 20:57:50 +00001534 // If we didn't find one, return the ScriptInterpreter for the null language.
1535 assert(none_instance != nullptr);
1536 return none_instance(interpreter);
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001537}
1538
Todd Fiala75930012016-08-19 04:21:48 +00001539#pragma mark -
1540#pragma mark StructuredDataPlugin
1541
1542// -----------------------------------------------------------------------------
1543// StructuredDataPlugin
1544// -----------------------------------------------------------------------------
1545
Kate Stoneb9c1b512016-09-06 20:57:50 +00001546struct StructuredDataPluginInstance {
1547 StructuredDataPluginInstance()
1548 : name(), description(), create_callback(nullptr),
1549 debugger_init_callback(nullptr), filter_callback(nullptr) {}
Todd Fiala75930012016-08-19 04:21:48 +00001550
Kate Stoneb9c1b512016-09-06 20:57:50 +00001551 ConstString name;
1552 std::string description;
1553 StructuredDataPluginCreateInstance create_callback;
1554 DebuggerInitializeCallback debugger_init_callback;
1555 StructuredDataFilterLaunchInfo filter_callback;
Todd Fiala75930012016-08-19 04:21:48 +00001556};
1557
1558typedef std::vector<StructuredDataPluginInstance> StructuredDataPluginInstances;
1559
Kate Stoneb9c1b512016-09-06 20:57:50 +00001560static std::recursive_mutex &GetStructuredDataPluginMutex() {
1561 static std::recursive_mutex g_instances_mutex;
1562 return g_instances_mutex;
Todd Fiala75930012016-08-19 04:21:48 +00001563}
1564
Kate Stoneb9c1b512016-09-06 20:57:50 +00001565static StructuredDataPluginInstances &GetStructuredDataPluginInstances() {
1566 static StructuredDataPluginInstances g_instances;
1567 return g_instances;
Todd Fiala75930012016-08-19 04:21:48 +00001568}
1569
Kate Stoneb9c1b512016-09-06 20:57:50 +00001570bool PluginManager::RegisterPlugin(
1571 const ConstString &name, const char *description,
1572 StructuredDataPluginCreateInstance create_callback,
1573 DebuggerInitializeCallback debugger_init_callback,
1574 StructuredDataFilterLaunchInfo filter_callback) {
1575 if (create_callback) {
1576 StructuredDataPluginInstance instance;
1577 assert((bool)name);
1578 instance.name = name;
1579 if (description && description[0])
1580 instance.description = description;
1581 instance.create_callback = create_callback;
1582 instance.debugger_init_callback = debugger_init_callback;
1583 instance.filter_callback = filter_callback;
1584 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
1585 GetStructuredDataPluginInstances().push_back(instance);
1586 }
1587 return false;
Todd Fiala75930012016-08-19 04:21:48 +00001588}
1589
Kate Stoneb9c1b512016-09-06 20:57:50 +00001590bool PluginManager::UnregisterPlugin(
1591 StructuredDataPluginCreateInstance create_callback) {
1592 if (create_callback) {
Todd Fiala75930012016-08-19 04:21:48 +00001593 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
1594 StructuredDataPluginInstances &instances =
1595 GetStructuredDataPluginInstances();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001596
1597 StructuredDataPluginInstances::iterator pos, end = instances.end();
1598 for (pos = instances.begin(); pos != end; ++pos) {
1599 if (pos->create_callback == create_callback) {
1600 instances.erase(pos);
1601 return true;
1602 }
1603 }
1604 }
1605 return false;
1606}
1607
1608StructuredDataPluginCreateInstance
1609PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
1610 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
1611 StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances();
1612 if (idx < instances.size())
1613 return instances[idx].create_callback;
1614 return nullptr;
Todd Fiala75930012016-08-19 04:21:48 +00001615}
1616
1617StructuredDataPluginCreateInstance
1618PluginManager::GetStructuredDataPluginCreateCallbackForPluginName(
Kate Stoneb9c1b512016-09-06 20:57:50 +00001619 const ConstString &name) {
1620 if (name) {
Todd Fiala75930012016-08-19 04:21:48 +00001621 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
1622 StructuredDataPluginInstances &instances =
1623 GetStructuredDataPluginInstances();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001624
1625 StructuredDataPluginInstances::iterator pos, end = instances.end();
1626 for (pos = instances.begin(); pos != end; ++pos) {
1627 if (name == pos->name)
1628 return pos->create_callback;
Todd Fiala75930012016-08-19 04:21:48 +00001629 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001630 }
1631 return nullptr;
1632}
1633
1634StructuredDataFilterLaunchInfo
1635PluginManager::GetStructuredDataFilterCallbackAtIndex(
1636 uint32_t idx, bool &iteration_complete) {
1637 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
1638 StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances();
1639 if (idx < instances.size()) {
1640 iteration_complete = false;
1641 return instances[idx].filter_callback;
1642 } else {
1643 iteration_complete = true;
1644 }
1645 return nullptr;
Todd Fiala75930012016-08-19 04:21:48 +00001646}
1647
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001648#pragma mark SymbolFile
1649
Kate Stoneb9c1b512016-09-06 20:57:50 +00001650struct SymbolFileInstance {
1651 SymbolFileInstance()
1652 : name(), description(), create_callback(nullptr),
1653 debugger_init_callback(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001654
Kate Stoneb9c1b512016-09-06 20:57:50 +00001655 ConstString name;
1656 std::string description;
1657 SymbolFileCreateInstance create_callback;
1658 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659};
1660
1661typedef std::vector<SymbolFileInstance> SymbolFileInstances;
1662
Kate Stoneb9c1b512016-09-06 20:57:50 +00001663static std::recursive_mutex &GetSymbolFileMutex() {
1664 static std::recursive_mutex g_instances_mutex;
1665 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +00001666}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667
Kate Stoneb9c1b512016-09-06 20:57:50 +00001668static SymbolFileInstances &GetSymbolFileInstances() {
1669 static SymbolFileInstances g_instances;
1670 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001671}
1672
Kate Stoneb9c1b512016-09-06 20:57:50 +00001673bool PluginManager::RegisterPlugin(
1674 const ConstString &name, const char *description,
1675 SymbolFileCreateInstance create_callback,
1676 DebuggerInitializeCallback debugger_init_callback) {
1677 if (create_callback) {
1678 SymbolFileInstance instance;
1679 assert((bool)name);
1680 instance.name = name;
1681 if (description && description[0])
1682 instance.description = description;
1683 instance.create_callback = create_callback;
1684 instance.debugger_init_callback = debugger_init_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001685 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001686 GetSymbolFileInstances().push_back(instance);
1687 }
1688 return false;
1689}
1690
1691bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) {
1692 if (create_callback) {
1693 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
1694 SymbolFileInstances &instances = GetSymbolFileInstances();
1695
1696 SymbolFileInstances::iterator pos, end = instances.end();
1697 for (pos = instances.begin(); pos != end; ++pos) {
1698 if (pos->create_callback == create_callback) {
1699 instances.erase(pos);
1700 return true;
1701 }
1702 }
1703 }
1704 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705}
Greg Claytonab65b342011-04-13 22:47:15 +00001706
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001707SymbolFileCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001708PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) {
1709 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
1710 SymbolFileInstances &instances = GetSymbolFileInstances();
1711 if (idx < instances.size())
1712 return instances[idx].create_callback;
1713 return nullptr;
1714}
1715
1716SymbolFileCreateInstance
1717PluginManager::GetSymbolFileCreateCallbackForPluginName(
1718 const ConstString &name) {
1719 if (name) {
1720 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
1721 SymbolFileInstances &instances = GetSymbolFileInstances();
1722
1723 SymbolFileInstances::iterator pos, end = instances.end();
1724 for (pos = instances.begin(); pos != end; ++pos) {
1725 if (name == pos->name)
1726 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001727 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001728 }
1729 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730}
1731
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732#pragma mark SymbolVendor
1733
Kate Stoneb9c1b512016-09-06 20:57:50 +00001734struct SymbolVendorInstance {
1735 SymbolVendorInstance() : name(), description(), create_callback(nullptr) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001736
Kate Stoneb9c1b512016-09-06 20:57:50 +00001737 ConstString name;
1738 std::string description;
1739 SymbolVendorCreateInstance create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001740};
1741
1742typedef std::vector<SymbolVendorInstance> SymbolVendorInstances;
1743
Kate Stoneb9c1b512016-09-06 20:57:50 +00001744static std::recursive_mutex &GetSymbolVendorMutex() {
1745 static std::recursive_mutex g_instances_mutex;
1746 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +00001747}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748
Kate Stoneb9c1b512016-09-06 20:57:50 +00001749static SymbolVendorInstances &GetSymbolVendorInstances() {
1750 static SymbolVendorInstances g_instances;
1751 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001752}
1753
Kate Stoneb9c1b512016-09-06 20:57:50 +00001754bool PluginManager::RegisterPlugin(const ConstString &name,
1755 const char *description,
1756 SymbolVendorCreateInstance create_callback) {
1757 if (create_callback) {
1758 SymbolVendorInstance instance;
1759 assert((bool)name);
1760 instance.name = name;
1761 if (description && description[0])
1762 instance.description = description;
1763 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001764 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001765 GetSymbolVendorInstances().push_back(instance);
1766 }
1767 return false;
1768}
1769
1770bool PluginManager::UnregisterPlugin(
1771 SymbolVendorCreateInstance create_callback) {
1772 if (create_callback) {
1773 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
1774 SymbolVendorInstances &instances = GetSymbolVendorInstances();
1775
1776 SymbolVendorInstances::iterator pos, end = instances.end();
1777 for (pos = instances.begin(); pos != end; ++pos) {
1778 if (pos->create_callback == create_callback) {
1779 instances.erase(pos);
1780 return true;
1781 }
1782 }
1783 }
1784 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001785}
1786
1787SymbolVendorCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001788PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
1789 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
1790 SymbolVendorInstances &instances = GetSymbolVendorInstances();
1791 if (idx < instances.size())
1792 return instances[idx].create_callback;
1793 return nullptr;
1794}
1795
1796SymbolVendorCreateInstance
1797PluginManager::GetSymbolVendorCreateCallbackForPluginName(
1798 const ConstString &name) {
1799 if (name) {
1800 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
1801 SymbolVendorInstances &instances = GetSymbolVendorInstances();
1802
1803 SymbolVendorInstances::iterator pos, end = instances.end();
1804 for (pos = instances.begin(); pos != end; ++pos) {
1805 if (name == pos->name)
1806 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001808 }
1809 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001810}
1811
Greg Clayton7be25422011-04-25 21:14:26 +00001812#pragma mark UnwindAssembly
Jason Molendafbcb7f22010-09-10 07:49:16 +00001813
Kate Stoneb9c1b512016-09-06 20:57:50 +00001814struct UnwindAssemblyInstance {
1815 UnwindAssemblyInstance() : name(), description(), create_callback(nullptr) {}
Jason Molendafbcb7f22010-09-10 07:49:16 +00001816
Kate Stoneb9c1b512016-09-06 20:57:50 +00001817 ConstString name;
1818 std::string description;
1819 UnwindAssemblyCreateInstance create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001820};
1821
Greg Clayton7be25422011-04-25 21:14:26 +00001822typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001823
Kate Stoneb9c1b512016-09-06 20:57:50 +00001824static std::recursive_mutex &GetUnwindAssemblyMutex() {
1825 static std::recursive_mutex g_instances_mutex;
1826 return g_instances_mutex;
Greg Claytonab65b342011-04-13 22:47:15 +00001827}
Jason Molendafbcb7f22010-09-10 07:49:16 +00001828
Kate Stoneb9c1b512016-09-06 20:57:50 +00001829static UnwindAssemblyInstances &GetUnwindAssemblyInstances() {
1830 static UnwindAssemblyInstances g_instances;
1831 return g_instances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001832}
1833
Kate Stoneb9c1b512016-09-06 20:57:50 +00001834bool PluginManager::RegisterPlugin(
1835 const ConstString &name, const char *description,
1836 UnwindAssemblyCreateInstance create_callback) {
1837 if (create_callback) {
1838 UnwindAssemblyInstance instance;
1839 assert((bool)name);
1840 instance.name = name;
1841 if (description && description[0])
1842 instance.description = description;
1843 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001844 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001845 GetUnwindAssemblyInstances().push_back(instance);
1846 }
1847 return false;
1848}
1849
1850bool PluginManager::UnregisterPlugin(
1851 UnwindAssemblyCreateInstance create_callback) {
1852 if (create_callback) {
1853 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
1854 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
1855
1856 UnwindAssemblyInstances::iterator pos, end = instances.end();
1857 for (pos = instances.begin(); pos != end; ++pos) {
1858 if (pos->create_callback == create_callback) {
1859 instances.erase(pos);
1860 return true;
1861 }
1862 }
1863 }
1864 return false;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001865}
1866
Greg Clayton7be25422011-04-25 21:14:26 +00001867UnwindAssemblyCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001868PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) {
1869 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
1870 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
1871 if (idx < instances.size())
1872 return instances[idx].create_callback;
1873 return nullptr;
1874}
1875
1876UnwindAssemblyCreateInstance
1877PluginManager::GetUnwindAssemblyCreateCallbackForPluginName(
1878 const ConstString &name) {
1879 if (name) {
1880 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
1881 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
1882
1883 UnwindAssemblyInstances::iterator pos, end = instances.end();
1884 for (pos = instances.begin(); pos != end; ++pos) {
1885 if (name == pos->name)
1886 return pos->create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001887 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001888 }
1889 return nullptr;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001890}
1891
Kuba Breckabeed8212014-09-04 01:03:18 +00001892#pragma mark MemoryHistory
1893
Kate Stoneb9c1b512016-09-06 20:57:50 +00001894struct MemoryHistoryInstance {
1895 MemoryHistoryInstance() : name(), description(), create_callback(nullptr) {}
1896
1897 ConstString name;
1898 std::string description;
1899 MemoryHistoryCreateInstance create_callback;
Kuba Breckabeed8212014-09-04 01:03:18 +00001900};
1901
1902typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances;
1903
Kate Stoneb9c1b512016-09-06 20:57:50 +00001904static std::recursive_mutex &GetMemoryHistoryMutex() {
1905 static std::recursive_mutex g_instances_mutex;
1906 return g_instances_mutex;
Kuba Breckabeed8212014-09-04 01:03:18 +00001907}
1908
Kate Stoneb9c1b512016-09-06 20:57:50 +00001909static MemoryHistoryInstances &GetMemoryHistoryInstances() {
1910 static MemoryHistoryInstances g_instances;
1911 return g_instances;
Kuba Breckabeed8212014-09-04 01:03:18 +00001912}
1913
Kate Stoneb9c1b512016-09-06 20:57:50 +00001914bool PluginManager::RegisterPlugin(
1915 const ConstString &name, const char *description,
1916 MemoryHistoryCreateInstance create_callback) {
1917 if (create_callback) {
1918 MemoryHistoryInstance instance;
1919 assert((bool)name);
1920 instance.name = name;
1921 if (description && description[0])
1922 instance.description = description;
1923 instance.create_callback = create_callback;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00001924 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001925 GetMemoryHistoryInstances().push_back(instance);
1926 }
1927 return false;
1928}
1929
1930bool PluginManager::UnregisterPlugin(
1931 MemoryHistoryCreateInstance create_callback) {
1932 if (create_callback) {
1933 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
1934 MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
1935
1936 MemoryHistoryInstances::iterator pos, end = instances.end();
1937 for (pos = instances.begin(); pos != end; ++pos) {
1938 if (pos->create_callback == create_callback) {
1939 instances.erase(pos);
1940 return true;
1941 }
1942 }
1943 }
1944 return false;
Kuba Breckabeed8212014-09-04 01:03:18 +00001945}
1946
Kuba Breckabeed8212014-09-04 01:03:18 +00001947MemoryHistoryCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00001948PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) {
1949 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
1950 MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
1951 if (idx < instances.size())
1952 return instances[idx].create_callback;
1953 return nullptr;
1954}
1955
1956MemoryHistoryCreateInstance
1957PluginManager::GetMemoryHistoryCreateCallbackForPluginName(
1958 const ConstString &name) {
1959 if (name) {
1960 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
1961 MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
1962
1963 MemoryHistoryInstances::iterator pos, end = instances.end();
1964 for (pos = instances.begin(); pos != end; ++pos) {
1965 if (name == pos->name)
1966 return pos->create_callback;
Kuba Breckabeed8212014-09-04 01:03:18 +00001967 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001968 }
1969 return nullptr;
Kuba Breckabeed8212014-09-04 01:03:18 +00001970}
1971
Kuba Breckaafdf8422014-10-10 23:43:03 +00001972#pragma mark InstrumentationRuntime
1973
Kate Stoneb9c1b512016-09-06 20:57:50 +00001974struct InstrumentationRuntimeInstance {
1975 InstrumentationRuntimeInstance()
1976 : name(), description(), create_callback(nullptr) {}
1977
1978 ConstString name;
1979 std::string description;
1980 InstrumentationRuntimeCreateInstance create_callback;
1981 InstrumentationRuntimeGetType get_type_callback;
Kuba Breckaafdf8422014-10-10 23:43:03 +00001982};
1983
Kate Stoneb9c1b512016-09-06 20:57:50 +00001984typedef std::vector<InstrumentationRuntimeInstance>
1985 InstrumentationRuntimeInstances;
Kuba Breckaafdf8422014-10-10 23:43:03 +00001986
Kate Stoneb9c1b512016-09-06 20:57:50 +00001987static std::recursive_mutex &GetInstrumentationRuntimeMutex() {
1988 static std::recursive_mutex g_instances_mutex;
1989 return g_instances_mutex;
Kuba Breckaafdf8422014-10-10 23:43:03 +00001990}
1991
Kate Stoneb9c1b512016-09-06 20:57:50 +00001992static InstrumentationRuntimeInstances &GetInstrumentationRuntimeInstances() {
1993 static InstrumentationRuntimeInstances g_instances;
1994 return g_instances;
Kuba Breckaafdf8422014-10-10 23:43:03 +00001995}
1996
Kate Stoneb9c1b512016-09-06 20:57:50 +00001997bool PluginManager::RegisterPlugin(
1998 const ConstString &name, const char *description,
1999 InstrumentationRuntimeCreateInstance create_callback,
2000 InstrumentationRuntimeGetType get_type_callback) {
2001 if (create_callback) {
2002 InstrumentationRuntimeInstance instance;
2003 assert((bool)name);
2004 instance.name = name;
2005 if (description && description[0])
2006 instance.description = description;
2007 instance.create_callback = create_callback;
2008 instance.get_type_callback = get_type_callback;
2009 std::lock_guard<std::recursive_mutex> guard(
2010 GetInstrumentationRuntimeMutex());
2011 GetInstrumentationRuntimeInstances().push_back(instance);
2012 }
2013 return false;
2014}
2015
2016bool PluginManager::UnregisterPlugin(
2017 InstrumentationRuntimeCreateInstance create_callback) {
2018 if (create_callback) {
2019 std::lock_guard<std::recursive_mutex> guard(
2020 GetInstrumentationRuntimeMutex());
2021 InstrumentationRuntimeInstances &instances =
2022 GetInstrumentationRuntimeInstances();
2023
2024 InstrumentationRuntimeInstances::iterator pos, end = instances.end();
2025 for (pos = instances.begin(); pos != end; ++pos) {
2026 if (pos->create_callback == create_callback) {
2027 instances.erase(pos);
2028 return true;
2029 }
Kuba Breckaafdf8422014-10-10 23:43:03 +00002030 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002031 }
2032 return false;
Kuba Breckaafdf8422014-10-10 23:43:03 +00002033}
2034
2035InstrumentationRuntimeGetType
Kate Stoneb9c1b512016-09-06 20:57:50 +00002036PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
2037 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
2038 InstrumentationRuntimeInstances &instances =
2039 GetInstrumentationRuntimeInstances();
2040 if (idx < instances.size())
2041 return instances[idx].get_type_callback;
2042 return nullptr;
Kuba Breckaafdf8422014-10-10 23:43:03 +00002043}
2044
2045InstrumentationRuntimeCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00002046PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) {
2047 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
2048 InstrumentationRuntimeInstances &instances =
2049 GetInstrumentationRuntimeInstances();
2050 if (idx < instances.size())
2051 return instances[idx].create_callback;
2052 return nullptr;
Kuba Breckaafdf8422014-10-10 23:43:03 +00002053}
2054
Kuba Breckaafdf8422014-10-10 23:43:03 +00002055InstrumentationRuntimeCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00002056PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName(
2057 const ConstString &name) {
2058 if (name) {
2059 std::lock_guard<std::recursive_mutex> guard(
2060 GetInstrumentationRuntimeMutex());
2061 InstrumentationRuntimeInstances &instances =
2062 GetInstrumentationRuntimeInstances();
2063
2064 InstrumentationRuntimeInstances::iterator pos, end = instances.end();
2065 for (pos = instances.begin(); pos != end; ++pos) {
2066 if (name == pos->name)
2067 return pos->create_callback;
Kuba Breckaafdf8422014-10-10 23:43:03 +00002068 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002069 }
2070 return nullptr;
Kuba Breckaafdf8422014-10-10 23:43:03 +00002071}
2072
Greg Clayton56939cb2015-09-17 22:23:34 +00002073#pragma mark TypeSystem
2074
Kate Stoneb9c1b512016-09-06 20:57:50 +00002075struct TypeSystemInstance {
2076 TypeSystemInstance() : name(), description(), create_callback(nullptr) {}
Greg Clayton56939cb2015-09-17 22:23:34 +00002077
Kate Stoneb9c1b512016-09-06 20:57:50 +00002078 ConstString name;
2079 std::string description;
2080 TypeSystemCreateInstance create_callback;
2081 TypeSystemEnumerateSupportedLanguages enumerate_callback;
Greg Clayton56939cb2015-09-17 22:23:34 +00002082};
2083
2084typedef std::vector<TypeSystemInstance> TypeSystemInstances;
2085
Kate Stoneb9c1b512016-09-06 20:57:50 +00002086static std::recursive_mutex &GetTypeSystemMutex() {
2087 static std::recursive_mutex g_instances_mutex;
2088 return g_instances_mutex;
Greg Clayton56939cb2015-09-17 22:23:34 +00002089}
2090
Kate Stoneb9c1b512016-09-06 20:57:50 +00002091static TypeSystemInstances &GetTypeSystemInstances() {
2092 static TypeSystemInstances g_instances;
2093 return g_instances;
Greg Clayton56939cb2015-09-17 22:23:34 +00002094}
2095
Kate Stoneb9c1b512016-09-06 20:57:50 +00002096bool PluginManager::RegisterPlugin(const ConstString &name,
2097 const char *description,
2098 TypeSystemCreateInstance create_callback,
2099 TypeSystemEnumerateSupportedLanguages
2100 enumerate_supported_languages_callback) {
2101 if (create_callback) {
2102 TypeSystemInstance instance;
2103 assert((bool)name);
2104 instance.name = name;
2105 if (description && description[0])
2106 instance.description = description;
2107 instance.create_callback = create_callback;
2108 instance.enumerate_callback = enumerate_supported_languages_callback;
2109 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
2110 GetTypeSystemInstances().push_back(instance);
2111 }
2112 return false;
2113}
2114
2115bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
2116 if (create_callback) {
2117 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
2118 TypeSystemInstances &instances = GetTypeSystemInstances();
2119
2120 TypeSystemInstances::iterator pos, end = instances.end();
2121 for (pos = instances.begin(); pos != end; ++pos) {
2122 if (pos->create_callback == create_callback) {
2123 instances.erase(pos);
2124 return true;
2125 }
Greg Clayton56939cb2015-09-17 22:23:34 +00002126 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002127 }
2128 return false;
Greg Clayton56939cb2015-09-17 22:23:34 +00002129}
2130
2131TypeSystemCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00002132PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
2133 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
2134 TypeSystemInstances &instances = GetTypeSystemInstances();
2135 if (idx < instances.size())
2136 return instances[idx].create_callback;
2137 return nullptr;
Greg Clayton56939cb2015-09-17 22:23:34 +00002138}
2139
2140TypeSystemCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00002141PluginManager::GetTypeSystemCreateCallbackForPluginName(
2142 const ConstString &name) {
2143 if (name) {
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00002144 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002145 TypeSystemInstances &instances = GetTypeSystemInstances();
2146
2147 TypeSystemInstances::iterator pos, end = instances.end();
2148 for (pos = instances.begin(); pos != end; ++pos) {
2149 if (name == pos->name)
2150 return pos->create_callback;
2151 }
2152 }
2153 return nullptr;
Sean Callananfe38c852015-10-08 23:07:53 +00002154}
2155
2156TypeSystemEnumerateSupportedLanguages
Kate Stoneb9c1b512016-09-06 20:57:50 +00002157PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(
2158 uint32_t idx) {
2159 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
2160 TypeSystemInstances &instances = GetTypeSystemInstances();
2161 if (idx < instances.size())
2162 return instances[idx].enumerate_callback;
2163 return nullptr;
2164}
2165
2166TypeSystemEnumerateSupportedLanguages
2167PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName(
2168 const ConstString &name) {
2169 if (name) {
2170 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
2171 TypeSystemInstances &instances = GetTypeSystemInstances();
2172
2173 TypeSystemInstances::iterator pos, end = instances.end();
2174 for (pos = instances.begin(); pos != end; ++pos) {
2175 if (name == pos->name)
2176 return pos->enumerate_callback;
Sean Callananfe38c852015-10-08 23:07:53 +00002177 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002178 }
2179 return nullptr;
Sean Callananfe38c852015-10-08 23:07:53 +00002180}
Greg Clayton56939cb2015-09-17 22:23:34 +00002181
Sean Callanan66810412015-10-19 23:11:07 +00002182#pragma mark REPL
2183
Kate Stoneb9c1b512016-09-06 20:57:50 +00002184struct REPLInstance {
2185 REPLInstance() : name(), description(), create_callback(nullptr) {}
2186
2187 ConstString name;
2188 std::string description;
2189 REPLCreateInstance create_callback;
2190 REPLEnumerateSupportedLanguages enumerate_languages_callback;
Sean Callanan66810412015-10-19 23:11:07 +00002191};
2192
2193typedef std::vector<REPLInstance> REPLInstances;
2194
Kate Stoneb9c1b512016-09-06 20:57:50 +00002195static std::recursive_mutex &GetREPLMutex() {
2196 static std::recursive_mutex g_instances_mutex;
2197 return g_instances_mutex;
Sean Callanan66810412015-10-19 23:11:07 +00002198}
2199
Kate Stoneb9c1b512016-09-06 20:57:50 +00002200static REPLInstances &GetREPLInstances() {
2201 static REPLInstances g_instances;
2202 return g_instances;
Sean Callanan66810412015-10-19 23:11:07 +00002203}
2204
Kate Stoneb9c1b512016-09-06 20:57:50 +00002205bool PluginManager::RegisterPlugin(
2206 const ConstString &name, const char *description,
2207 REPLCreateInstance create_callback,
2208 REPLEnumerateSupportedLanguages enumerate_languages_callback) {
2209 if (create_callback) {
2210 REPLInstance instance;
2211 assert((bool)name);
2212 instance.name = name;
2213 if (description && description[0])
2214 instance.description = description;
2215 instance.create_callback = create_callback;
2216 instance.enumerate_languages_callback = enumerate_languages_callback;
2217 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
2218 GetREPLInstances().push_back(instance);
2219 }
2220 return false;
2221}
2222
2223bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) {
2224 if (create_callback) {
2225 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
2226 REPLInstances &instances = GetREPLInstances();
2227
2228 REPLInstances::iterator pos, end = instances.end();
2229 for (pos = instances.begin(); pos != end; ++pos) {
2230 if (pos->create_callback == create_callback) {
2231 instances.erase(pos);
2232 return true;
2233 }
Sean Callanan66810412015-10-19 23:11:07 +00002234 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002235 }
2236 return false;
Sean Callanan66810412015-10-19 23:11:07 +00002237}
2238
Kate Stoneb9c1b512016-09-06 20:57:50 +00002239REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
2240 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
2241 REPLInstances &instances = GetREPLInstances();
2242 if (idx < instances.size())
2243 return instances[idx].create_callback;
2244 return nullptr;
Sean Callanan66810412015-10-19 23:11:07 +00002245}
2246
2247REPLCreateInstance
Kate Stoneb9c1b512016-09-06 20:57:50 +00002248PluginManager::GetREPLCreateCallbackForPluginName(const ConstString &name) {
2249 if (name) {
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +00002250 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002251 REPLInstances &instances = GetREPLInstances();
Sean Callanan66810412015-10-19 23:11:07 +00002252
Kate Stoneb9c1b512016-09-06 20:57:50 +00002253 REPLInstances::iterator pos, end = instances.end();
2254 for (pos = instances.begin(); pos != end; ++pos) {
2255 if (name == pos->name)
2256 return pos->create_callback;
Sean Callanan66810412015-10-19 23:11:07 +00002257 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002258 }
2259 return nullptr;
Sean Callanan66810412015-10-19 23:11:07 +00002260}
2261
Sean Callanan93c0b002015-10-21 19:14:33 +00002262REPLEnumerateSupportedLanguages
Kate Stoneb9c1b512016-09-06 20:57:50 +00002263PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx) {
2264 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
2265 REPLInstances &instances = GetREPLInstances();
2266 if (idx < instances.size())
2267 return instances[idx].enumerate_languages_callback;
2268 return nullptr;
Sean Callanan93c0b002015-10-21 19:14:33 +00002269}
2270
Sean Callanan93c0b002015-10-21 19:14:33 +00002271REPLEnumerateSupportedLanguages
Kate Stoneb9c1b512016-09-06 20:57:50 +00002272PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName(
2273 const ConstString &name) {
2274 if (name) {
2275 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
2276 REPLInstances &instances = GetREPLInstances();
2277
2278 REPLInstances::iterator pos, end = instances.end();
2279 for (pos = instances.begin(); pos != end; ++pos) {
2280 if (name == pos->name)
2281 return pos->enumerate_languages_callback;
Sean Callanan93c0b002015-10-21 19:14:33 +00002282 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002283 }
2284 return nullptr;
Sean Callanan93c0b002015-10-21 19:14:33 +00002285}
2286
Kuba Breckaafdf8422014-10-10 23:43:03 +00002287#pragma mark PluginManager
2288
Kate Stoneb9c1b512016-09-06 20:57:50 +00002289void PluginManager::DebuggerInitialize(Debugger &debugger) {
2290 // Initialize the DynamicLoader plugins
2291 {
2292 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
2293 DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
Jason Molenda9b837a12013-04-05 05:06:39 +00002294
Kate Stoneb9c1b512016-09-06 20:57:50 +00002295 DynamicLoaderInstances::iterator pos, end = instances.end();
2296 for (pos = instances.begin(); pos != end; ++pos) {
2297 if (pos->debugger_init_callback)
2298 pos->debugger_init_callback(debugger);
Andrew MacPherson17220c12014-03-05 10:12:43 +00002299 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002300 }
Andrew MacPherson17220c12014-03-05 10:12:43 +00002301
Kate Stoneb9c1b512016-09-06 20:57:50 +00002302 // Initialize the JITLoader plugins
2303 {
2304 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
2305 JITLoaderInstances &instances = GetJITLoaderInstances();
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002306
Kate Stoneb9c1b512016-09-06 20:57:50 +00002307 JITLoaderInstances::iterator pos, end = instances.end();
2308 for (pos = instances.begin(); pos != end; ++pos) {
2309 if (pos->debugger_init_callback)
2310 pos->debugger_init_callback(debugger);
Greg Clayton7f982402013-07-15 22:54:20 +00002311 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002312 }
Greg Clayton7f982402013-07-15 22:54:20 +00002313
Kate Stoneb9c1b512016-09-06 20:57:50 +00002314 // Initialize the Platform plugins
2315 {
2316 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
2317 PlatformInstances &instances = GetPlatformInstances();
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002318
Kate Stoneb9c1b512016-09-06 20:57:50 +00002319 PlatformInstances::iterator pos, end = instances.end();
2320 for (pos = instances.begin(); pos != end; ++pos) {
2321 if (pos->debugger_init_callback)
2322 pos->debugger_init_callback(debugger);
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002323 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002324 }
Todd Fiala75930012016-08-19 04:21:48 +00002325
Kate Stoneb9c1b512016-09-06 20:57:50 +00002326 // Initialize the Process plugins
2327 {
2328 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
2329 ProcessInstances &instances = GetProcessInstances();
2330
2331 ProcessInstances::iterator pos, end = instances.end();
2332 for (pos = instances.begin(); pos != end; ++pos) {
2333 if (pos->debugger_init_callback)
2334 pos->debugger_init_callback(debugger);
Todd Fiala75930012016-08-19 04:21:48 +00002335 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002336 }
2337
2338 // Initialize the SymbolFile plugins
2339 {
2340 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
2341 for (auto &sym_file : GetSymbolFileInstances()) {
2342 if (sym_file.debugger_init_callback)
2343 sym_file.debugger_init_callback(debugger);
2344 }
2345 }
2346
2347 // Initialize the OperatingSystem plugins
2348 {
2349 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
2350 for (auto &os : GetOperatingSystemInstances()) {
2351 if (os.debugger_init_callback)
2352 os.debugger_init_callback(debugger);
2353 }
2354 }
2355
2356 // Initialize the StructuredDataPlugin plugins
2357 {
2358 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
2359 for (auto &plugin : GetStructuredDataPluginInstances()) {
2360 if (plugin.debugger_init_callback)
2361 plugin.debugger_init_callback(debugger);
2362 }
2363 }
Greg Claytone8cd0c92012-10-19 18:02:49 +00002364}
2365
Greg Clayton7f982402013-07-15 22:54:20 +00002366// This is the preferred new way to register plugin specific settings. e.g.
Kate Stoneb9c1b512016-09-06 20:57:50 +00002367// This will put a plugin's settings under e.g.
2368// "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
2369static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins(
2370 Debugger &debugger, const ConstString &plugin_type_name,
2371 const ConstString &plugin_type_desc, bool can_create) {
2372 lldb::OptionValuePropertiesSP parent_properties_sp(
2373 debugger.GetValueProperties());
2374 if (parent_properties_sp) {
2375 static ConstString g_property_name("plugin");
2376
2377 OptionValuePropertiesSP plugin_properties_sp =
2378 parent_properties_sp->GetSubProperty(nullptr, g_property_name);
2379 if (!plugin_properties_sp && can_create) {
Zachary Turner2f3df612017-04-06 21:28:29 +00002380 plugin_properties_sp =
2381 std::make_shared<OptionValueProperties>(g_property_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002382 parent_properties_sp->AppendProperty(
2383 g_property_name, ConstString("Settings specify to plugins."), true,
2384 plugin_properties_sp);
Greg Claytone8cd0c92012-10-19 18:02:49 +00002385 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002386
2387 if (plugin_properties_sp) {
2388 lldb::OptionValuePropertiesSP plugin_type_properties_sp =
2389 plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
2390 if (!plugin_type_properties_sp && can_create) {
Zachary Turner2f3df612017-04-06 21:28:29 +00002391 plugin_type_properties_sp =
2392 std::make_shared<OptionValueProperties>(plugin_type_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002393 plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
2394 true, plugin_type_properties_sp);
2395 }
2396 return plugin_type_properties_sp;
2397 }
2398 }
2399 return lldb::OptionValuePropertiesSP();
Greg Claytone8cd0c92012-10-19 18:02:49 +00002400}
2401
Greg Clayton7f982402013-07-15 22:54:20 +00002402// This is deprecated way to register plugin specific settings. e.g.
Adrian Prantl05097242018-04-30 16:49:04 +00002403// "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform
2404// generic settings would be under "platform.SETTINGNAME".
Kate Stoneb9c1b512016-09-06 20:57:50 +00002405static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(
2406 Debugger &debugger, const ConstString &plugin_type_name,
2407 const ConstString &plugin_type_desc, bool can_create) {
2408 static ConstString g_property_name("plugin");
2409 lldb::OptionValuePropertiesSP parent_properties_sp(
2410 debugger.GetValueProperties());
2411 if (parent_properties_sp) {
2412 OptionValuePropertiesSP plugin_properties_sp =
2413 parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
2414 if (!plugin_properties_sp && can_create) {
Zachary Turner2f3df612017-04-06 21:28:29 +00002415 plugin_properties_sp =
2416 std::make_shared<OptionValueProperties>(plugin_type_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002417 parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
2418 true, plugin_properties_sp);
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002419 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002420
2421 if (plugin_properties_sp) {
2422 lldb::OptionValuePropertiesSP plugin_type_properties_sp =
2423 plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
2424 if (!plugin_type_properties_sp && can_create) {
Zachary Turner2f3df612017-04-06 21:28:29 +00002425 plugin_type_properties_sp =
2426 std::make_shared<OptionValueProperties>(g_property_name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002427 plugin_properties_sp->AppendProperty(
2428 g_property_name, ConstString("Settings specific to plugins"), true,
2429 plugin_type_properties_sp);
2430 }
2431 return plugin_type_properties_sp;
2432 }
2433 }
2434 return lldb::OptionValuePropertiesSP();
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002435}
2436
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002437namespace {
2438
2439typedef lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002440GetDebuggerPropertyForPluginsPtr(Debugger &, const ConstString &,
2441 const ConstString &, bool can_create);
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002442
Greg Claytone8cd0c92012-10-19 18:02:49 +00002443lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002444GetSettingForPlugin(Debugger &debugger, const ConstString &setting_name,
2445 const ConstString &plugin_type_name,
2446 GetDebuggerPropertyForPluginsPtr get_debugger_property =
2447 GetDebuggerPropertyForPlugins) {
2448 lldb::OptionValuePropertiesSP properties_sp;
2449 lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property(
2450 debugger, plugin_type_name,
2451 ConstString(), // not creating to so we don't need the description
2452 false));
2453 if (plugin_type_properties_sp)
2454 properties_sp =
2455 plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
2456 return properties_sp;
Greg Claytone8cd0c92012-10-19 18:02:49 +00002457}
2458
Kate Stoneb9c1b512016-09-06 20:57:50 +00002459bool CreateSettingForPlugin(
2460 Debugger &debugger, const ConstString &plugin_type_name,
2461 const ConstString &plugin_type_desc,
2462 const lldb::OptionValuePropertiesSP &properties_sp,
2463 const ConstString &description, bool is_global_property,
2464 GetDebuggerPropertyForPluginsPtr get_debugger_property =
2465 GetDebuggerPropertyForPlugins) {
2466 if (properties_sp) {
2467 lldb::OptionValuePropertiesSP plugin_type_properties_sp(
2468 get_debugger_property(debugger, plugin_type_name, plugin_type_desc,
2469 true));
2470 if (plugin_type_properties_sp) {
2471 plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
2472 description, is_global_property,
2473 properties_sp);
2474 return true;
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002475 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002476 }
2477 return false;
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002478}
2479
Kate Stoneb9c1b512016-09-06 20:57:50 +00002480const char *kDynamicLoaderPluginName("dynamic-loader");
2481const char *kPlatformPluginName("platform");
2482const char *kProcessPluginName("process");
2483const char *kSymbolFilePluginName("symbol-file");
2484const char *kJITLoaderPluginName("jit-loader");
2485const char *kStructuredDataPluginName("structured-data");
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002486
Eugene Zelenko89183722016-03-11 21:55:47 +00002487} // anonymous namespace
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002488
Kate Stoneb9c1b512016-09-06 20:57:50 +00002489lldb::OptionValuePropertiesSP PluginManager::GetSettingForDynamicLoaderPlugin(
2490 Debugger &debugger, const ConstString &setting_name) {
2491 return GetSettingForPlugin(debugger, setting_name,
2492 ConstString(kDynamicLoaderPluginName));
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002493}
2494
Kate Stoneb9c1b512016-09-06 20:57:50 +00002495bool PluginManager::CreateSettingForDynamicLoaderPlugin(
2496 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2497 const ConstString &description, bool is_global_property) {
2498 return CreateSettingForPlugin(
2499 debugger, ConstString(kDynamicLoaderPluginName),
2500 ConstString("Settings for dynamic loader plug-ins"), properties_sp,
2501 description, is_global_property);
Greg Claytone8cd0c92012-10-19 18:02:49 +00002502}
2503
Jason Molenda9b837a12013-04-05 05:06:39 +00002504lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002505PluginManager::GetSettingForPlatformPlugin(Debugger &debugger,
2506 const ConstString &setting_name) {
2507 return GetSettingForPlugin(debugger, setting_name,
2508 ConstString(kPlatformPluginName),
2509 GetDebuggerPropertyForPluginsOldStyle);
Jason Molenda9b837a12013-04-05 05:06:39 +00002510}
2511
Kate Stoneb9c1b512016-09-06 20:57:50 +00002512bool PluginManager::CreateSettingForPlatformPlugin(
2513 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2514 const ConstString &description, bool is_global_property) {
2515 return CreateSettingForPlugin(debugger, ConstString(kPlatformPluginName),
2516 ConstString("Settings for platform plug-ins"),
2517 properties_sp, description, is_global_property,
2518 GetDebuggerPropertyForPluginsOldStyle);
Greg Clayton7f982402013-07-15 22:54:20 +00002519}
2520
Greg Clayton7f982402013-07-15 22:54:20 +00002521lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002522PluginManager::GetSettingForProcessPlugin(Debugger &debugger,
2523 const ConstString &setting_name) {
2524 return GetSettingForPlugin(debugger, setting_name,
2525 ConstString(kProcessPluginName));
Greg Clayton7f982402013-07-15 22:54:20 +00002526}
2527
Kate Stoneb9c1b512016-09-06 20:57:50 +00002528bool PluginManager::CreateSettingForProcessPlugin(
2529 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2530 const ConstString &description, bool is_global_property) {
2531 return CreateSettingForPlugin(debugger, ConstString(kProcessPluginName),
2532 ConstString("Settings for process plug-ins"),
2533 properties_sp, description, is_global_property);
Jason Molenda9b837a12013-04-05 05:06:39 +00002534}
2535
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002536lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002537PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger,
2538 const ConstString &setting_name) {
2539 return GetSettingForPlugin(debugger, setting_name,
2540 ConstString(kSymbolFilePluginName));
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002541}
2542
Kate Stoneb9c1b512016-09-06 20:57:50 +00002543bool PluginManager::CreateSettingForSymbolFilePlugin(
2544 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2545 const ConstString &description, bool is_global_property) {
2546 return CreateSettingForPlugin(
2547 debugger, ConstString(kSymbolFilePluginName),
2548 ConstString("Settings for symbol file plug-ins"), properties_sp,
2549 description, is_global_property);
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002550}
2551
2552lldb::OptionValuePropertiesSP
Kate Stoneb9c1b512016-09-06 20:57:50 +00002553PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger,
2554 const ConstString &setting_name) {
2555 return GetSettingForPlugin(debugger, setting_name,
2556 ConstString(kJITLoaderPluginName));
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002557}
2558
Kate Stoneb9c1b512016-09-06 20:57:50 +00002559bool PluginManager::CreateSettingForJITLoaderPlugin(
2560 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2561 const ConstString &description, bool is_global_property) {
2562 return CreateSettingForPlugin(debugger, ConstString(kJITLoaderPluginName),
2563 ConstString("Settings for JIT loader plug-ins"),
2564 properties_sp, description, is_global_property);
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002565}
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002566
2567static const char *kOperatingSystemPluginName("os");
2568
Kate Stoneb9c1b512016-09-06 20:57:50 +00002569lldb::OptionValuePropertiesSP PluginManager::GetSettingForOperatingSystemPlugin(
2570 Debugger &debugger, const ConstString &setting_name) {
2571 lldb::OptionValuePropertiesSP properties_sp;
2572 lldb::OptionValuePropertiesSP plugin_type_properties_sp(
2573 GetDebuggerPropertyForPlugins(
2574 debugger, ConstString(kOperatingSystemPluginName),
2575 ConstString(), // not creating to so we don't need the description
2576 false));
2577 if (plugin_type_properties_sp)
2578 properties_sp =
2579 plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
2580 return properties_sp;
2581}
2582
2583bool PluginManager::CreateSettingForOperatingSystemPlugin(
2584 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2585 const ConstString &description, bool is_global_property) {
2586 if (properties_sp) {
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002587 lldb::OptionValuePropertiesSP plugin_type_properties_sp(
Kate Stoneb9c1b512016-09-06 20:57:50 +00002588 GetDebuggerPropertyForPlugins(
2589 debugger, ConstString(kOperatingSystemPluginName),
2590 ConstString("Settings for operating system plug-ins"), true));
2591 if (plugin_type_properties_sp) {
2592 plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
2593 description, is_global_property,
2594 properties_sp);
2595 return true;
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002596 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002597 }
2598 return false;
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002599}
Todd Fiala75930012016-08-19 04:21:48 +00002600
Kate Stoneb9c1b512016-09-06 20:57:50 +00002601lldb::OptionValuePropertiesSP PluginManager::GetSettingForStructuredDataPlugin(
2602 Debugger &debugger, const ConstString &setting_name) {
2603 return GetSettingForPlugin(debugger, setting_name,
2604 ConstString(kStructuredDataPluginName));
Todd Fiala75930012016-08-19 04:21:48 +00002605}
2606
Kate Stoneb9c1b512016-09-06 20:57:50 +00002607bool PluginManager::CreateSettingForStructuredDataPlugin(
2608 Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
2609 const ConstString &description, bool is_global_property) {
2610 return CreateSettingForPlugin(
2611 debugger, ConstString(kStructuredDataPluginName),
2612 ConstString("Settings for structured data plug-ins"), properties_sp,
2613 description, is_global_property);
Todd Fiala75930012016-08-19 04:21:48 +00002614}