blob: 7bf4348fafba4db4ab74cd17485d8c7fa6d8caf0 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- PluginManager.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/PluginManager.h"
11
Stephen Wilson8acdbb82011-04-08 13:36:44 +000012#include <limits.h>
13
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include <string>
15#include <vector>
16
Greg Claytone8cd0c92012-10-19 18:02:49 +000017#include "lldb/Core/Debugger.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000018#include "lldb/Core/Error.h"
Greg Clayton53239f02011-02-08 05:05:52 +000019#include "lldb/Host/FileSpec.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000020#include "lldb/Host/Host.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000021#include "lldb/Host/HostInfo.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000022#include "lldb/Host/Mutex.h"
Greg Claytone8cd0c92012-10-19 18:02:49 +000023#include "lldb/Interpreter/OptionValueProperties.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000024
Greg Claytonab65b342011-04-13 22:47:15 +000025#include "llvm/ADT/StringRef.h"
Zachary Turner58a559c2014-08-27 20:15:09 +000026#include "llvm/Support/DynamicLibrary.h"
Greg Claytonab65b342011-04-13 22:47:15 +000027
Greg Clayton4272cc72011-02-02 02:24:04 +000028using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029using namespace lldb_private;
30
Jason Molenda743e86a2010-06-11 23:44:18 +000031enum PluginAction
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032{
33 ePluginRegisterInstance,
34 ePluginUnregisterInstance,
35 ePluginGetInstanceAtIndex
36};
37
Greg Clayton03da4cc2013-04-19 21:31:16 +000038
39typedef bool (*PluginInitCallback) (void);
40typedef void (*PluginTermCallback) (void);
41
Greg Clayton4272cc72011-02-02 02:24:04 +000042struct PluginInfo
43{
Zachary Turner58a559c2014-08-27 20:15:09 +000044 PluginInfo()
45 : plugin_init_callback(nullptr), plugin_term_callback(nullptr)
46 {
47 }
48
49 llvm::sys::DynamicLibrary library;
Greg Clayton03da4cc2013-04-19 21:31:16 +000050 PluginInitCallback plugin_init_callback;
51 PluginTermCallback plugin_term_callback;
Greg Clayton4272cc72011-02-02 02:24:04 +000052};
53
54typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
55
56static Mutex &
57GetPluginMapMutex ()
58{
59 static Mutex g_plugin_map_mutex (Mutex::eMutexTypeRecursive);
60 return g_plugin_map_mutex;
61}
62
63static PluginTerminateMap &
64GetPluginMap ()
65{
66 static PluginTerminateMap g_plugin_map;
67 return g_plugin_map;
68}
69
70static bool
71PluginIsLoaded (const FileSpec &plugin_file_spec)
72{
73 Mutex::Locker locker (GetPluginMapMutex ());
74 PluginTerminateMap &plugin_map = GetPluginMap ();
75 return plugin_map.find (plugin_file_spec) != plugin_map.end();
76}
77
78static void
79SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
80{
81 Mutex::Locker locker (GetPluginMapMutex ());
82 PluginTerminateMap &plugin_map = GetPluginMap ();
Michael Sartain3cf443d2013-07-17 00:26:30 +000083 assert (plugin_map.find (plugin_file_spec) == plugin_map.end());
Greg Clayton4272cc72011-02-02 02:24:04 +000084 plugin_map[plugin_file_spec] = plugin_info;
85}
86
David Majnemer5ff02782014-07-22 21:59:22 +000087template <typename FPtrTy>
88static FPtrTy
89CastToFPtr (void *VPtr)
90{
91 return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
92}
Greg Clayton4272cc72011-02-02 02:24:04 +000093
94static FileSpec::EnumerateDirectoryResult
95LoadPluginCallback
96(
97 void *baton,
98 FileSpec::FileType file_type,
99 const FileSpec &file_spec
100)
101{
102// PluginManager *plugin_manager = (PluginManager *)baton;
103 Error error;
104
105 // If we have a regular file, a symbolic link or unknown file type, try
106 // and process the file. We must handle unknown as sometimes the directory
107 // enumeration might be enumerating a file system that doesn't have correct
108 // file type information.
109 if (file_type == FileSpec::eFileTypeRegular ||
110 file_type == FileSpec::eFileTypeSymbolicLink ||
111 file_type == FileSpec::eFileTypeUnknown )
112 {
113 FileSpec plugin_file_spec (file_spec);
114 plugin_file_spec.ResolvePath();
115
116 if (PluginIsLoaded (plugin_file_spec))
117 return FileSpec::eEnumerateDirectoryResultNext;
118 else
119 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000120 PluginInfo plugin_info;
Greg Clayton45319462011-02-08 00:35:34 +0000121
Zachary Turner58a559c2014-08-27 20:15:09 +0000122 std::string pluginLoadError;
123 plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary (plugin_file_spec.GetPath().c_str(), &pluginLoadError);
124 if (plugin_info.library.isValid())
Greg Clayton4272cc72011-02-02 02:24:04 +0000125 {
126 bool success = false;
David Majnemer5ff02782014-07-22 21:59:22 +0000127 plugin_info.plugin_init_callback =
Zachary Turner58a559c2014-08-27 20:15:09 +0000128 CastToFPtr<PluginInitCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
Greg Clayton4272cc72011-02-02 02:24:04 +0000129 if (plugin_info.plugin_init_callback)
130 {
131 // Call the plug-in "bool LLDBPluginInitialize(void)" function
Greg Clayton03da4cc2013-04-19 21:31:16 +0000132 success = plugin_info.plugin_init_callback();
Greg Clayton4272cc72011-02-02 02:24:04 +0000133 }
134
135 if (success)
136 {
137 // It is ok for the "LLDBPluginTerminate" symbol to be NULL
David Majnemer5ff02782014-07-22 21:59:22 +0000138 plugin_info.plugin_term_callback =
Zachary Turner58a559c2014-08-27 20:15:09 +0000139 CastToFPtr<PluginTermCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate"));
Greg Clayton4272cc72011-02-02 02:24:04 +0000140 }
141 else
142 {
Zachary Turner58a559c2014-08-27 20:15:09 +0000143 // The initialize function returned FALSE which means the plug-in might not be
144 // compatible, or might be too new or too old, or might not want to run on this
145 // machine. Set it to a default-constructed instance to invalidate it.
146 plugin_info = PluginInfo();
Greg Clayton4272cc72011-02-02 02:24:04 +0000147 }
148
149 // Regardless of success or failure, cache the plug-in load
150 // in our plug-in info so we don't try to load it again and
151 // again.
152 SetPluginInfo (plugin_file_spec, plugin_info);
153
154 return FileSpec::eEnumerateDirectoryResultNext;
155 }
156 }
157 }
158
159 if (file_type == FileSpec::eFileTypeUnknown ||
160 file_type == FileSpec::eFileTypeDirectory ||
161 file_type == FileSpec::eFileTypeSymbolicLink )
162 {
163 // Try and recurse into anything that a directory or symbolic link.
164 // We must also do this for unknown as sometimes the directory enumeration
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000165 // might be enumerating a file system that doesn't have correct file type
Greg Clayton4272cc72011-02-02 02:24:04 +0000166 // information.
167 return FileSpec::eEnumerateDirectoryResultEnter;
168 }
169
170 return FileSpec::eEnumerateDirectoryResultNext;
171}
172
173
174void
175PluginManager::Initialize ()
176{
Greg Clayton1cb64962011-03-24 04:28:38 +0000177#if 1
Greg Clayton4272cc72011-02-02 02:24:04 +0000178 FileSpec dir_spec;
179 const bool find_directories = true;
180 const bool find_files = true;
181 const bool find_other = true;
182 char dir_path[PATH_MAX];
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000183 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec))
Greg Clayton4272cc72011-02-02 02:24:04 +0000184 {
185 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
186 {
187 FileSpec::EnumerateDirectory (dir_path,
188 find_directories,
189 find_files,
190 find_other,
191 LoadPluginCallback,
192 NULL);
193 }
194 }
195
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000196 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
Greg Clayton4272cc72011-02-02 02:24:04 +0000197 {
198 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
199 {
200 FileSpec::EnumerateDirectory (dir_path,
201 find_directories,
202 find_files,
203 find_other,
204 LoadPluginCallback,
205 NULL);
206 }
207 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000208#endif
Greg Clayton4272cc72011-02-02 02:24:04 +0000209}
210
211void
212PluginManager::Terminate ()
213{
214 Mutex::Locker locker (GetPluginMapMutex ());
215 PluginTerminateMap &plugin_map = GetPluginMap ();
216
217 PluginTerminateMap::const_iterator pos, end = plugin_map.end();
218 for (pos = plugin_map.begin(); pos != end; ++pos)
219 {
220 // Call the plug-in "void LLDBPluginTerminate (void)" function if there
221 // is one (if the symbol was not NULL).
Zachary Turner58a559c2014-08-27 20:15:09 +0000222 if (pos->second.library.isValid())
Greg Clayton4272cc72011-02-02 02:24:04 +0000223 {
224 if (pos->second.plugin_term_callback)
Greg Clayton03da4cc2013-04-19 21:31:16 +0000225 pos->second.plugin_term_callback();
Greg Clayton4272cc72011-02-02 02:24:04 +0000226 }
227 }
228 plugin_map.clear();
229}
230
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231
232#pragma mark ABI
233
234
Jason Molenda743e86a2010-06-11 23:44:18 +0000235struct ABIInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236{
237 ABIInstance() :
238 name(),
239 description(),
240 create_callback(NULL)
241 {
242 }
243
Greg Clayton57abc5d2013-05-10 21:47:16 +0000244 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 std::string description;
246 ABICreateInstance create_callback;
247};
248
249typedef std::vector<ABIInstance> ABIInstances;
250
Greg Claytonded470d2011-03-19 01:12:21 +0000251static Mutex &
252GetABIInstancesMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253{
Greg Claytonded470d2011-03-19 01:12:21 +0000254 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
255 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256}
257
Greg Claytonded470d2011-03-19 01:12:21 +0000258static ABIInstances &
259GetABIInstances ()
260{
261 static ABIInstances g_instances;
262 return g_instances;
263}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264
265bool
266PluginManager::RegisterPlugin
Greg Clayton4272cc72011-02-02 02:24:04 +0000267(
Greg Clayton57abc5d2013-05-10 21:47:16 +0000268 const ConstString &name,
Greg Clayton4272cc72011-02-02 02:24:04 +0000269 const char *description,
270 ABICreateInstance create_callback
271)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272{
273 if (create_callback)
274 {
275 ABIInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000276 assert ((bool)name);
277 instance.name = name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 if (description && description[0])
279 instance.description = description;
280 instance.create_callback = create_callback;
Greg Claytonded470d2011-03-19 01:12:21 +0000281 Mutex::Locker locker (GetABIInstancesMutex ());
282 GetABIInstances ().push_back (instance);
283 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284 }
285 return false;
286}
287
288bool
289PluginManager::UnregisterPlugin (ABICreateInstance create_callback)
290{
291 if (create_callback)
292 {
Greg Claytonded470d2011-03-19 01:12:21 +0000293 Mutex::Locker locker (GetABIInstancesMutex ());
294 ABIInstances &instances = GetABIInstances ();
295
296 ABIInstances::iterator pos, end = instances.end();
297 for (pos = instances.begin(); pos != end; ++ pos)
298 {
299 if (pos->create_callback == create_callback)
300 {
301 instances.erase(pos);
302 return true;
303 }
304 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305 }
306 return false;
307}
308
309ABICreateInstance
310PluginManager::GetABICreateCallbackAtIndex (uint32_t idx)
311{
Greg Claytonded470d2011-03-19 01:12:21 +0000312 Mutex::Locker locker (GetABIInstancesMutex ());
313 ABIInstances &instances = GetABIInstances ();
Greg Claytonded470d2011-03-19 01:12:21 +0000314 if (idx < instances.size())
315 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000316 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317}
318
319ABICreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +0000320PluginManager::GetABICreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000322 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323 {
Greg Claytonded470d2011-03-19 01:12:21 +0000324 Mutex::Locker locker (GetABIInstancesMutex ());
Greg Claytonded470d2011-03-19 01:12:21 +0000325 ABIInstances &instances = GetABIInstances ();
326
327 ABIInstances::iterator pos, end = instances.end();
328 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000330 if (name == pos->name)
Greg Claytonded470d2011-03-19 01:12:21 +0000331 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332 }
333 }
334 return NULL;
335}
336
337
338#pragma mark Disassembler
339
340
Jason Molenda743e86a2010-06-11 23:44:18 +0000341struct DisassemblerInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342{
343 DisassemblerInstance() :
344 name(),
345 description(),
346 create_callback(NULL)
347 {
348 }
349
Greg Clayton57abc5d2013-05-10 21:47:16 +0000350 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 std::string description;
352 DisassemblerCreateInstance create_callback;
353};
354
355typedef std::vector<DisassemblerInstance> DisassemblerInstances;
356
Greg Claytonab65b342011-04-13 22:47:15 +0000357static Mutex &
358GetDisassemblerMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359{
Greg Claytonab65b342011-04-13 22:47:15 +0000360 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
361 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
Greg Claytonab65b342011-04-13 22:47:15 +0000364static DisassemblerInstances &
365GetDisassemblerInstances ()
366{
367 static DisassemblerInstances g_instances;
368 return g_instances;
369}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370
371bool
372PluginManager::RegisterPlugin
373(
Greg Clayton57abc5d2013-05-10 21:47:16 +0000374 const ConstString &name,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 const char *description,
376 DisassemblerCreateInstance create_callback
377)
378{
379 if (create_callback)
380 {
381 DisassemblerInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000382 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 instance.name = name;
384 if (description && description[0])
385 instance.description = description;
386 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000387 Mutex::Locker locker (GetDisassemblerMutex ());
388 GetDisassemblerInstances ().push_back (instance);
389 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 }
391 return false;
392}
393
394bool
395PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback)
396{
397 if (create_callback)
398 {
Greg Claytonab65b342011-04-13 22:47:15 +0000399 Mutex::Locker locker (GetDisassemblerMutex ());
400 DisassemblerInstances &instances = GetDisassemblerInstances ();
401
402 DisassemblerInstances::iterator pos, end = instances.end();
403 for (pos = instances.begin(); pos != end; ++ pos)
404 {
405 if (pos->create_callback == create_callback)
406 {
407 instances.erase(pos);
408 return true;
409 }
410 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 }
412 return false;
413}
414
415DisassemblerCreateInstance
416PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx)
417{
Greg Claytonab65b342011-04-13 22:47:15 +0000418 Mutex::Locker locker (GetDisassemblerMutex ());
419 DisassemblerInstances &instances = GetDisassemblerInstances ();
420 if (idx < instances.size())
421 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000422 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423}
424
425DisassemblerCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +0000426PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000428 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 {
Greg Claytonab65b342011-04-13 22:47:15 +0000430 Mutex::Locker locker (GetDisassemblerMutex ());
431 DisassemblerInstances &instances = GetDisassemblerInstances ();
432
433 DisassemblerInstances::iterator pos, end = instances.end();
434 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000436 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +0000437 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 }
439 }
440 return NULL;
441}
442
443
444
445#pragma mark DynamicLoader
446
447
Jason Molenda743e86a2010-06-11 23:44:18 +0000448struct DynamicLoaderInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449{
450 DynamicLoaderInstance() :
451 name(),
452 description(),
Greg Claytone8cd0c92012-10-19 18:02:49 +0000453 create_callback(NULL),
454 debugger_init_callback (NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
456 }
457
Greg Clayton57abc5d2013-05-10 21:47:16 +0000458 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 std::string description;
460 DynamicLoaderCreateInstance create_callback;
Greg Claytone8cd0c92012-10-19 18:02:49 +0000461 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462};
463
464typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances;
465
Greg Claytonab65b342011-04-13 22:47:15 +0000466
467static Mutex &
468GetDynamicLoaderMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469{
Greg Claytonab65b342011-04-13 22:47:15 +0000470 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
471 return g_instances_mutex;
472}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473
Greg Claytonab65b342011-04-13 22:47:15 +0000474static DynamicLoaderInstances &
475GetDynamicLoaderInstances ()
476{
477 static DynamicLoaderInstances g_instances;
478 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479}
480
481
482bool
483PluginManager::RegisterPlugin
484(
Greg Clayton57abc5d2013-05-10 21:47:16 +0000485 const ConstString &name,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 const char *description,
Greg Claytone8cd0c92012-10-19 18:02:49 +0000487 DynamicLoaderCreateInstance create_callback,
488 DebuggerInitializeCallback debugger_init_callback
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489)
490{
491 if (create_callback)
492 {
493 DynamicLoaderInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000494 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 instance.name = name;
496 if (description && description[0])
497 instance.description = description;
498 instance.create_callback = create_callback;
Greg Claytone8cd0c92012-10-19 18:02:49 +0000499 instance.debugger_init_callback = debugger_init_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000500 Mutex::Locker locker (GetDynamicLoaderMutex ());
501 GetDynamicLoaderInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 }
503 return false;
504}
505
506bool
507PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback)
508{
509 if (create_callback)
510 {
Greg Claytonab65b342011-04-13 22:47:15 +0000511 Mutex::Locker locker (GetDynamicLoaderMutex ());
512 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
513
514 DynamicLoaderInstances::iterator pos, end = instances.end();
515 for (pos = instances.begin(); pos != end; ++ pos)
516 {
517 if (pos->create_callback == create_callback)
518 {
519 instances.erase(pos);
520 return true;
521 }
522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 }
524 return false;
525}
526
527DynamicLoaderCreateInstance
528PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx)
529{
Greg Claytonab65b342011-04-13 22:47:15 +0000530 Mutex::Locker locker (GetDynamicLoaderMutex ());
531 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
532 if (idx < instances.size())
533 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000534 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535}
536
537DynamicLoaderCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +0000538PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000540 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 {
Greg Claytonab65b342011-04-13 22:47:15 +0000542 Mutex::Locker locker (GetDynamicLoaderMutex ());
543 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
544
545 DynamicLoaderInstances::iterator pos, end = instances.end();
546 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000548 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +0000549 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 }
551 }
552 return NULL;
553}
554
Andrew MacPherson17220c12014-03-05 10:12:43 +0000555#pragma mark JITLoader
556
557
558struct JITLoaderInstance
559{
560 JITLoaderInstance() :
561 name(),
562 description(),
563 create_callback(NULL),
564 debugger_init_callback (NULL)
565 {
566 }
567
568 ConstString name;
569 std::string description;
570 JITLoaderCreateInstance create_callback;
571 DebuggerInitializeCallback debugger_init_callback;
572};
573
574typedef std::vector<JITLoaderInstance> JITLoaderInstances;
575
576
577static Mutex &
578GetJITLoaderMutex ()
579{
580 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
581 return g_instances_mutex;
582}
583
584static JITLoaderInstances &
585GetJITLoaderInstances ()
586{
587 static JITLoaderInstances g_instances;
588 return g_instances;
589}
590
591
592bool
593PluginManager::RegisterPlugin
594(
595 const ConstString &name,
596 const char *description,
597 JITLoaderCreateInstance create_callback,
598 DebuggerInitializeCallback debugger_init_callback
599)
600{
601 if (create_callback)
602 {
603 JITLoaderInstance instance;
604 assert ((bool)name);
605 instance.name = name;
606 if (description && description[0])
607 instance.description = description;
608 instance.create_callback = create_callback;
609 instance.debugger_init_callback = debugger_init_callback;
610 Mutex::Locker locker (GetJITLoaderMutex ());
611 GetJITLoaderInstances ().push_back (instance);
612 }
613 return false;
614}
615
616bool
617PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback)
618{
619 if (create_callback)
620 {
621 Mutex::Locker locker (GetJITLoaderMutex ());
622 JITLoaderInstances &instances = GetJITLoaderInstances ();
623
624 JITLoaderInstances::iterator pos, end = instances.end();
625 for (pos = instances.begin(); pos != end; ++ pos)
626 {
627 if (pos->create_callback == create_callback)
628 {
629 instances.erase(pos);
630 return true;
631 }
632 }
633 }
634 return false;
635}
636
637JITLoaderCreateInstance
638PluginManager::GetJITLoaderCreateCallbackAtIndex (uint32_t idx)
639{
640 Mutex::Locker locker (GetJITLoaderMutex ());
641 JITLoaderInstances &instances = GetJITLoaderInstances ();
642 if (idx < instances.size())
643 return instances[idx].create_callback;
644 return NULL;
645}
646
647JITLoaderCreateInstance
648PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name)
649{
650 if (name)
651 {
652 Mutex::Locker locker (GetJITLoaderMutex ());
653 JITLoaderInstances &instances = GetJITLoaderInstances ();
654
655 JITLoaderInstances::iterator pos, end = instances.end();
656 for (pos = instances.begin(); pos != end; ++ pos)
657 {
658 if (name == pos->name)
659 return pos->create_callback;
660 }
661 }
662 return NULL;
663}
664
Greg Claytonf03bbe22011-02-01 01:37:45 +0000665#pragma mark EmulateInstruction
666
667
668struct EmulateInstructionInstance
669{
670 EmulateInstructionInstance() :
671 name(),
672 description(),
673 create_callback(NULL)
674 {
675 }
676
Greg Clayton57abc5d2013-05-10 21:47:16 +0000677 ConstString name;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000678 std::string description;
679 EmulateInstructionCreateInstance create_callback;
680};
681
682typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances;
683
Greg Claytonab65b342011-04-13 22:47:15 +0000684static Mutex &
685GetEmulateInstructionMutex ()
Greg Claytonf03bbe22011-02-01 01:37:45 +0000686{
Greg Claytonab65b342011-04-13 22:47:15 +0000687 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
688 return g_instances_mutex;
689}
690
691static EmulateInstructionInstances &
692GetEmulateInstructionInstances ()
693{
694 static EmulateInstructionInstances g_instances;
695 return g_instances;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000696}
697
698
699bool
700PluginManager::RegisterPlugin
701(
Greg Clayton57abc5d2013-05-10 21:47:16 +0000702 const ConstString &name,
Greg Clayton4272cc72011-02-02 02:24:04 +0000703 const char *description,
704 EmulateInstructionCreateInstance create_callback
705)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000706{
707 if (create_callback)
708 {
709 EmulateInstructionInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000710 assert ((bool)name);
Greg Claytonf03bbe22011-02-01 01:37:45 +0000711 instance.name = name;
712 if (description && description[0])
713 instance.description = description;
714 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000715 Mutex::Locker locker (GetEmulateInstructionMutex ());
716 GetEmulateInstructionInstances ().push_back (instance);
Greg Claytonf03bbe22011-02-01 01:37:45 +0000717 }
718 return false;
719}
720
721bool
722PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callback)
723{
724 if (create_callback)
725 {
Greg Claytonab65b342011-04-13 22:47:15 +0000726 Mutex::Locker locker (GetEmulateInstructionMutex ());
727 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
728
729 EmulateInstructionInstances::iterator pos, end = instances.end();
730 for (pos = instances.begin(); pos != end; ++ pos)
731 {
732 if (pos->create_callback == create_callback)
733 {
734 instances.erase(pos);
735 return true;
736 }
737 }
Greg Claytonf03bbe22011-02-01 01:37:45 +0000738 }
739 return false;
740}
741
742EmulateInstructionCreateInstance
743PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx)
744{
Greg Claytonab65b342011-04-13 22:47:15 +0000745 Mutex::Locker locker (GetEmulateInstructionMutex ());
746 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
747 if (idx < instances.size())
748 return instances[idx].create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000749 return NULL;
750}
751
752EmulateInstructionCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +0000753PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstString &name)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000754{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000755 if (name)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000756 {
Greg Claytonab65b342011-04-13 22:47:15 +0000757 Mutex::Locker locker (GetEmulateInstructionMutex ());
758 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
759
760 EmulateInstructionInstances::iterator pos, end = instances.end();
761 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000762 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000763 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +0000764 return pos->create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000765 }
766 }
767 return NULL;
768}
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000769#pragma mark OperatingSystem
770
771
772struct OperatingSystemInstance
773{
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000774 OperatingSystemInstance () :
775 name (),
776 description (),
777 create_callback (nullptr),
778 debugger_init_callback (nullptr)
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000779 {
780 }
781
Greg Clayton57abc5d2013-05-10 21:47:16 +0000782 ConstString name;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000783 std::string description;
784 OperatingSystemCreateInstance create_callback;
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000785 DebuggerInitializeCallback debugger_init_callback;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000786};
787
788typedef std::vector<OperatingSystemInstance> OperatingSystemInstances;
789
790static Mutex &
791GetOperatingSystemMutex ()
792{
793 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
794 return g_instances_mutex;
795}
796
797static OperatingSystemInstances &
798GetOperatingSystemInstances ()
799{
800 static OperatingSystemInstances g_instances;
801 return g_instances;
802}
803
804bool
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000805PluginManager::RegisterPlugin(const ConstString &name, const char *description,
806 OperatingSystemCreateInstance create_callback,
807 DebuggerInitializeCallback debugger_init_callback)
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000808{
809 if (create_callback)
810 {
811 OperatingSystemInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000812 assert ((bool)name);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000813 instance.name = name;
814 if (description && description[0])
815 instance.description = description;
816 instance.create_callback = create_callback;
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000817 instance.debugger_init_callback = debugger_init_callback;
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000818 Mutex::Locker locker (GetOperatingSystemMutex ());
819 GetOperatingSystemInstances ().push_back (instance);
820 }
821 return false;
822}
823
824bool
825PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback)
826{
827 if (create_callback)
828 {
829 Mutex::Locker locker (GetOperatingSystemMutex ());
830 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
831
832 OperatingSystemInstances::iterator pos, end = instances.end();
833 for (pos = instances.begin(); pos != end; ++ pos)
834 {
835 if (pos->create_callback == create_callback)
836 {
837 instances.erase(pos);
838 return true;
839 }
840 }
841 }
842 return false;
843}
844
845OperatingSystemCreateInstance
846PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx)
847{
848 Mutex::Locker locker (GetOperatingSystemMutex ());
849 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
850 if (idx < instances.size())
851 return instances[idx].create_callback;
852 return NULL;
853}
854
855OperatingSystemCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +0000856PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString &name)
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000857{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000858 if (name)
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000859 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000860 Mutex::Locker locker (GetOperatingSystemMutex ());
861 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
862
863 OperatingSystemInstances::iterator pos, end = instances.end();
864 for (pos = instances.begin(); pos != end; ++ pos)
865 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000866 if (name == pos->name)
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000867 return pos->create_callback;
868 }
869 }
870 return NULL;
871}
Greg Claytonf03bbe22011-02-01 01:37:45 +0000872
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873
Enrico Granata5f9d3102015-08-27 21:33:50 +0000874#pragma mark Language
875
876
877struct LanguageInstance
878{
879 LanguageInstance() :
880 name(),
881 description(),
882 create_callback(NULL)
883 {
884 }
885
886 ConstString name;
887 std::string description;
888 LanguageCreateInstance create_callback;
889};
890
891typedef std::vector<LanguageInstance> LanguageInstances;
892
893static Mutex &
894GetLanguageMutex ()
895{
896 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
897 return g_instances_mutex;
898}
899
900static LanguageInstances &
901GetLanguageInstances ()
902{
903 static LanguageInstances g_instances;
904 return g_instances;
905}
906
907bool
908PluginManager::RegisterPlugin
909(
910 const ConstString &name,
911 const char *description,
912 LanguageCreateInstance create_callback
913 )
914{
915 if (create_callback)
916 {
917 LanguageInstance instance;
918 assert ((bool)name);
919 instance.name = name;
920 if (description && description[0])
921 instance.description = description;
922 instance.create_callback = create_callback;
923 Mutex::Locker locker (GetLanguageMutex ());
924 GetLanguageInstances ().push_back (instance);
925 }
926 return false;
927}
928
929bool
930PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback)
931{
932 if (create_callback)
933 {
934 Mutex::Locker locker (GetLanguageMutex ());
935 LanguageInstances &instances = GetLanguageInstances ();
936
937 LanguageInstances::iterator pos, end = instances.end();
938 for (pos = instances.begin(); pos != end; ++ pos)
939 {
940 if (pos->create_callback == create_callback)
941 {
942 instances.erase(pos);
943 return true;
944 }
945 }
946 }
947 return false;
948}
949
950LanguageCreateInstance
951PluginManager::GetLanguageCreateCallbackAtIndex (uint32_t idx)
952{
953 Mutex::Locker locker (GetLanguageMutex ());
954 LanguageInstances &instances = GetLanguageInstances ();
955 if (idx < instances.size())
956 return instances[idx].create_callback;
957 return NULL;
958}
959
960LanguageCreateInstance
961PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name)
962{
963 if (name)
964 {
965 Mutex::Locker locker (GetLanguageMutex ());
966 LanguageInstances &instances = GetLanguageInstances ();
967
968 LanguageInstances::iterator pos, end = instances.end();
969 for (pos = instances.begin(); pos != end; ++ pos)
970 {
971 if (name == pos->name)
972 return pos->create_callback;
973 }
974 }
975 return NULL;
976}
977
978
Jim Ingham22777012010-09-23 02:01:19 +0000979#pragma mark LanguageRuntime
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980
981
Jim Ingham22777012010-09-23 02:01:19 +0000982struct LanguageRuntimeInstance
983{
984 LanguageRuntimeInstance() :
985 name(),
986 description(),
987 create_callback(NULL)
988 {
989 }
990
Greg Clayton57abc5d2013-05-10 21:47:16 +0000991 ConstString name;
Jim Ingham22777012010-09-23 02:01:19 +0000992 std::string description;
993 LanguageRuntimeCreateInstance create_callback;
Colin Rileyc9c55a22015-05-04 18:39:38 +0000994 LanguageRuntimeGetCommandObject command_callback;
Jim Ingham22777012010-09-23 02:01:19 +0000995};
996
997typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances;
998
Greg Claytonab65b342011-04-13 22:47:15 +0000999static Mutex &
1000GetLanguageRuntimeMutex ()
Jim Ingham22777012010-09-23 02:01:19 +00001001{
Greg Claytonab65b342011-04-13 22:47:15 +00001002 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1003 return g_instances_mutex;
Jim Ingham22777012010-09-23 02:01:19 +00001004}
1005
Greg Claytonab65b342011-04-13 22:47:15 +00001006static LanguageRuntimeInstances &
1007GetLanguageRuntimeInstances ()
1008{
1009 static LanguageRuntimeInstances g_instances;
1010 return g_instances;
1011}
Jim Ingham22777012010-09-23 02:01:19 +00001012
1013bool
1014PluginManager::RegisterPlugin
Greg Clayton4272cc72011-02-02 02:24:04 +00001015(
Greg Clayton57abc5d2013-05-10 21:47:16 +00001016 const ConstString &name,
Greg Clayton4272cc72011-02-02 02:24:04 +00001017 const char *description,
Colin Rileyc9c55a22015-05-04 18:39:38 +00001018 LanguageRuntimeCreateInstance create_callback,
1019 LanguageRuntimeGetCommandObject command_callback
Greg Clayton4272cc72011-02-02 02:24:04 +00001020)
Jim Ingham22777012010-09-23 02:01:19 +00001021{
1022 if (create_callback)
1023 {
1024 LanguageRuntimeInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001025 assert ((bool)name);
Jim Ingham22777012010-09-23 02:01:19 +00001026 instance.name = name;
1027 if (description && description[0])
1028 instance.description = description;
1029 instance.create_callback = create_callback;
Colin Rileyc9c55a22015-05-04 18:39:38 +00001030 instance.command_callback = command_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001031 Mutex::Locker locker (GetLanguageRuntimeMutex ());
1032 GetLanguageRuntimeInstances ().push_back (instance);
Jim Ingham22777012010-09-23 02:01:19 +00001033 }
1034 return false;
1035}
1036
1037bool
1038PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback)
1039{
1040 if (create_callback)
1041 {
Greg Claytonab65b342011-04-13 22:47:15 +00001042 Mutex::Locker locker (GetLanguageRuntimeMutex ());
1043 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
1044
1045 LanguageRuntimeInstances::iterator pos, end = instances.end();
1046 for (pos = instances.begin(); pos != end; ++ pos)
1047 {
1048 if (pos->create_callback == create_callback)
1049 {
1050 instances.erase(pos);
1051 return true;
1052 }
1053 }
Jim Ingham22777012010-09-23 02:01:19 +00001054 }
1055 return false;
1056}
1057
1058LanguageRuntimeCreateInstance
1059PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx)
1060{
Greg Claytonab65b342011-04-13 22:47:15 +00001061 Mutex::Locker locker (GetLanguageRuntimeMutex ());
1062 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
1063 if (idx < instances.size())
1064 return instances[idx].create_callback;
Jim Ingham22777012010-09-23 02:01:19 +00001065 return NULL;
1066}
1067
Colin Rileyc9c55a22015-05-04 18:39:38 +00001068LanguageRuntimeGetCommandObject
1069PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex (uint32_t idx)
1070{
1071 Mutex::Locker locker (GetLanguageRuntimeMutex ());
1072 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
1073 if (idx < instances.size())
1074 return instances[idx].command_callback;
1075 return NULL;
1076}
1077
Jim Ingham22777012010-09-23 02:01:19 +00001078LanguageRuntimeCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001079PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString &name)
Jim Ingham22777012010-09-23 02:01:19 +00001080{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001081 if (name)
Jim Ingham22777012010-09-23 02:01:19 +00001082 {
Greg Claytonab65b342011-04-13 22:47:15 +00001083 Mutex::Locker locker (GetLanguageRuntimeMutex ());
1084 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
1085
1086 LanguageRuntimeInstances::iterator pos, end = instances.end();
1087 for (pos = instances.begin(); pos != end; ++ pos)
Jim Ingham22777012010-09-23 02:01:19 +00001088 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001089 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00001090 return pos->create_callback;
Jim Ingham22777012010-09-23 02:01:19 +00001091 }
1092 }
1093 return NULL;
1094}
1095
Jason Molendaeef51062013-11-05 03:57:19 +00001096#pragma mark SystemRuntime
1097
1098
1099struct SystemRuntimeInstance
1100{
1101 SystemRuntimeInstance() :
1102 name(),
1103 description(),
1104 create_callback(NULL)
1105 {
1106 }
1107
1108 ConstString name;
1109 std::string description;
1110 SystemRuntimeCreateInstance create_callback;
1111};
1112
1113typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances;
1114
1115static Mutex &
1116GetSystemRuntimeMutex ()
1117{
1118 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1119 return g_instances_mutex;
1120}
1121
1122static SystemRuntimeInstances &
1123GetSystemRuntimeInstances ()
1124{
1125 static SystemRuntimeInstances g_instances;
1126 return g_instances;
1127}
1128
1129bool
1130PluginManager::RegisterPlugin
1131(
1132 const ConstString &name,
1133 const char *description,
1134 SystemRuntimeCreateInstance create_callback
1135)
1136{
1137 if (create_callback)
1138 {
1139 SystemRuntimeInstance instance;
1140 assert ((bool)name);
1141 instance.name = name;
1142 if (description && description[0])
1143 instance.description = description;
1144 instance.create_callback = create_callback;
1145 Mutex::Locker locker (GetSystemRuntimeMutex ());
1146 GetSystemRuntimeInstances ().push_back (instance);
1147 }
1148 return false;
1149}
1150
1151bool
1152PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback)
1153{
1154 if (create_callback)
1155 {
1156 Mutex::Locker locker (GetSystemRuntimeMutex ());
1157 SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
1158
1159 SystemRuntimeInstances::iterator pos, end = instances.end();
1160 for (pos = instances.begin(); pos != end; ++ pos)
1161 {
1162 if (pos->create_callback == create_callback)
1163 {
1164 instances.erase(pos);
1165 return true;
1166 }
1167 }
1168 }
1169 return false;
1170}
1171
1172SystemRuntimeCreateInstance
1173PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx)
1174{
1175 Mutex::Locker locker (GetSystemRuntimeMutex ());
1176 SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
1177 if (idx < instances.size())
1178 return instances[idx].create_callback;
1179 return NULL;
1180}
1181
1182SystemRuntimeCreateInstance
1183PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name)
1184{
1185 if (name)
1186 {
1187 Mutex::Locker locker (GetSystemRuntimeMutex ());
1188 SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
1189
1190 SystemRuntimeInstances::iterator pos, end = instances.end();
1191 for (pos = instances.begin(); pos != end; ++ pos)
1192 {
1193 if (name == pos->name)
1194 return pos->create_callback;
1195 }
1196 }
1197 return NULL;
1198}
1199
1200
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201#pragma mark ObjectFile
1202
Jason Molenda743e86a2010-06-11 23:44:18 +00001203struct ObjectFileInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204{
1205 ObjectFileInstance() :
1206 name(),
1207 description(),
Greg Claytonf4d6de62013-04-24 22:29:28 +00001208 create_callback(NULL),
1209 create_memory_callback (NULL),
Greg Claytona2715cf2014-06-13 00:54:12 +00001210 get_module_specifications (NULL),
1211 save_core (NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
1213 }
1214
Greg Clayton57abc5d2013-05-10 21:47:16 +00001215 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 std::string description;
1217 ObjectFileCreateInstance create_callback;
Greg Claytonc9660542012-02-05 02:38:54 +00001218 ObjectFileCreateMemoryInstance create_memory_callback;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001219 ObjectFileGetModuleSpecifications get_module_specifications;
Greg Claytona2715cf2014-06-13 00:54:12 +00001220 ObjectFileSaveCore save_core;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001221};
1222
1223typedef std::vector<ObjectFileInstance> ObjectFileInstances;
1224
Greg Claytonab65b342011-04-13 22:47:15 +00001225static Mutex &
1226GetObjectFileMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227{
Greg Claytonab65b342011-04-13 22:47:15 +00001228 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1229 return g_instances_mutex;
1230}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001231
Greg Claytonab65b342011-04-13 22:47:15 +00001232static ObjectFileInstances &
1233GetObjectFileInstances ()
1234{
1235 static ObjectFileInstances g_instances;
1236 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001237}
1238
1239
1240bool
Greg Clayton57abc5d2013-05-10 21:47:16 +00001241PluginManager::RegisterPlugin (const ConstString &name,
Greg Claytonf4d6de62013-04-24 22:29:28 +00001242 const char *description,
1243 ObjectFileCreateInstance create_callback,
1244 ObjectFileCreateMemoryInstance create_memory_callback,
Greg Claytona2715cf2014-06-13 00:54:12 +00001245 ObjectFileGetModuleSpecifications get_module_specifications,
1246 ObjectFileSaveCore save_core)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247{
1248 if (create_callback)
1249 {
1250 ObjectFileInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001251 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 instance.name = name;
1253 if (description && description[0])
1254 instance.description = description;
1255 instance.create_callback = create_callback;
Greg Claytonc9660542012-02-05 02:38:54 +00001256 instance.create_memory_callback = create_memory_callback;
Greg Claytona2715cf2014-06-13 00:54:12 +00001257 instance.save_core = save_core;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001258 instance.get_module_specifications = get_module_specifications;
Greg Claytonab65b342011-04-13 22:47:15 +00001259 Mutex::Locker locker (GetObjectFileMutex ());
1260 GetObjectFileInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 }
1262 return false;
1263}
1264
1265bool
1266PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback)
1267{
1268 if (create_callback)
1269 {
Greg Claytonab65b342011-04-13 22:47:15 +00001270 Mutex::Locker locker (GetObjectFileMutex ());
1271 ObjectFileInstances &instances = GetObjectFileInstances ();
1272
1273 ObjectFileInstances::iterator pos, end = instances.end();
1274 for (pos = instances.begin(); pos != end; ++ pos)
1275 {
1276 if (pos->create_callback == create_callback)
1277 {
1278 instances.erase(pos);
1279 return true;
1280 }
1281 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 }
1283 return false;
1284}
1285
1286ObjectFileCreateInstance
1287PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx)
1288{
Greg Claytonab65b342011-04-13 22:47:15 +00001289 Mutex::Locker locker (GetObjectFileMutex ());
1290 ObjectFileInstances &instances = GetObjectFileInstances ();
1291 if (idx < instances.size())
1292 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001293 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294}
Greg Claytonab65b342011-04-13 22:47:15 +00001295
Greg Claytonc9660542012-02-05 02:38:54 +00001296
1297ObjectFileCreateMemoryInstance
1298PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx)
1299{
1300 Mutex::Locker locker (GetObjectFileMutex ());
1301 ObjectFileInstances &instances = GetObjectFileInstances ();
1302 if (idx < instances.size())
1303 return instances[idx].create_memory_callback;
1304 return NULL;
1305}
1306
Greg Claytonf4d6de62013-04-24 22:29:28 +00001307ObjectFileGetModuleSpecifications
1308PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
1309{
1310 Mutex::Locker locker (GetObjectFileMutex ());
1311 ObjectFileInstances &instances = GetObjectFileInstances ();
1312 if (idx < instances.size())
1313 return instances[idx].get_module_specifications;
1314 return NULL;
1315}
1316
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317ObjectFileCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001318PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001320 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 {
Greg Claytonab65b342011-04-13 22:47:15 +00001322 Mutex::Locker locker (GetObjectFileMutex ());
1323 ObjectFileInstances &instances = GetObjectFileInstances ();
1324
1325 ObjectFileInstances::iterator pos, end = instances.end();
1326 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001328 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00001329 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 }
1331 }
1332 return NULL;
1333}
1334
1335
Greg Claytonc9660542012-02-05 02:38:54 +00001336ObjectFileCreateMemoryInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001337PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString &name)
Greg Claytonc9660542012-02-05 02:38:54 +00001338{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001339 if (name)
Greg Claytonc9660542012-02-05 02:38:54 +00001340 {
Greg Claytonc9660542012-02-05 02:38:54 +00001341 Mutex::Locker locker (GetObjectFileMutex ());
1342 ObjectFileInstances &instances = GetObjectFileInstances ();
1343
1344 ObjectFileInstances::iterator pos, end = instances.end();
1345 for (pos = instances.begin(); pos != end; ++ pos)
1346 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001347 if (name == pos->name)
Greg Claytonc9660542012-02-05 02:38:54 +00001348 return pos->create_memory_callback;
1349 }
1350 }
1351 return NULL;
1352}
1353
Greg Claytona2715cf2014-06-13 00:54:12 +00001354Error
1355PluginManager::SaveCore (const lldb::ProcessSP &process_sp, const FileSpec &outfile)
1356{
1357 Error error;
1358 Mutex::Locker locker (GetObjectFileMutex ());
1359 ObjectFileInstances &instances = GetObjectFileInstances ();
1360
1361 ObjectFileInstances::iterator pos, end = instances.end();
1362 for (pos = instances.begin(); pos != end; ++ pos)
1363 {
1364 if (pos->save_core && pos->save_core (process_sp, outfile, error))
1365 return error;
1366 }
1367 error.SetErrorString("no ObjectFile plugins were able to save a core for this process");
1368 return error;
1369}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001370
1371#pragma mark ObjectContainer
1372
Jason Molenda743e86a2010-06-11 23:44:18 +00001373struct ObjectContainerInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374{
1375 ObjectContainerInstance() :
1376 name(),
1377 description(),
Greg Claytonf4d6de62013-04-24 22:29:28 +00001378 create_callback (NULL),
1379 get_module_specifications (NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380 {
1381 }
1382
Greg Clayton57abc5d2013-05-10 21:47:16 +00001383 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 std::string description;
1385 ObjectContainerCreateInstance create_callback;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001386 ObjectFileGetModuleSpecifications get_module_specifications;
1387
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388};
1389
1390typedef std::vector<ObjectContainerInstance> ObjectContainerInstances;
1391
Greg Claytonab65b342011-04-13 22:47:15 +00001392static Mutex &
1393GetObjectContainerMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394{
Greg Claytonab65b342011-04-13 22:47:15 +00001395 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1396 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397}
1398
Greg Claytonab65b342011-04-13 22:47:15 +00001399static ObjectContainerInstances &
1400GetObjectContainerInstances ()
1401{
1402 static ObjectContainerInstances g_instances;
1403 return g_instances;
1404}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405
1406bool
Greg Clayton57abc5d2013-05-10 21:47:16 +00001407PluginManager::RegisterPlugin (const ConstString &name,
Greg Claytonf4d6de62013-04-24 22:29:28 +00001408 const char *description,
1409 ObjectContainerCreateInstance create_callback,
1410 ObjectFileGetModuleSpecifications get_module_specifications)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411{
1412 if (create_callback)
1413 {
1414 ObjectContainerInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001415 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 instance.name = name;
1417 if (description && description[0])
1418 instance.description = description;
1419 instance.create_callback = create_callback;
Greg Claytonf4d6de62013-04-24 22:29:28 +00001420 instance.get_module_specifications = get_module_specifications;
Greg Claytonab65b342011-04-13 22:47:15 +00001421 Mutex::Locker locker (GetObjectContainerMutex ());
1422 GetObjectContainerInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423 }
1424 return false;
1425}
1426
1427bool
1428PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback)
1429{
1430 if (create_callback)
1431 {
Greg Claytonab65b342011-04-13 22:47:15 +00001432 Mutex::Locker locker (GetObjectContainerMutex ());
1433 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1434
1435 ObjectContainerInstances::iterator pos, end = instances.end();
1436 for (pos = instances.begin(); pos != end; ++ pos)
1437 {
1438 if (pos->create_callback == create_callback)
1439 {
1440 instances.erase(pos);
1441 return true;
1442 }
1443 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 }
1445 return false;
1446}
1447
1448ObjectContainerCreateInstance
1449PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx)
1450{
Greg Claytonab65b342011-04-13 22:47:15 +00001451 Mutex::Locker locker (GetObjectContainerMutex ());
1452 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1453 if (idx < instances.size())
1454 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001455 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001456}
Greg Claytonab65b342011-04-13 22:47:15 +00001457
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458ObjectContainerCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001459PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001461 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462 {
Greg Claytonab65b342011-04-13 22:47:15 +00001463 Mutex::Locker locker (GetObjectContainerMutex ());
1464 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1465
1466 ObjectContainerInstances::iterator pos, end = instances.end();
1467 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001469 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00001470 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 }
1472 }
1473 return NULL;
1474}
1475
Greg Claytonf4d6de62013-04-24 22:29:28 +00001476ObjectFileGetModuleSpecifications
1477PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
1478{
1479 Mutex::Locker locker (GetObjectContainerMutex ());
1480 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1481 if (idx < instances.size())
1482 return instances[idx].get_module_specifications;
1483 return NULL;
1484}
1485
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486#pragma mark LogChannel
1487
Greg Claytonab65b342011-04-13 22:47:15 +00001488struct LogInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489{
Greg Claytonab65b342011-04-13 22:47:15 +00001490 LogInstance() :
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 name(),
1492 description(),
1493 create_callback(NULL)
1494 {
1495 }
1496
Greg Clayton57abc5d2013-05-10 21:47:16 +00001497 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 std::string description;
1499 LogChannelCreateInstance create_callback;
1500};
1501
Greg Claytonab65b342011-04-13 22:47:15 +00001502typedef std::vector<LogInstance> LogInstances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503
Greg Claytonab65b342011-04-13 22:47:15 +00001504static Mutex &
1505GetLogMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506{
Greg Claytonab65b342011-04-13 22:47:15 +00001507 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1508 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509}
1510
Greg Claytonab65b342011-04-13 22:47:15 +00001511static LogInstances &
1512GetLogInstances ()
1513{
1514 static LogInstances g_instances;
1515 return g_instances;
1516}
1517
1518
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001519
1520bool
1521PluginManager::RegisterPlugin
1522(
Greg Clayton57abc5d2013-05-10 21:47:16 +00001523 const ConstString &name,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001524 const char *description,
1525 LogChannelCreateInstance create_callback
1526)
1527{
1528 if (create_callback)
1529 {
Greg Claytonab65b342011-04-13 22:47:15 +00001530 LogInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001531 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532 instance.name = name;
1533 if (description && description[0])
1534 instance.description = description;
1535 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001536 Mutex::Locker locker (GetLogMutex ());
1537 GetLogInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001538 }
1539 return false;
1540}
1541
1542bool
1543PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback)
1544{
1545 if (create_callback)
1546 {
Greg Claytonab65b342011-04-13 22:47:15 +00001547 Mutex::Locker locker (GetLogMutex ());
1548 LogInstances &instances = GetLogInstances ();
1549
1550 LogInstances::iterator pos, end = instances.end();
1551 for (pos = instances.begin(); pos != end; ++ pos)
1552 {
1553 if (pos->create_callback == create_callback)
1554 {
1555 instances.erase(pos);
1556 return true;
1557 }
1558 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001559 }
1560 return false;
1561}
1562
1563const char *
1564PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx)
1565{
Greg Claytonab65b342011-04-13 22:47:15 +00001566 Mutex::Locker locker (GetLogMutex ());
1567 LogInstances &instances = GetLogInstances ();
1568 if (idx < instances.size())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001569 return instances[idx].name.GetCString();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001570 return NULL;
1571}
1572
1573
1574LogChannelCreateInstance
1575PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx)
1576{
Greg Claytonab65b342011-04-13 22:47:15 +00001577 Mutex::Locker locker (GetLogMutex ());
1578 LogInstances &instances = GetLogInstances ();
1579 if (idx < instances.size())
1580 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001581 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582}
1583
1584LogChannelCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001585PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001586{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001587 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588 {
Greg Claytonab65b342011-04-13 22:47:15 +00001589 Mutex::Locker locker (GetLogMutex ());
1590 LogInstances &instances = GetLogInstances ();
1591
1592 LogInstances::iterator pos, end = instances.end();
1593 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001594 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001595 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00001596 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 }
1598 }
1599 return NULL;
1600}
1601
Greg Claytone996fd32011-03-08 22:40:15 +00001602#pragma mark Platform
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603
Greg Claytone996fd32011-03-08 22:40:15 +00001604struct PlatformInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605{
Greg Claytone996fd32011-03-08 22:40:15 +00001606 PlatformInstance() :
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001607 name(),
1608 description(),
Jason Molenda9b837a12013-04-05 05:06:39 +00001609 create_callback(NULL),
1610 debugger_init_callback (NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611 {
1612 }
Greg Claytone996fd32011-03-08 22:40:15 +00001613
Greg Clayton57abc5d2013-05-10 21:47:16 +00001614 ConstString name;
Greg Claytone996fd32011-03-08 22:40:15 +00001615 std::string description;
1616 PlatformCreateInstance create_callback;
Jason Molenda9b837a12013-04-05 05:06:39 +00001617 DebuggerInitializeCallback debugger_init_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001618};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001619
Greg Claytone996fd32011-03-08 22:40:15 +00001620typedef std::vector<PlatformInstance> PlatformInstances;
1621
Greg Claytonded470d2011-03-19 01:12:21 +00001622static Mutex &
1623GetPlatformInstancesMutex ()
Greg Claytone996fd32011-03-08 22:40:15 +00001624{
Greg Claytonded470d2011-03-19 01:12:21 +00001625 static Mutex g_platform_instances_mutex (Mutex::eMutexTypeRecursive);
1626 return g_platform_instances_mutex;
Greg Claytone996fd32011-03-08 22:40:15 +00001627}
1628
Greg Claytonded470d2011-03-19 01:12:21 +00001629static PlatformInstances &
1630GetPlatformInstances ()
1631{
1632 static PlatformInstances g_platform_instances;
1633 return g_platform_instances;
1634}
Greg Claytone996fd32011-03-08 22:40:15 +00001635
Greg Claytonab65b342011-04-13 22:47:15 +00001636
Greg Claytone996fd32011-03-08 22:40:15 +00001637bool
Greg Clayton57abc5d2013-05-10 21:47:16 +00001638PluginManager::RegisterPlugin (const ConstString &name,
Greg Claytone996fd32011-03-08 22:40:15 +00001639 const char *description,
Jason Molenda9b837a12013-04-05 05:06:39 +00001640 PlatformCreateInstance create_callback,
1641 DebuggerInitializeCallback debugger_init_callback)
Greg Claytone996fd32011-03-08 22:40:15 +00001642{
1643 if (create_callback)
1644 {
Greg Claytonded470d2011-03-19 01:12:21 +00001645 Mutex::Locker locker (GetPlatformInstancesMutex ());
1646
Greg Claytone996fd32011-03-08 22:40:15 +00001647 PlatformInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001648 assert ((bool)name);
Greg Claytone996fd32011-03-08 22:40:15 +00001649 instance.name = name;
1650 if (description && description[0])
1651 instance.description = description;
1652 instance.create_callback = create_callback;
Jason Molenda9b837a12013-04-05 05:06:39 +00001653 instance.debugger_init_callback = debugger_init_callback;
Greg Claytonded470d2011-03-19 01:12:21 +00001654 GetPlatformInstances ().push_back (instance);
1655 return true;
Greg Claytone996fd32011-03-08 22:40:15 +00001656 }
1657 return false;
1658}
1659
Jason Molenda9b837a12013-04-05 05:06:39 +00001660
Greg Claytone996fd32011-03-08 22:40:15 +00001661const char *
1662PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx)
1663{
Greg Claytonded470d2011-03-19 01:12:21 +00001664 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001665 PlatformInstances &instances = GetPlatformInstances ();
1666 if (idx < instances.size())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001667 return instances[idx].name.GetCString();
Greg Claytone996fd32011-03-08 22:40:15 +00001668 return NULL;
1669}
1670
1671const char *
1672PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx)
1673{
Greg Claytonded470d2011-03-19 01:12:21 +00001674 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001675 PlatformInstances &instances = GetPlatformInstances ();
1676 if (idx < instances.size())
1677 return instances[idx].description.c_str();
Greg Claytone996fd32011-03-08 22:40:15 +00001678 return NULL;
1679}
1680
1681bool
1682PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback)
1683{
1684 if (create_callback)
1685 {
Greg Claytonded470d2011-03-19 01:12:21 +00001686 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001687 PlatformInstances &instances = GetPlatformInstances ();
Greg Claytonded470d2011-03-19 01:12:21 +00001688
Greg Claytonab65b342011-04-13 22:47:15 +00001689 PlatformInstances::iterator pos, end = instances.end();
1690 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytonded470d2011-03-19 01:12:21 +00001691 {
1692 if (pos->create_callback == create_callback)
1693 {
Greg Claytonab65b342011-04-13 22:47:15 +00001694 instances.erase(pos);
Greg Claytonded470d2011-03-19 01:12:21 +00001695 return true;
1696 }
1697 }
Greg Claytone996fd32011-03-08 22:40:15 +00001698 }
1699 return false;
1700}
1701
1702PlatformCreateInstance
1703PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx)
1704{
Greg Claytonded470d2011-03-19 01:12:21 +00001705 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001706 PlatformInstances &instances = GetPlatformInstances ();
1707 if (idx < instances.size())
1708 return instances[idx].create_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001709 return NULL;
1710}
1711
1712PlatformCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001713PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name)
Greg Claytone996fd32011-03-08 22:40:15 +00001714{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001715 if (name)
Greg Claytone996fd32011-03-08 22:40:15 +00001716 {
Greg Claytonded470d2011-03-19 01:12:21 +00001717 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001718 PlatformInstances &instances = GetPlatformInstances ();
Greg Claytonded470d2011-03-19 01:12:21 +00001719
Greg Claytonab65b342011-04-13 22:47:15 +00001720 PlatformInstances::iterator pos, end = instances.end();
1721 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytone996fd32011-03-08 22:40:15 +00001722 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001723 if (name == pos->name)
Greg Claytonded470d2011-03-19 01:12:21 +00001724 return pos->create_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001725 }
1726 }
1727 return NULL;
1728}
1729
Greg Claytonc7bece562013-01-25 18:06:21 +00001730size_t
Greg Claytonab65b342011-04-13 22:47:15 +00001731PluginManager::AutoCompletePlatformName (const char *name, StringList &matches)
1732{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001733 if (name)
Greg Claytonab65b342011-04-13 22:47:15 +00001734 {
1735 Mutex::Locker locker (GetPlatformInstancesMutex ());
1736 PlatformInstances &instances = GetPlatformInstances ();
1737 llvm::StringRef name_sref(name);
1738
1739 PlatformInstances::iterator pos, end = instances.end();
1740 for (pos = instances.begin(); pos != end; ++ pos)
1741 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001742 llvm::StringRef plugin_name (pos->name.GetCString());
Greg Clayton7260f622011-04-18 08:33:37 +00001743 if (plugin_name.startswith(name_sref))
1744 matches.AppendString (plugin_name.data());
Greg Claytonab65b342011-04-13 22:47:15 +00001745 }
1746 }
1747 return matches.GetSize();
1748}
Greg Claytone996fd32011-03-08 22:40:15 +00001749#pragma mark Process
1750
1751struct ProcessInstance
1752{
1753 ProcessInstance() :
Greg Clayton7f982402013-07-15 22:54:20 +00001754 name(),
1755 description(),
1756 create_callback(NULL),
1757 debugger_init_callback(NULL)
Greg Claytone996fd32011-03-08 22:40:15 +00001758 {
1759 }
1760
Greg Clayton57abc5d2013-05-10 21:47:16 +00001761 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762 std::string description;
1763 ProcessCreateInstance create_callback;
Greg Clayton7f982402013-07-15 22:54:20 +00001764 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001765};
1766
1767typedef std::vector<ProcessInstance> ProcessInstances;
1768
Greg Claytonab65b342011-04-13 22:47:15 +00001769static Mutex &
1770GetProcessMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771{
Greg Claytonab65b342011-04-13 22:47:15 +00001772 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1773 return g_instances_mutex;
1774}
1775
1776static ProcessInstances &
1777GetProcessInstances ()
1778{
1779 static ProcessInstances g_instances;
1780 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001781}
1782
1783
1784bool
Greg Clayton7f982402013-07-15 22:54:20 +00001785PluginManager::RegisterPlugin (const ConstString &name,
1786 const char *description,
1787 ProcessCreateInstance create_callback,
1788 DebuggerInitializeCallback debugger_init_callback)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001789{
1790 if (create_callback)
1791 {
1792 ProcessInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00001793 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794 instance.name = name;
1795 if (description && description[0])
1796 instance.description = description;
1797 instance.create_callback = create_callback;
Greg Clayton7f982402013-07-15 22:54:20 +00001798 instance.debugger_init_callback = debugger_init_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001799 Mutex::Locker locker (GetProcessMutex ());
1800 GetProcessInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 }
1802 return false;
1803}
1804
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001805const char *
1806PluginManager::GetProcessPluginNameAtIndex (uint32_t idx)
1807{
Greg Claytonab65b342011-04-13 22:47:15 +00001808 Mutex::Locker locker (GetProcessMutex ());
1809 ProcessInstances &instances = GetProcessInstances ();
1810 if (idx < instances.size())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001811 return instances[idx].name.GetCString();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001812 return NULL;
1813}
1814
1815const char *
1816PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx)
1817{
Greg Claytonab65b342011-04-13 22:47:15 +00001818 Mutex::Locker locker (GetProcessMutex ());
1819 ProcessInstances &instances = GetProcessInstances ();
1820 if (idx < instances.size())
1821 return instances[idx].description.c_str();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001822 return NULL;
1823}
1824
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001825bool
1826PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback)
1827{
1828 if (create_callback)
1829 {
Greg Claytonab65b342011-04-13 22:47:15 +00001830 Mutex::Locker locker (GetProcessMutex ());
1831 ProcessInstances &instances = GetProcessInstances ();
1832
1833 ProcessInstances::iterator pos, end = instances.end();
1834 for (pos = instances.begin(); pos != end; ++ pos)
1835 {
1836 if (pos->create_callback == create_callback)
1837 {
1838 instances.erase(pos);
1839 return true;
1840 }
1841 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001842 }
1843 return false;
1844}
1845
1846ProcessCreateInstance
1847PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx)
1848{
Greg Claytonab65b342011-04-13 22:47:15 +00001849 Mutex::Locker locker (GetProcessMutex ());
1850 ProcessInstances &instances = GetProcessInstances ();
1851 if (idx < instances.size())
1852 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001853 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854}
1855
Greg Claytonab65b342011-04-13 22:47:15 +00001856
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857ProcessCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00001858PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859{
Greg Clayton57abc5d2013-05-10 21:47:16 +00001860 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 {
Greg Claytonab65b342011-04-13 22:47:15 +00001862 Mutex::Locker locker (GetProcessMutex ());
1863 ProcessInstances &instances = GetProcessInstances ();
1864
1865 ProcessInstances::iterator pos, end = instances.end();
1866 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001867 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00001868 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00001869 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870 }
1871 }
1872 return NULL;
1873}
1874
Zachary Turner2c1f46d2015-07-30 20:28:07 +00001875#pragma mark ScriptInterpreter
1876
1877struct ScriptInterpreterInstance
1878{
1879 ScriptInterpreterInstance()
1880 : name()
1881 , language(lldb::eScriptLanguageNone)
1882 , description()
1883 , create_callback(NULL)
1884 {
1885 }
1886
1887 ConstString name;
1888 lldb::ScriptLanguage language;
1889 std::string description;
1890 ScriptInterpreterCreateInstance create_callback;
1891};
1892
1893typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances;
1894
1895static Mutex &
1896GetScriptInterpreterMutex()
1897{
1898 static Mutex g_instances_mutex(Mutex::eMutexTypeRecursive);
1899 return g_instances_mutex;
1900}
1901
1902static ScriptInterpreterInstances &
1903GetScriptInterpreterInstances()
1904{
1905 static ScriptInterpreterInstances g_instances;
1906 return g_instances;
1907}
1908
1909bool
1910PluginManager::RegisterPlugin(const ConstString &name, const char *description, lldb::ScriptLanguage script_language,
1911 ScriptInterpreterCreateInstance create_callback)
1912{
1913 if (!create_callback)
1914 return false;
1915 ScriptInterpreterInstance instance;
1916 assert((bool)name);
1917 instance.name = name;
1918 if (description && description[0])
1919 instance.description = description;
1920 instance.create_callback = create_callback;
1921 instance.language = script_language;
1922 Mutex::Locker locker(GetScriptInterpreterMutex());
1923 GetScriptInterpreterInstances().push_back(instance);
1924 return false;
1925}
1926
1927bool
1928PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)
1929{
1930 if (!create_callback)
1931 return false;
1932 Mutex::Locker locker(GetScriptInterpreterMutex());
1933 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
1934
1935 ScriptInterpreterInstances::iterator pos, end = instances.end();
1936 for (pos = instances.begin(); pos != end; ++pos)
1937 {
1938 if (pos->create_callback != create_callback)
1939 continue;
1940
1941 instances.erase(pos);
1942 return true;
1943 }
1944 return false;
1945}
1946
1947ScriptInterpreterCreateInstance
1948PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)
1949{
1950 Mutex::Locker locker(GetScriptInterpreterMutex());
1951 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
1952 if (idx < instances.size())
1953 return instances[idx].create_callback;
1954 return nullptr;
1955}
1956
1957lldb::ScriptInterpreterSP
1958PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter)
1959{
1960 Mutex::Locker locker(GetScriptInterpreterMutex());
1961 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
1962
1963 ScriptInterpreterInstances::iterator pos, end = instances.end();
1964 ScriptInterpreterCreateInstance none_instance = nullptr;
1965 for (pos = instances.begin(); pos != end; ++pos)
1966 {
1967 if (pos->language == lldb::eScriptLanguageNone)
1968 none_instance = pos->create_callback;
1969
1970 if (script_lang == pos->language)
1971 return pos->create_callback(interpreter);
1972 }
1973
1974 // If we didn't find one, return the ScriptInterpreter for the null language.
1975 assert(none_instance != nullptr);
1976 return none_instance(interpreter);
1977}
1978
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001979#pragma mark SymbolFile
1980
Jason Molenda743e86a2010-06-11 23:44:18 +00001981struct SymbolFileInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982{
1983 SymbolFileInstance() :
1984 name(),
1985 description(),
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00001986 create_callback(nullptr),
1987 debugger_init_callback(nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001988 {
1989 }
1990
Greg Clayton57abc5d2013-05-10 21:47:16 +00001991 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001992 std::string description;
1993 SymbolFileCreateInstance create_callback;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00001994 DebuggerInitializeCallback debugger_init_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995};
1996
1997typedef std::vector<SymbolFileInstance> SymbolFileInstances;
1998
Greg Claytonab65b342011-04-13 22:47:15 +00001999static Mutex &
2000GetSymbolFileMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001{
Greg Claytonab65b342011-04-13 22:47:15 +00002002 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2003 return g_instances_mutex;
2004}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002005
Greg Claytonab65b342011-04-13 22:47:15 +00002006static SymbolFileInstances &
2007GetSymbolFileInstances ()
2008{
2009 static SymbolFileInstances g_instances;
2010 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011}
2012
2013
2014bool
2015PluginManager::RegisterPlugin
2016(
Greg Clayton57abc5d2013-05-10 21:47:16 +00002017 const ConstString &name,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 const char *description,
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002019 SymbolFileCreateInstance create_callback,
2020 DebuggerInitializeCallback debugger_init_callback
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021)
2022{
2023 if (create_callback)
2024 {
2025 SymbolFileInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00002026 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027 instance.name = name;
2028 if (description && description[0])
2029 instance.description = description;
2030 instance.create_callback = create_callback;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002031 instance.debugger_init_callback = debugger_init_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00002032 Mutex::Locker locker (GetSymbolFileMutex ());
2033 GetSymbolFileInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002034 }
2035 return false;
2036}
2037
2038bool
2039PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback)
2040{
2041 if (create_callback)
2042 {
Greg Claytonab65b342011-04-13 22:47:15 +00002043 Mutex::Locker locker (GetSymbolFileMutex ());
2044 SymbolFileInstances &instances = GetSymbolFileInstances ();
2045
2046 SymbolFileInstances::iterator pos, end = instances.end();
2047 for (pos = instances.begin(); pos != end; ++ pos)
2048 {
2049 if (pos->create_callback == create_callback)
2050 {
2051 instances.erase(pos);
2052 return true;
2053 }
2054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055 }
2056 return false;
2057}
2058
2059SymbolFileCreateInstance
2060PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx)
2061{
Greg Claytonab65b342011-04-13 22:47:15 +00002062 Mutex::Locker locker (GetSymbolFileMutex ());
2063 SymbolFileInstances &instances = GetSymbolFileInstances ();
2064 if (idx < instances.size())
2065 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00002066 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067}
Greg Claytonab65b342011-04-13 22:47:15 +00002068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069SymbolFileCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00002070PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071{
Greg Clayton57abc5d2013-05-10 21:47:16 +00002072 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073 {
Greg Claytonab65b342011-04-13 22:47:15 +00002074 Mutex::Locker locker (GetSymbolFileMutex ());
2075 SymbolFileInstances &instances = GetSymbolFileInstances ();
2076
2077 SymbolFileInstances::iterator pos, end = instances.end();
2078 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002079 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00002080 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00002081 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002082 }
2083 }
2084 return NULL;
2085}
2086
2087
2088
2089#pragma mark SymbolVendor
2090
Jason Molenda743e86a2010-06-11 23:44:18 +00002091struct SymbolVendorInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002092{
2093 SymbolVendorInstance() :
2094 name(),
2095 description(),
2096 create_callback(NULL)
2097 {
2098 }
2099
Greg Clayton57abc5d2013-05-10 21:47:16 +00002100 ConstString name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002101 std::string description;
2102 SymbolVendorCreateInstance create_callback;
2103};
2104
2105typedef std::vector<SymbolVendorInstance> SymbolVendorInstances;
2106
Greg Claytonab65b342011-04-13 22:47:15 +00002107static Mutex &
2108GetSymbolVendorMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002109{
Greg Claytonab65b342011-04-13 22:47:15 +00002110 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2111 return g_instances_mutex;
2112}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002113
Greg Claytonab65b342011-04-13 22:47:15 +00002114static SymbolVendorInstances &
2115GetSymbolVendorInstances ()
2116{
2117 static SymbolVendorInstances g_instances;
2118 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002119}
2120
2121bool
2122PluginManager::RegisterPlugin
2123(
Greg Clayton57abc5d2013-05-10 21:47:16 +00002124 const ConstString &name,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002125 const char *description,
2126 SymbolVendorCreateInstance create_callback
2127)
2128{
2129 if (create_callback)
2130 {
2131 SymbolVendorInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00002132 assert ((bool)name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002133 instance.name = name;
2134 if (description && description[0])
2135 instance.description = description;
2136 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00002137 Mutex::Locker locker (GetSymbolVendorMutex ());
2138 GetSymbolVendorInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002139 }
2140 return false;
2141}
2142
2143bool
2144PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback)
2145{
2146 if (create_callback)
2147 {
Greg Claytonab65b342011-04-13 22:47:15 +00002148 Mutex::Locker locker (GetSymbolVendorMutex ());
2149 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
2150
2151 SymbolVendorInstances::iterator pos, end = instances.end();
2152 for (pos = instances.begin(); pos != end; ++ pos)
2153 {
2154 if (pos->create_callback == create_callback)
2155 {
2156 instances.erase(pos);
2157 return true;
2158 }
2159 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002160 }
2161 return false;
2162}
2163
2164SymbolVendorCreateInstance
2165PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx)
2166{
Greg Claytonab65b342011-04-13 22:47:15 +00002167 Mutex::Locker locker (GetSymbolVendorMutex ());
2168 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
2169 if (idx < instances.size())
2170 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00002171 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002172}
2173
Greg Claytonab65b342011-04-13 22:47:15 +00002174
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002175SymbolVendorCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00002176PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002177{
Greg Clayton57abc5d2013-05-10 21:47:16 +00002178 if (name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002179 {
Greg Claytonab65b342011-04-13 22:47:15 +00002180 Mutex::Locker locker (GetSymbolVendorMutex ());
2181 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
2182
2183 SymbolVendorInstances::iterator pos, end = instances.end();
2184 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002185 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00002186 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00002187 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002188 }
2189 }
2190 return NULL;
2191}
2192
2193
Greg Clayton7be25422011-04-25 21:14:26 +00002194#pragma mark UnwindAssembly
Jason Molendafbcb7f22010-09-10 07:49:16 +00002195
Greg Clayton7be25422011-04-25 21:14:26 +00002196struct UnwindAssemblyInstance
Jason Molendafbcb7f22010-09-10 07:49:16 +00002197{
Greg Clayton7be25422011-04-25 21:14:26 +00002198 UnwindAssemblyInstance() :
Jason Molendafbcb7f22010-09-10 07:49:16 +00002199 name(),
2200 description(),
2201 create_callback(NULL)
2202 {
2203 }
2204
Greg Clayton57abc5d2013-05-10 21:47:16 +00002205 ConstString name;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002206 std::string description;
Greg Clayton7be25422011-04-25 21:14:26 +00002207 UnwindAssemblyCreateInstance create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002208};
2209
Greg Clayton7be25422011-04-25 21:14:26 +00002210typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002211
Greg Claytonab65b342011-04-13 22:47:15 +00002212static Mutex &
Greg Clayton7be25422011-04-25 21:14:26 +00002213GetUnwindAssemblyMutex ()
Jason Molendafbcb7f22010-09-10 07:49:16 +00002214{
Greg Claytonab65b342011-04-13 22:47:15 +00002215 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2216 return g_instances_mutex;
2217}
Jason Molendafbcb7f22010-09-10 07:49:16 +00002218
Greg Clayton7be25422011-04-25 21:14:26 +00002219static UnwindAssemblyInstances &
2220GetUnwindAssemblyInstances ()
Greg Claytonab65b342011-04-13 22:47:15 +00002221{
Greg Clayton7be25422011-04-25 21:14:26 +00002222 static UnwindAssemblyInstances g_instances;
Greg Claytonab65b342011-04-13 22:47:15 +00002223 return g_instances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002224}
2225
2226bool
2227PluginManager::RegisterPlugin
2228(
Greg Clayton57abc5d2013-05-10 21:47:16 +00002229 const ConstString &name,
Jason Molendafbcb7f22010-09-10 07:49:16 +00002230 const char *description,
Greg Clayton7be25422011-04-25 21:14:26 +00002231 UnwindAssemblyCreateInstance create_callback
Jason Molendafbcb7f22010-09-10 07:49:16 +00002232)
2233{
2234 if (create_callback)
2235 {
Greg Clayton7be25422011-04-25 21:14:26 +00002236 UnwindAssemblyInstance instance;
Greg Clayton57abc5d2013-05-10 21:47:16 +00002237 assert ((bool)name);
Jason Molendafbcb7f22010-09-10 07:49:16 +00002238 instance.name = name;
2239 if (description && description[0])
2240 instance.description = description;
2241 instance.create_callback = create_callback;
Greg Clayton7be25422011-04-25 21:14:26 +00002242 Mutex::Locker locker (GetUnwindAssemblyMutex ());
2243 GetUnwindAssemblyInstances ().push_back (instance);
Jason Molendafbcb7f22010-09-10 07:49:16 +00002244 }
2245 return false;
2246}
2247
2248bool
Greg Clayton7be25422011-04-25 21:14:26 +00002249PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback)
Jason Molendafbcb7f22010-09-10 07:49:16 +00002250{
2251 if (create_callback)
2252 {
Greg Clayton7be25422011-04-25 21:14:26 +00002253 Mutex::Locker locker (GetUnwindAssemblyMutex ());
2254 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00002255
Greg Clayton7be25422011-04-25 21:14:26 +00002256 UnwindAssemblyInstances::iterator pos, end = instances.end();
Greg Claytonab65b342011-04-13 22:47:15 +00002257 for (pos = instances.begin(); pos != end; ++ pos)
2258 {
2259 if (pos->create_callback == create_callback)
2260 {
2261 instances.erase(pos);
2262 return true;
2263 }
2264 }
Jason Molendafbcb7f22010-09-10 07:49:16 +00002265 }
2266 return false;
2267}
2268
Greg Clayton7be25422011-04-25 21:14:26 +00002269UnwindAssemblyCreateInstance
2270PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx)
Jason Molendafbcb7f22010-09-10 07:49:16 +00002271{
Greg Clayton7be25422011-04-25 21:14:26 +00002272 Mutex::Locker locker (GetUnwindAssemblyMutex ());
2273 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00002274 if (idx < instances.size())
2275 return instances[idx].create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002276 return NULL;
2277}
2278
Greg Claytonab65b342011-04-13 22:47:15 +00002279
Greg Clayton7be25422011-04-25 21:14:26 +00002280UnwindAssemblyCreateInstance
Greg Clayton57abc5d2013-05-10 21:47:16 +00002281PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &name)
Jason Molendafbcb7f22010-09-10 07:49:16 +00002282{
Greg Clayton57abc5d2013-05-10 21:47:16 +00002283 if (name)
Jason Molendafbcb7f22010-09-10 07:49:16 +00002284 {
Greg Clayton7be25422011-04-25 21:14:26 +00002285 Mutex::Locker locker (GetUnwindAssemblyMutex ());
2286 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00002287
Greg Clayton7be25422011-04-25 21:14:26 +00002288 UnwindAssemblyInstances::iterator pos, end = instances.end();
Greg Claytonab65b342011-04-13 22:47:15 +00002289 for (pos = instances.begin(); pos != end; ++ pos)
Jason Molendafbcb7f22010-09-10 07:49:16 +00002290 {
Greg Clayton57abc5d2013-05-10 21:47:16 +00002291 if (name == pos->name)
Greg Claytonab65b342011-04-13 22:47:15 +00002292 return pos->create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00002293 }
2294 }
2295 return NULL;
2296}
2297
Kuba Breckabeed8212014-09-04 01:03:18 +00002298#pragma mark MemoryHistory
2299
2300struct MemoryHistoryInstance
2301{
2302 MemoryHistoryInstance() :
2303 name(),
2304 description(),
2305 create_callback(NULL)
2306 {
2307 }
2308
2309 ConstString name;
2310 std::string description;
2311 MemoryHistoryCreateInstance create_callback;
2312};
2313
2314typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances;
2315
2316static Mutex &
2317GetMemoryHistoryMutex ()
2318{
2319 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2320 return g_instances_mutex;
2321}
2322
2323static MemoryHistoryInstances &
2324GetMemoryHistoryInstances ()
2325{
2326 static MemoryHistoryInstances g_instances;
2327 return g_instances;
2328}
2329
2330bool
2331PluginManager::RegisterPlugin
2332(
2333 const ConstString &name,
2334 const char *description,
2335 MemoryHistoryCreateInstance create_callback
2336 )
2337{
2338 if (create_callback)
2339 {
2340 MemoryHistoryInstance instance;
2341 assert ((bool)name);
2342 instance.name = name;
2343 if (description && description[0])
2344 instance.description = description;
2345 instance.create_callback = create_callback;
2346 Mutex::Locker locker (GetMemoryHistoryMutex ());
2347 GetMemoryHistoryInstances ().push_back (instance);
2348 }
2349 return false;
2350}
2351
2352bool
2353PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback)
2354{
2355 if (create_callback)
2356 {
2357 Mutex::Locker locker (GetMemoryHistoryMutex ());
2358 MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
2359
2360 MemoryHistoryInstances::iterator pos, end = instances.end();
2361 for (pos = instances.begin(); pos != end; ++ pos)
2362 {
2363 if (pos->create_callback == create_callback)
2364 {
2365 instances.erase(pos);
2366 return true;
2367 }
2368 }
2369 }
2370 return false;
2371}
2372
2373MemoryHistoryCreateInstance
2374PluginManager::GetMemoryHistoryCreateCallbackAtIndex (uint32_t idx)
2375{
2376 Mutex::Locker locker (GetMemoryHistoryMutex ());
2377 MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
2378 if (idx < instances.size())
2379 return instances[idx].create_callback;
2380 return NULL;
2381}
2382
2383
2384MemoryHistoryCreateInstance
2385PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &name)
2386{
2387 if (name)
2388 {
2389 Mutex::Locker locker (GetMemoryHistoryMutex ());
2390 MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
2391
2392 MemoryHistoryInstances::iterator pos, end = instances.end();
2393 for (pos = instances.begin(); pos != end; ++ pos)
2394 {
2395 if (name == pos->name)
2396 return pos->create_callback;
2397 }
2398 }
2399 return NULL;
2400}
2401
Kuba Breckaafdf8422014-10-10 23:43:03 +00002402#pragma mark InstrumentationRuntime
2403
2404struct InstrumentationRuntimeInstance
2405{
2406 InstrumentationRuntimeInstance() :
2407 name(),
2408 description(),
2409 create_callback(NULL)
2410 {
2411 }
2412
2413 ConstString name;
2414 std::string description;
2415 InstrumentationRuntimeCreateInstance create_callback;
2416 InstrumentationRuntimeGetType get_type_callback;
2417};
2418
2419typedef std::vector<InstrumentationRuntimeInstance> InstrumentationRuntimeInstances;
2420
2421static Mutex &
2422GetInstrumentationRuntimeMutex ()
2423{
2424 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2425 return g_instances_mutex;
2426}
2427
2428static InstrumentationRuntimeInstances &
2429GetInstrumentationRuntimeInstances ()
2430{
2431 static InstrumentationRuntimeInstances g_instances;
2432 return g_instances;
2433}
2434
2435bool
2436PluginManager::RegisterPlugin
2437(
2438 const ConstString &name,
2439 const char *description,
2440 InstrumentationRuntimeCreateInstance create_callback,
2441 InstrumentationRuntimeGetType get_type_callback
2442 )
2443{
2444 if (create_callback)
2445 {
2446 InstrumentationRuntimeInstance instance;
2447 assert ((bool)name);
2448 instance.name = name;
2449 if (description && description[0])
2450 instance.description = description;
2451 instance.create_callback = create_callback;
2452 instance.get_type_callback = get_type_callback;
2453 Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
2454 GetInstrumentationRuntimeInstances ().push_back (instance);
2455 }
2456 return false;
2457}
2458
2459bool
2460PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_callback)
2461{
2462 if (create_callback)
2463 {
2464 Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
2465 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
2466
2467 InstrumentationRuntimeInstances::iterator pos, end = instances.end();
2468 for (pos = instances.begin(); pos != end; ++ pos)
2469 {
2470 if (pos->create_callback == create_callback)
2471 {
2472 instances.erase(pos);
2473 return true;
2474 }
2475 }
2476 }
2477 return false;
2478}
2479
2480InstrumentationRuntimeGetType
2481PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx)
2482{
2483 Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
2484 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
2485 if (idx < instances.size())
2486 return instances[idx].get_type_callback;
2487 return NULL;
2488}
2489
2490InstrumentationRuntimeCreateInstance
2491PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex (uint32_t idx)
2492{
2493 Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
2494 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
2495 if (idx < instances.size())
2496 return instances[idx].create_callback;
2497 return NULL;
2498}
2499
2500
2501InstrumentationRuntimeCreateInstance
2502PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const ConstString &name)
2503{
2504 if (name)
2505 {
2506 Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
2507 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
2508
2509 InstrumentationRuntimeInstances::iterator pos, end = instances.end();
2510 for (pos = instances.begin(); pos != end; ++ pos)
2511 {
2512 if (name == pos->name)
2513 return pos->create_callback;
2514 }
2515 }
2516 return NULL;
2517}
2518
Greg Clayton56939cb2015-09-17 22:23:34 +00002519#pragma mark TypeSystem
2520
2521
2522struct TypeSystemInstance
2523{
2524 TypeSystemInstance() :
2525 name(),
2526 description(),
2527 create_callback(NULL)
2528 {
2529 }
2530
2531 ConstString name;
2532 std::string description;
2533 TypeSystemCreateInstance create_callback;
2534};
2535
2536typedef std::vector<TypeSystemInstance> TypeSystemInstances;
2537
2538static Mutex &
2539GetTypeSystemMutex ()
2540{
2541 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
2542 return g_instances_mutex;
2543}
2544
2545static TypeSystemInstances &
2546GetTypeSystemInstances ()
2547{
2548 static TypeSystemInstances g_instances;
2549 return g_instances;
2550}
2551
2552bool
2553PluginManager::RegisterPlugin (const ConstString &name,
2554 const char *description,
2555 TypeSystemCreateInstance create_callback)
2556{
2557 if (create_callback)
2558 {
2559 TypeSystemInstance instance;
2560 assert ((bool)name);
2561 instance.name = name;
2562 if (description && description[0])
2563 instance.description = description;
2564 instance.create_callback = create_callback;
2565 Mutex::Locker locker (GetTypeSystemMutex ());
2566 GetTypeSystemInstances ().push_back (instance);
2567 }
2568 return false;
2569}
2570
2571bool
2572PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback)
2573{
2574 if (create_callback)
2575 {
2576 Mutex::Locker locker (GetTypeSystemMutex ());
2577 TypeSystemInstances &instances = GetTypeSystemInstances ();
2578
2579 TypeSystemInstances::iterator pos, end = instances.end();
2580 for (pos = instances.begin(); pos != end; ++ pos)
2581 {
2582 if (pos->create_callback == create_callback)
2583 {
2584 instances.erase(pos);
2585 return true;
2586 }
2587 }
2588 }
2589 return false;
2590}
2591
2592TypeSystemCreateInstance
2593PluginManager::GetTypeSystemCreateCallbackAtIndex (uint32_t idx)
2594{
2595 Mutex::Locker locker (GetTypeSystemMutex ());
2596 TypeSystemInstances &instances = GetTypeSystemInstances ();
2597 if (idx < instances.size())
2598 return instances[idx].create_callback;
2599 return NULL;
2600}
2601
2602TypeSystemCreateInstance
2603PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name)
2604{
2605 if (name)
2606 {
2607 Mutex::Locker locker (GetTypeSystemMutex ());
2608 TypeSystemInstances &instances = GetTypeSystemInstances ();
2609
2610 TypeSystemInstances::iterator pos, end = instances.end();
2611 for (pos = instances.begin(); pos != end; ++ pos)
2612 {
2613 if (name == pos->name)
2614 return pos->create_callback;
2615 }
2616 }
2617 return NULL;
2618}
2619
2620
Kuba Breckaafdf8422014-10-10 23:43:03 +00002621#pragma mark PluginManager
2622
Greg Claytone8cd0c92012-10-19 18:02:49 +00002623void
2624PluginManager::DebuggerInitialize (Debugger &debugger)
2625{
Jason Molenda9b837a12013-04-05 05:06:39 +00002626 // Initialize the DynamicLoader plugins
Greg Claytone8cd0c92012-10-19 18:02:49 +00002627 {
Jason Molenda9b837a12013-04-05 05:06:39 +00002628 Mutex::Locker locker (GetDynamicLoaderMutex ());
2629 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
2630
2631 DynamicLoaderInstances::iterator pos, end = instances.end();
2632 for (pos = instances.begin(); pos != end; ++ pos)
2633 {
2634 if (pos->debugger_init_callback)
2635 pos->debugger_init_callback (debugger);
2636 }
2637 }
2638
Andrew MacPherson17220c12014-03-05 10:12:43 +00002639 // Initialize the JITLoader plugins
2640 {
2641 Mutex::Locker locker (GetJITLoaderMutex ());
2642 JITLoaderInstances &instances = GetJITLoaderInstances ();
2643
2644 JITLoaderInstances::iterator pos, end = instances.end();
2645 for (pos = instances.begin(); pos != end; ++ pos)
2646 {
2647 if (pos->debugger_init_callback)
2648 pos->debugger_init_callback (debugger);
2649 }
2650 }
2651
Jason Molenda9b837a12013-04-05 05:06:39 +00002652 // Initialize the Platform plugins
2653 {
2654 Mutex::Locker locker (GetPlatformInstancesMutex ());
2655 PlatformInstances &instances = GetPlatformInstances ();
2656
2657 PlatformInstances::iterator pos, end = instances.end();
2658 for (pos = instances.begin(); pos != end; ++ pos)
2659 {
2660 if (pos->debugger_init_callback)
2661 pos->debugger_init_callback (debugger);
2662 }
Greg Claytone8cd0c92012-10-19 18:02:49 +00002663 }
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002664
Greg Clayton7f982402013-07-15 22:54:20 +00002665 // Initialize the Process plugins
2666 {
2667 Mutex::Locker locker (GetProcessMutex());
2668 ProcessInstances &instances = GetProcessInstances();
2669
2670 ProcessInstances::iterator pos, end = instances.end();
2671 for (pos = instances.begin(); pos != end; ++ pos)
2672 {
2673 if (pos->debugger_init_callback)
2674 pos->debugger_init_callback (debugger);
2675 }
2676 }
2677
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002678 // Initialize the SymbolFile plugins
2679 {
2680 Mutex::Locker locker (GetSymbolFileMutex());
2681 for (auto& sym_file: GetSymbolFileInstances())
2682 {
2683 if (sym_file.debugger_init_callback)
2684 sym_file.debugger_init_callback (debugger);
2685 }
2686 }
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002687
2688 // Initialize the OperatingSystem plugins
2689 {
2690 Mutex::Locker locker(GetOperatingSystemMutex());
2691 for (auto &os : GetOperatingSystemInstances())
2692 {
2693 if (os.debugger_init_callback)
2694 os.debugger_init_callback(debugger);
2695 }
2696 }
Greg Claytone8cd0c92012-10-19 18:02:49 +00002697}
2698
Greg Clayton7f982402013-07-15 22:54:20 +00002699// This is the preferred new way to register plugin specific settings. e.g.
2700// This will put a plugin's settings under e.g. "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
Greg Claytone8cd0c92012-10-19 18:02:49 +00002701static lldb::OptionValuePropertiesSP
Greg Clayton7f982402013-07-15 22:54:20 +00002702GetDebuggerPropertyForPlugins (Debugger &debugger,
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002703 const ConstString &plugin_type_name,
2704 const ConstString &plugin_type_desc,
2705 bool can_create)
Greg Claytone8cd0c92012-10-19 18:02:49 +00002706{
2707 lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties());
2708 if (parent_properties_sp)
2709 {
2710 static ConstString g_property_name("plugin");
2711
2712 OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty (NULL, g_property_name);
2713 if (!plugin_properties_sp && can_create)
2714 {
2715 plugin_properties_sp.reset (new OptionValueProperties (g_property_name));
2716 parent_properties_sp->AppendProperty (g_property_name,
2717 ConstString("Settings specify to plugins."),
2718 true,
2719 plugin_properties_sp);
2720 }
2721
2722 if (plugin_properties_sp)
2723 {
2724 lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty (NULL, plugin_type_name);
2725 if (!plugin_type_properties_sp && can_create)
2726 {
2727 plugin_type_properties_sp.reset (new OptionValueProperties (plugin_type_name));
2728 plugin_properties_sp->AppendProperty (plugin_type_name,
2729 plugin_type_desc,
2730 true,
2731 plugin_type_properties_sp);
2732 }
2733 return plugin_type_properties_sp;
2734 }
2735 }
2736 return lldb::OptionValuePropertiesSP();
2737}
2738
Greg Clayton7f982402013-07-15 22:54:20 +00002739// This is deprecated way to register plugin specific settings. e.g.
2740// "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME"
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002741// and Platform generic settings would be under "platform.SETTINGNAME".
2742static lldb::OptionValuePropertiesSP
Greg Clayton7f982402013-07-15 22:54:20 +00002743GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger,
2744 const ConstString &plugin_type_name,
2745 const ConstString &plugin_type_desc,
2746 bool can_create)
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002747{
2748 static ConstString g_property_name("plugin");
2749 lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties());
2750 if (parent_properties_sp)
2751 {
2752 OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty (NULL, plugin_type_name);
2753 if (!plugin_properties_sp && can_create)
2754 {
2755 plugin_properties_sp.reset (new OptionValueProperties (plugin_type_name));
2756 parent_properties_sp->AppendProperty (plugin_type_name,
2757 plugin_type_desc,
2758 true,
2759 plugin_properties_sp);
2760 }
2761
2762 if (plugin_properties_sp)
2763 {
2764 lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty (NULL, g_property_name);
2765 if (!plugin_type_properties_sp && can_create)
2766 {
2767 plugin_type_properties_sp.reset (new OptionValueProperties (g_property_name));
2768 plugin_properties_sp->AppendProperty (g_property_name,
2769 ConstString("Settings specific to plugins"),
2770 true,
2771 plugin_type_properties_sp);
2772 }
2773 return plugin_type_properties_sp;
2774 }
2775 }
2776 return lldb::OptionValuePropertiesSP();
2777}
2778
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002779namespace {
2780
2781typedef lldb::OptionValuePropertiesSP
2782GetDebuggerPropertyForPluginsPtr (Debugger&, const ConstString&, const ConstString&, bool can_create);
Jason Molenda3b59f5c2013-04-05 22:40:42 +00002783
Greg Claytone8cd0c92012-10-19 18:02:49 +00002784lldb::OptionValuePropertiesSP
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002785GetSettingForPlugin (Debugger &debugger,
2786 const ConstString &setting_name,
2787 const ConstString &plugin_type_name,
2788 GetDebuggerPropertyForPluginsPtr get_debugger_property= GetDebuggerPropertyForPlugins)
Greg Claytone8cd0c92012-10-19 18:02:49 +00002789{
2790 lldb::OptionValuePropertiesSP properties_sp;
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002791 lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (debugger,
2792 plugin_type_name,
2793 ConstString(), // not creating to so we don't need the description
2794 false));
Greg Claytone8cd0c92012-10-19 18:02:49 +00002795 if (plugin_type_properties_sp)
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002796 properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name);
Greg Claytone8cd0c92012-10-19 18:02:49 +00002797 return properties_sp;
2798}
2799
2800bool
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002801CreateSettingForPlugin (Debugger &debugger,
2802 const ConstString &plugin_type_name,
2803 const ConstString &plugin_type_desc,
2804 const lldb::OptionValuePropertiesSP &properties_sp,
2805 const ConstString &description,
2806 bool is_global_property,
2807 GetDebuggerPropertyForPluginsPtr get_debugger_property = GetDebuggerPropertyForPlugins)
2808{
2809 if (properties_sp)
2810 {
2811 lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (
2812 debugger, plugin_type_name, plugin_type_desc, true));
2813 if (plugin_type_properties_sp)
2814 {
2815 plugin_type_properties_sp->AppendProperty (properties_sp->GetName(),
2816 description,
2817 is_global_property,
2818 properties_sp);
2819 return true;
2820 }
2821 }
2822 return false;
2823}
2824
2825const char* kDynamicLoaderPluginName("dynamic-loader");
2826const char* kPlatformPluginName("platform");
2827const char* kProcessPluginName("process");
2828const char* kSymbolFilePluginName("symbol-file");
2829const char* kJITLoaderPluginName("jit-loader");
2830
2831}
2832
2833lldb::OptionValuePropertiesSP
2834PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger,
2835 const ConstString &setting_name)
2836{
2837 return GetSettingForPlugin(debugger, setting_name, ConstString(kDynamicLoaderPluginName));
2838}
2839
2840bool
Greg Claytone8cd0c92012-10-19 18:02:49 +00002841PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger,
2842 const lldb::OptionValuePropertiesSP &properties_sp,
2843 const ConstString &description,
2844 bool is_global_property)
2845{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002846 return CreateSettingForPlugin(debugger,
2847 ConstString(kDynamicLoaderPluginName),
2848 ConstString("Settings for dynamic loader plug-ins"),
2849 properties_sp,
2850 description,
2851 is_global_property);
Greg Claytone8cd0c92012-10-19 18:02:49 +00002852}
2853
Jason Molenda9b837a12013-04-05 05:06:39 +00002854
2855lldb::OptionValuePropertiesSP
2856PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name)
2857{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002858 return GetSettingForPlugin(debugger,
2859 setting_name,
2860 ConstString(kPlatformPluginName),
2861 GetDebuggerPropertyForPluginsOldStyle);
Jason Molenda9b837a12013-04-05 05:06:39 +00002862}
2863
2864bool
2865PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger,
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002866 const lldb::OptionValuePropertiesSP &properties_sp,
2867 const ConstString &description,
2868 bool is_global_property)
Jason Molenda9b837a12013-04-05 05:06:39 +00002869{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002870 return CreateSettingForPlugin(debugger,
2871 ConstString(kPlatformPluginName),
2872 ConstString("Settings for platform plug-ins"),
2873 properties_sp,
2874 description,
2875 is_global_property,
2876 GetDebuggerPropertyForPluginsOldStyle);
Greg Clayton7f982402013-07-15 22:54:20 +00002877}
2878
2879
2880lldb::OptionValuePropertiesSP
2881PluginManager::GetSettingForProcessPlugin (Debugger &debugger, const ConstString &setting_name)
2882{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002883 return GetSettingForPlugin(debugger, setting_name, ConstString(kProcessPluginName));
Greg Clayton7f982402013-07-15 22:54:20 +00002884}
2885
2886bool
2887PluginManager::CreateSettingForProcessPlugin (Debugger &debugger,
2888 const lldb::OptionValuePropertiesSP &properties_sp,
2889 const ConstString &description,
2890 bool is_global_property)
2891{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002892 return CreateSettingForPlugin(debugger,
2893 ConstString(kProcessPluginName),
2894 ConstString("Settings for process plug-ins"),
2895 properties_sp,
2896 description,
2897 is_global_property);
Jason Molenda9b837a12013-04-05 05:06:39 +00002898}
2899
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002900lldb::OptionValuePropertiesSP
2901PluginManager::GetSettingForSymbolFilePlugin (Debugger &debugger,
2902 const ConstString &setting_name)
2903{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002904 return GetSettingForPlugin(debugger, setting_name, ConstString(kSymbolFilePluginName));
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002905}
2906
2907bool
2908PluginManager::CreateSettingForSymbolFilePlugin (Debugger &debugger,
2909 const lldb::OptionValuePropertiesSP &properties_sp,
2910 const ConstString &description,
2911 bool is_global_property)
2912{
Oleksiy Vyaloveff9ad22015-09-16 17:38:36 +00002913 return CreateSettingForPlugin(debugger,
2914 ConstString(kSymbolFilePluginName),
2915 ConstString("Settings for symbol file plug-ins"),
2916 properties_sp,
2917 description,
2918 is_global_property);
2919}
2920
2921lldb::OptionValuePropertiesSP
2922PluginManager::GetSettingForJITLoaderPlugin (Debugger &debugger,
2923 const ConstString &setting_name)
2924{
2925 return GetSettingForPlugin(debugger, setting_name, ConstString(kJITLoaderPluginName));
2926}
2927
2928bool
2929PluginManager::CreateSettingForJITLoaderPlugin (Debugger &debugger,
2930 const lldb::OptionValuePropertiesSP &properties_sp,
2931 const ConstString &description,
2932 bool is_global_property)
2933{
2934 return CreateSettingForPlugin(debugger,
2935 ConstString(kJITLoaderPluginName),
2936 ConstString("Settings for JIT loader plug-ins"),
2937 properties_sp,
2938 description,
2939 is_global_property);
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +00002940}
Ryan Brown65d4d5c2015-09-16 21:20:44 +00002941
2942static const char *kOperatingSystemPluginName("os");
2943
2944lldb::OptionValuePropertiesSP
2945PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger, const ConstString &setting_name)
2946{
2947 lldb::OptionValuePropertiesSP properties_sp;
2948 lldb::OptionValuePropertiesSP plugin_type_properties_sp(
2949 GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName),
2950 ConstString(), // not creating to so we don't need the description
2951 false));
2952 if (plugin_type_properties_sp)
2953 properties_sp = plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
2954 return properties_sp;
2955}
2956
2957bool
2958PluginManager::CreateSettingForOperatingSystemPlugin(Debugger &debugger,
2959 const lldb::OptionValuePropertiesSP &properties_sp,
2960 const ConstString &description, bool is_global_property)
2961{
2962 if (properties_sp)
2963 {
2964 lldb::OptionValuePropertiesSP plugin_type_properties_sp(
2965 GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName),
2966 ConstString("Settings for operating system plug-ins"), true));
2967 if (plugin_type_properties_sp)
2968 {
2969 plugin_type_properties_sp->AppendProperty(properties_sp->GetName(), description, is_global_property,
2970 properties_sp);
2971 return true;
2972 }
2973 }
2974 return false;
2975}