blob: 63bde64b63beb016a48790f4e1557e196d63e1f3 [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 Clayton4272cc72011-02-02 02:24:04 +000017#include "lldb/Core/Error.h"
Greg Clayton53239f02011-02-08 05:05:52 +000018#include "lldb/Host/FileSpec.h"
Greg Clayton4272cc72011-02-02 02:24:04 +000019#include "lldb/Host/Host.h"
20#include "lldb/Host/Mutex.h"
21
Greg Claytonab65b342011-04-13 22:47:15 +000022#include "llvm/ADT/StringRef.h"
23
Greg Clayton4272cc72011-02-02 02:24:04 +000024using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025using namespace lldb_private;
26
Jason Molenda743e86a2010-06-11 23:44:18 +000027enum PluginAction
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028{
29 ePluginRegisterInstance,
30 ePluginUnregisterInstance,
31 ePluginGetInstanceAtIndex
32};
33
Greg Clayton4272cc72011-02-02 02:24:04 +000034struct PluginInfo
35{
36 void *plugin_handle;
37 void *plugin_init_callback;
38 void *plugin_term_callback;
39};
40
41typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
42
43static Mutex &
44GetPluginMapMutex ()
45{
46 static Mutex g_plugin_map_mutex (Mutex::eMutexTypeRecursive);
47 return g_plugin_map_mutex;
48}
49
50static PluginTerminateMap &
51GetPluginMap ()
52{
53 static PluginTerminateMap g_plugin_map;
54 return g_plugin_map;
55}
56
57static bool
58PluginIsLoaded (const FileSpec &plugin_file_spec)
59{
60 Mutex::Locker locker (GetPluginMapMutex ());
61 PluginTerminateMap &plugin_map = GetPluginMap ();
62 return plugin_map.find (plugin_file_spec) != plugin_map.end();
63}
64
65static void
66SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
67{
68 Mutex::Locker locker (GetPluginMapMutex ());
69 PluginTerminateMap &plugin_map = GetPluginMap ();
70 assert (plugin_map.find (plugin_file_spec) != plugin_map.end());
71 plugin_map[plugin_file_spec] = plugin_info;
72}
73
74
75static FileSpec::EnumerateDirectoryResult
76LoadPluginCallback
77(
78 void *baton,
79 FileSpec::FileType file_type,
80 const FileSpec &file_spec
81)
82{
83// PluginManager *plugin_manager = (PluginManager *)baton;
84 Error error;
85
86 // If we have a regular file, a symbolic link or unknown file type, try
87 // and process the file. We must handle unknown as sometimes the directory
88 // enumeration might be enumerating a file system that doesn't have correct
89 // file type information.
90 if (file_type == FileSpec::eFileTypeRegular ||
91 file_type == FileSpec::eFileTypeSymbolicLink ||
92 file_type == FileSpec::eFileTypeUnknown )
93 {
94 FileSpec plugin_file_spec (file_spec);
95 plugin_file_spec.ResolvePath();
96
97 if (PluginIsLoaded (plugin_file_spec))
98 return FileSpec::eEnumerateDirectoryResultNext;
99 else
100 {
101 PluginInfo plugin_info = { NULL, NULL, NULL };
Greg Clayton45319462011-02-08 00:35:34 +0000102 uint32_t flags = Host::eDynamicLibraryOpenOptionLazy |
103 Host::eDynamicLibraryOpenOptionLocal |
104 Host::eDynamicLibraryOpenOptionLimitGetSymbol;
105
106 plugin_info.plugin_handle = Host::DynamicLibraryOpen (plugin_file_spec, flags, error);
Greg Clayton4272cc72011-02-02 02:24:04 +0000107 if (plugin_info.plugin_handle)
108 {
109 bool success = false;
110 plugin_info.plugin_init_callback = Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginInitialize", error);
111 if (plugin_info.plugin_init_callback)
112 {
113 // Call the plug-in "bool LLDBPluginInitialize(void)" function
114 success = ((bool (*)(void))plugin_info.plugin_init_callback)();
115 }
116
117 if (success)
118 {
119 // It is ok for the "LLDBPluginTerminate" symbol to be NULL
120 plugin_info.plugin_term_callback = Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginTerminate", error);
121 }
122 else
123 {
124 // The initialize function returned FALSE which means the
125 // plug-in might not be compatible, or might be too new or
126 // too old, or might not want to run on this machine.
127 Host::DynamicLibraryClose (plugin_info.plugin_handle);
128 plugin_info.plugin_handle = NULL;
129 plugin_info.plugin_init_callback = NULL;
130 }
131
132 // Regardless of success or failure, cache the plug-in load
133 // in our plug-in info so we don't try to load it again and
134 // again.
135 SetPluginInfo (plugin_file_spec, plugin_info);
136
137 return FileSpec::eEnumerateDirectoryResultNext;
138 }
139 }
140 }
141
142 if (file_type == FileSpec::eFileTypeUnknown ||
143 file_type == FileSpec::eFileTypeDirectory ||
144 file_type == FileSpec::eFileTypeSymbolicLink )
145 {
146 // Try and recurse into anything that a directory or symbolic link.
147 // We must also do this for unknown as sometimes the directory enumeration
148 // might be enurating a file system that doesn't have correct file type
149 // information.
150 return FileSpec::eEnumerateDirectoryResultEnter;
151 }
152
153 return FileSpec::eEnumerateDirectoryResultNext;
154}
155
156
157void
158PluginManager::Initialize ()
159{
Greg Clayton1cb64962011-03-24 04:28:38 +0000160#if 1
Greg Clayton4272cc72011-02-02 02:24:04 +0000161 FileSpec dir_spec;
162 const bool find_directories = true;
163 const bool find_files = true;
164 const bool find_other = true;
165 char dir_path[PATH_MAX];
166 if (Host::GetLLDBPath (ePathTypeLLDBSystemPlugins, dir_spec))
167 {
168 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
169 {
170 FileSpec::EnumerateDirectory (dir_path,
171 find_directories,
172 find_files,
173 find_other,
174 LoadPluginCallback,
175 NULL);
176 }
177 }
178
179 if (Host::GetLLDBPath (ePathTypeLLDBUserPlugins, dir_spec))
180 {
181 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
182 {
183 FileSpec::EnumerateDirectory (dir_path,
184 find_directories,
185 find_files,
186 find_other,
187 LoadPluginCallback,
188 NULL);
189 }
190 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000191#endif
Greg Clayton4272cc72011-02-02 02:24:04 +0000192}
193
194void
195PluginManager::Terminate ()
196{
197 Mutex::Locker locker (GetPluginMapMutex ());
198 PluginTerminateMap &plugin_map = GetPluginMap ();
199
200 PluginTerminateMap::const_iterator pos, end = plugin_map.end();
201 for (pos = plugin_map.begin(); pos != end; ++pos)
202 {
203 // Call the plug-in "void LLDBPluginTerminate (void)" function if there
204 // is one (if the symbol was not NULL).
205 if (pos->second.plugin_handle)
206 {
207 if (pos->second.plugin_term_callback)
208 ((void (*)(void))pos->second.plugin_term_callback)();
209 Host::DynamicLibraryClose (pos->second.plugin_handle);
210 }
211 }
212 plugin_map.clear();
213}
214
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
216#pragma mark ABI
217
218
Jason Molenda743e86a2010-06-11 23:44:18 +0000219struct ABIInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220{
221 ABIInstance() :
222 name(),
223 description(),
224 create_callback(NULL)
225 {
226 }
227
228 std::string name;
229 std::string description;
230 ABICreateInstance create_callback;
231};
232
233typedef std::vector<ABIInstance> ABIInstances;
234
Greg Claytonded470d2011-03-19 01:12:21 +0000235static Mutex &
236GetABIInstancesMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237{
Greg Claytonded470d2011-03-19 01:12:21 +0000238 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
239 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240}
241
Greg Claytonded470d2011-03-19 01:12:21 +0000242static ABIInstances &
243GetABIInstances ()
244{
245 static ABIInstances g_instances;
246 return g_instances;
247}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248
249bool
250PluginManager::RegisterPlugin
Greg Clayton4272cc72011-02-02 02:24:04 +0000251(
252 const char *name,
253 const char *description,
254 ABICreateInstance create_callback
255)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256{
257 if (create_callback)
258 {
259 ABIInstance instance;
260 assert (name && name[0]);
Greg Claytonab65b342011-04-13 22:47:15 +0000261 instance.name.assign (name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262 if (description && description[0])
263 instance.description = description;
264 instance.create_callback = create_callback;
Greg Claytonded470d2011-03-19 01:12:21 +0000265 Mutex::Locker locker (GetABIInstancesMutex ());
266 GetABIInstances ().push_back (instance);
267 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 }
269 return false;
270}
271
272bool
273PluginManager::UnregisterPlugin (ABICreateInstance create_callback)
274{
275 if (create_callback)
276 {
Greg Claytonded470d2011-03-19 01:12:21 +0000277 Mutex::Locker locker (GetABIInstancesMutex ());
278 ABIInstances &instances = GetABIInstances ();
279
280 ABIInstances::iterator pos, end = instances.end();
281 for (pos = instances.begin(); pos != end; ++ pos)
282 {
283 if (pos->create_callback == create_callback)
284 {
285 instances.erase(pos);
286 return true;
287 }
288 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 }
290 return false;
291}
292
293ABICreateInstance
294PluginManager::GetABICreateCallbackAtIndex (uint32_t idx)
295{
Greg Claytonded470d2011-03-19 01:12:21 +0000296 Mutex::Locker locker (GetABIInstancesMutex ());
297 ABIInstances &instances = GetABIInstances ();
Greg Claytonded470d2011-03-19 01:12:21 +0000298 if (idx < instances.size())
299 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000300 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301}
302
303ABICreateInstance
304PluginManager::GetABICreateCallbackForPluginName (const char *name)
305{
306 if (name && name[0])
307 {
Greg Claytonded470d2011-03-19 01:12:21 +0000308 Mutex::Locker locker (GetABIInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +0000309 llvm::StringRef name_sref(name);
Greg Claytonded470d2011-03-19 01:12:21 +0000310 ABIInstances &instances = GetABIInstances ();
311
312 ABIInstances::iterator pos, end = instances.end();
313 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314 {
Greg Claytonab65b342011-04-13 22:47:15 +0000315 if (name_sref.equals (pos->name))
Greg Claytonded470d2011-03-19 01:12:21 +0000316 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317 }
318 }
319 return NULL;
320}
321
322
323#pragma mark Disassembler
324
325
Jason Molenda743e86a2010-06-11 23:44:18 +0000326struct DisassemblerInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327{
328 DisassemblerInstance() :
329 name(),
330 description(),
331 create_callback(NULL)
332 {
333 }
334
335 std::string name;
336 std::string description;
337 DisassemblerCreateInstance create_callback;
338};
339
340typedef std::vector<DisassemblerInstance> DisassemblerInstances;
341
Greg Claytonab65b342011-04-13 22:47:15 +0000342static Mutex &
343GetDisassemblerMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344{
Greg Claytonab65b342011-04-13 22:47:15 +0000345 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
346 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347}
348
Greg Claytonab65b342011-04-13 22:47:15 +0000349static DisassemblerInstances &
350GetDisassemblerInstances ()
351{
352 static DisassemblerInstances g_instances;
353 return g_instances;
354}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355
356bool
357PluginManager::RegisterPlugin
358(
359 const char *name,
360 const char *description,
361 DisassemblerCreateInstance create_callback
362)
363{
364 if (create_callback)
365 {
366 DisassemblerInstance instance;
367 assert (name && name[0]);
368 instance.name = name;
369 if (description && description[0])
370 instance.description = description;
371 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000372 Mutex::Locker locker (GetDisassemblerMutex ());
373 GetDisassemblerInstances ().push_back (instance);
374 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 }
376 return false;
377}
378
379bool
380PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback)
381{
382 if (create_callback)
383 {
Greg Claytonab65b342011-04-13 22:47:15 +0000384 Mutex::Locker locker (GetDisassemblerMutex ());
385 DisassemblerInstances &instances = GetDisassemblerInstances ();
386
387 DisassemblerInstances::iterator pos, end = instances.end();
388 for (pos = instances.begin(); pos != end; ++ pos)
389 {
390 if (pos->create_callback == create_callback)
391 {
392 instances.erase(pos);
393 return true;
394 }
395 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 }
397 return false;
398}
399
400DisassemblerCreateInstance
401PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx)
402{
Greg Claytonab65b342011-04-13 22:47:15 +0000403 Mutex::Locker locker (GetDisassemblerMutex ());
404 DisassemblerInstances &instances = GetDisassemblerInstances ();
405 if (idx < instances.size())
406 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000407 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408}
409
410DisassemblerCreateInstance
411PluginManager::GetDisassemblerCreateCallbackForPluginName (const char *name)
412{
413 if (name && name[0])
414 {
Greg Claytonab65b342011-04-13 22:47:15 +0000415 llvm::StringRef name_sref(name);
416 Mutex::Locker locker (GetDisassemblerMutex ());
417 DisassemblerInstances &instances = GetDisassemblerInstances ();
418
419 DisassemblerInstances::iterator pos, end = instances.end();
420 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 {
Greg Claytonab65b342011-04-13 22:47:15 +0000422 if (name_sref.equals (pos->name))
423 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 }
425 }
426 return NULL;
427}
428
429
430
431#pragma mark DynamicLoader
432
433
Jason Molenda743e86a2010-06-11 23:44:18 +0000434struct DynamicLoaderInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435{
436 DynamicLoaderInstance() :
437 name(),
438 description(),
439 create_callback(NULL)
440 {
441 }
442
443 std::string name;
444 std::string description;
445 DynamicLoaderCreateInstance create_callback;
446};
447
448typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances;
449
Greg Claytonab65b342011-04-13 22:47:15 +0000450
451static Mutex &
452GetDynamicLoaderMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453{
Greg Claytonab65b342011-04-13 22:47:15 +0000454 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
455 return g_instances_mutex;
456}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457
Greg Claytonab65b342011-04-13 22:47:15 +0000458static DynamicLoaderInstances &
459GetDynamicLoaderInstances ()
460{
461 static DynamicLoaderInstances g_instances;
462 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463}
464
465
466bool
467PluginManager::RegisterPlugin
468(
469 const char *name,
470 const char *description,
471 DynamicLoaderCreateInstance create_callback
472)
473{
474 if (create_callback)
475 {
476 DynamicLoaderInstance instance;
477 assert (name && name[0]);
478 instance.name = name;
479 if (description && description[0])
480 instance.description = description;
481 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000482 Mutex::Locker locker (GetDynamicLoaderMutex ());
483 GetDynamicLoaderInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 }
485 return false;
486}
487
488bool
489PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback)
490{
491 if (create_callback)
492 {
Greg Claytonab65b342011-04-13 22:47:15 +0000493 Mutex::Locker locker (GetDynamicLoaderMutex ());
494 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
495
496 DynamicLoaderInstances::iterator pos, end = instances.end();
497 for (pos = instances.begin(); pos != end; ++ pos)
498 {
499 if (pos->create_callback == create_callback)
500 {
501 instances.erase(pos);
502 return true;
503 }
504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 }
506 return false;
507}
508
509DynamicLoaderCreateInstance
510PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx)
511{
Greg Claytonab65b342011-04-13 22:47:15 +0000512 Mutex::Locker locker (GetDynamicLoaderMutex ());
513 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
514 if (idx < instances.size())
515 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000516 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517}
518
519DynamicLoaderCreateInstance
520PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const char *name)
521{
522 if (name && name[0])
523 {
Greg Claytonab65b342011-04-13 22:47:15 +0000524 llvm::StringRef name_sref(name);
525 Mutex::Locker locker (GetDynamicLoaderMutex ());
526 DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
527
528 DynamicLoaderInstances::iterator pos, end = instances.end();
529 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 {
Greg Claytonab65b342011-04-13 22:47:15 +0000531 if (name_sref.equals (pos->name))
532 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 }
534 }
535 return NULL;
536}
537
Greg Claytonf03bbe22011-02-01 01:37:45 +0000538#pragma mark EmulateInstruction
539
540
541struct EmulateInstructionInstance
542{
543 EmulateInstructionInstance() :
544 name(),
545 description(),
546 create_callback(NULL)
547 {
548 }
549
550 std::string name;
551 std::string description;
552 EmulateInstructionCreateInstance create_callback;
553};
554
555typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances;
556
Greg Claytonab65b342011-04-13 22:47:15 +0000557static Mutex &
558GetEmulateInstructionMutex ()
Greg Claytonf03bbe22011-02-01 01:37:45 +0000559{
Greg Claytonab65b342011-04-13 22:47:15 +0000560 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
561 return g_instances_mutex;
562}
563
564static EmulateInstructionInstances &
565GetEmulateInstructionInstances ()
566{
567 static EmulateInstructionInstances g_instances;
568 return g_instances;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000569}
570
571
572bool
573PluginManager::RegisterPlugin
574(
Greg Clayton4272cc72011-02-02 02:24:04 +0000575 const char *name,
576 const char *description,
577 EmulateInstructionCreateInstance create_callback
578)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000579{
580 if (create_callback)
581 {
582 EmulateInstructionInstance instance;
583 assert (name && name[0]);
584 instance.name = name;
585 if (description && description[0])
586 instance.description = description;
587 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000588 Mutex::Locker locker (GetEmulateInstructionMutex ());
589 GetEmulateInstructionInstances ().push_back (instance);
Greg Claytonf03bbe22011-02-01 01:37:45 +0000590 }
591 return false;
592}
593
594bool
595PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callback)
596{
597 if (create_callback)
598 {
Greg Claytonab65b342011-04-13 22:47:15 +0000599 Mutex::Locker locker (GetEmulateInstructionMutex ());
600 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
601
602 EmulateInstructionInstances::iterator pos, end = instances.end();
603 for (pos = instances.begin(); pos != end; ++ pos)
604 {
605 if (pos->create_callback == create_callback)
606 {
607 instances.erase(pos);
608 return true;
609 }
610 }
Greg Claytonf03bbe22011-02-01 01:37:45 +0000611 }
612 return false;
613}
614
615EmulateInstructionCreateInstance
616PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx)
617{
Greg Claytonab65b342011-04-13 22:47:15 +0000618 Mutex::Locker locker (GetEmulateInstructionMutex ());
619 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
620 if (idx < instances.size())
621 return instances[idx].create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000622 return NULL;
623}
624
625EmulateInstructionCreateInstance
626PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const char *name)
627{
628 if (name && name[0])
629 {
Greg Claytonab65b342011-04-13 22:47:15 +0000630 llvm::StringRef name_sref(name);
631 Mutex::Locker locker (GetEmulateInstructionMutex ());
632 EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
633
634 EmulateInstructionInstances::iterator pos, end = instances.end();
635 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytonf03bbe22011-02-01 01:37:45 +0000636 {
Greg Claytonab65b342011-04-13 22:47:15 +0000637 if (name_sref.equals (pos->name))
638 return pos->create_callback;
Greg Claytonf03bbe22011-02-01 01:37:45 +0000639 }
640 }
641 return NULL;
642}
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000643#pragma mark OperatingSystem
644
645
646struct OperatingSystemInstance
647{
648 OperatingSystemInstance() :
649 name(),
650 description(),
651 create_callback(NULL)
652 {
653 }
654
655 std::string name;
656 std::string description;
657 OperatingSystemCreateInstance create_callback;
658};
659
660typedef std::vector<OperatingSystemInstance> OperatingSystemInstances;
661
662static Mutex &
663GetOperatingSystemMutex ()
664{
665 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
666 return g_instances_mutex;
667}
668
669static OperatingSystemInstances &
670GetOperatingSystemInstances ()
671{
672 static OperatingSystemInstances g_instances;
673 return g_instances;
674}
675
676bool
677PluginManager::RegisterPlugin
678(
679 const char *name,
680 const char *description,
681 OperatingSystemCreateInstance create_callback
682 )
683{
684 if (create_callback)
685 {
686 OperatingSystemInstance instance;
687 assert (name && name[0]);
688 instance.name = name;
689 if (description && description[0])
690 instance.description = description;
691 instance.create_callback = create_callback;
692 Mutex::Locker locker (GetOperatingSystemMutex ());
693 GetOperatingSystemInstances ().push_back (instance);
694 }
695 return false;
696}
697
698bool
699PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback)
700{
701 if (create_callback)
702 {
703 Mutex::Locker locker (GetOperatingSystemMutex ());
704 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
705
706 OperatingSystemInstances::iterator pos, end = instances.end();
707 for (pos = instances.begin(); pos != end; ++ pos)
708 {
709 if (pos->create_callback == create_callback)
710 {
711 instances.erase(pos);
712 return true;
713 }
714 }
715 }
716 return false;
717}
718
719OperatingSystemCreateInstance
720PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx)
721{
722 Mutex::Locker locker (GetOperatingSystemMutex ());
723 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
724 if (idx < instances.size())
725 return instances[idx].create_callback;
726 return NULL;
727}
728
729OperatingSystemCreateInstance
730PluginManager::GetOperatingSystemCreateCallbackForPluginName (const char *name)
731{
732 if (name && name[0])
733 {
734 llvm::StringRef name_sref(name);
735 Mutex::Locker locker (GetOperatingSystemMutex ());
736 OperatingSystemInstances &instances = GetOperatingSystemInstances ();
737
738 OperatingSystemInstances::iterator pos, end = instances.end();
739 for (pos = instances.begin(); pos != end; ++ pos)
740 {
741 if (name_sref.equals (pos->name))
742 return pos->create_callback;
743 }
744 }
745 return NULL;
746}
Greg Claytonf03bbe22011-02-01 01:37:45 +0000747
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748
Jim Ingham22777012010-09-23 02:01:19 +0000749#pragma mark LanguageRuntime
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750
751
Jim Ingham22777012010-09-23 02:01:19 +0000752struct LanguageRuntimeInstance
753{
754 LanguageRuntimeInstance() :
755 name(),
756 description(),
757 create_callback(NULL)
758 {
759 }
760
761 std::string name;
762 std::string description;
763 LanguageRuntimeCreateInstance create_callback;
764};
765
766typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances;
767
Greg Claytonab65b342011-04-13 22:47:15 +0000768static Mutex &
769GetLanguageRuntimeMutex ()
Jim Ingham22777012010-09-23 02:01:19 +0000770{
Greg Claytonab65b342011-04-13 22:47:15 +0000771 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
772 return g_instances_mutex;
Jim Ingham22777012010-09-23 02:01:19 +0000773}
774
Greg Claytonab65b342011-04-13 22:47:15 +0000775static LanguageRuntimeInstances &
776GetLanguageRuntimeInstances ()
777{
778 static LanguageRuntimeInstances g_instances;
779 return g_instances;
780}
Jim Ingham22777012010-09-23 02:01:19 +0000781
782bool
783PluginManager::RegisterPlugin
Greg Clayton4272cc72011-02-02 02:24:04 +0000784(
785 const char *name,
786 const char *description,
787 LanguageRuntimeCreateInstance create_callback
788)
Jim Ingham22777012010-09-23 02:01:19 +0000789{
790 if (create_callback)
791 {
792 LanguageRuntimeInstance instance;
793 assert (name && name[0]);
794 instance.name = name;
795 if (description && description[0])
796 instance.description = description;
797 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000798 Mutex::Locker locker (GetLanguageRuntimeMutex ());
799 GetLanguageRuntimeInstances ().push_back (instance);
Jim Ingham22777012010-09-23 02:01:19 +0000800 }
801 return false;
802}
803
804bool
805PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback)
806{
807 if (create_callback)
808 {
Greg Claytonab65b342011-04-13 22:47:15 +0000809 Mutex::Locker locker (GetLanguageRuntimeMutex ());
810 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
811
812 LanguageRuntimeInstances::iterator pos, end = instances.end();
813 for (pos = instances.begin(); pos != end; ++ pos)
814 {
815 if (pos->create_callback == create_callback)
816 {
817 instances.erase(pos);
818 return true;
819 }
820 }
Jim Ingham22777012010-09-23 02:01:19 +0000821 }
822 return false;
823}
824
825LanguageRuntimeCreateInstance
826PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx)
827{
Greg Claytonab65b342011-04-13 22:47:15 +0000828 Mutex::Locker locker (GetLanguageRuntimeMutex ());
829 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
830 if (idx < instances.size())
831 return instances[idx].create_callback;
Jim Ingham22777012010-09-23 02:01:19 +0000832 return NULL;
833}
834
835LanguageRuntimeCreateInstance
836PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const char *name)
837{
838 if (name && name[0])
839 {
Greg Claytonab65b342011-04-13 22:47:15 +0000840 llvm::StringRef name_sref(name);
841 Mutex::Locker locker (GetLanguageRuntimeMutex ());
842 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
843
844 LanguageRuntimeInstances::iterator pos, end = instances.end();
845 for (pos = instances.begin(); pos != end; ++ pos)
Jim Ingham22777012010-09-23 02:01:19 +0000846 {
Greg Claytonab65b342011-04-13 22:47:15 +0000847 if (name_sref.equals (pos->name))
848 return pos->create_callback;
Jim Ingham22777012010-09-23 02:01:19 +0000849 }
850 }
851 return NULL;
852}
853
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854#pragma mark ObjectFile
855
Jason Molenda743e86a2010-06-11 23:44:18 +0000856struct ObjectFileInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857{
858 ObjectFileInstance() :
859 name(),
860 description(),
861 create_callback(NULL)
862 {
863 }
864
865 std::string name;
866 std::string description;
867 ObjectFileCreateInstance create_callback;
Greg Claytonc9660542012-02-05 02:38:54 +0000868 ObjectFileCreateMemoryInstance create_memory_callback;
869
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870};
871
872typedef std::vector<ObjectFileInstance> ObjectFileInstances;
873
Greg Claytonab65b342011-04-13 22:47:15 +0000874static Mutex &
875GetObjectFileMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000876{
Greg Claytonab65b342011-04-13 22:47:15 +0000877 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
878 return g_instances_mutex;
879}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880
Greg Claytonab65b342011-04-13 22:47:15 +0000881static ObjectFileInstances &
882GetObjectFileInstances ()
883{
884 static ObjectFileInstances g_instances;
885 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000886}
887
888
889bool
890PluginManager::RegisterPlugin
891(
892 const char *name,
893 const char *description,
Greg Claytonc9660542012-02-05 02:38:54 +0000894 ObjectFileCreateInstance create_callback,
895 ObjectFileCreateMemoryInstance create_memory_callback
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896)
897{
898 if (create_callback)
899 {
900 ObjectFileInstance instance;
901 assert (name && name[0]);
902 instance.name = name;
903 if (description && description[0])
904 instance.description = description;
905 instance.create_callback = create_callback;
Greg Claytonc9660542012-02-05 02:38:54 +0000906 instance.create_memory_callback = create_memory_callback;
Greg Claytonab65b342011-04-13 22:47:15 +0000907 Mutex::Locker locker (GetObjectFileMutex ());
908 GetObjectFileInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 }
910 return false;
911}
912
913bool
914PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback)
915{
916 if (create_callback)
917 {
Greg Claytonab65b342011-04-13 22:47:15 +0000918 Mutex::Locker locker (GetObjectFileMutex ());
919 ObjectFileInstances &instances = GetObjectFileInstances ();
920
921 ObjectFileInstances::iterator pos, end = instances.end();
922 for (pos = instances.begin(); pos != end; ++ pos)
923 {
924 if (pos->create_callback == create_callback)
925 {
926 instances.erase(pos);
927 return true;
928 }
929 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 }
931 return false;
932}
933
934ObjectFileCreateInstance
935PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx)
936{
Greg Claytonab65b342011-04-13 22:47:15 +0000937 Mutex::Locker locker (GetObjectFileMutex ());
938 ObjectFileInstances &instances = GetObjectFileInstances ();
939 if (idx < instances.size())
940 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +0000941 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000942}
Greg Claytonab65b342011-04-13 22:47:15 +0000943
Greg Claytonc9660542012-02-05 02:38:54 +0000944
945ObjectFileCreateMemoryInstance
946PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx)
947{
948 Mutex::Locker locker (GetObjectFileMutex ());
949 ObjectFileInstances &instances = GetObjectFileInstances ();
950 if (idx < instances.size())
951 return instances[idx].create_memory_callback;
952 return NULL;
953}
954
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000955ObjectFileCreateInstance
956PluginManager::GetObjectFileCreateCallbackForPluginName (const char *name)
957{
958 if (name && name[0])
959 {
Greg Claytonab65b342011-04-13 22:47:15 +0000960 llvm::StringRef name_sref(name);
961 Mutex::Locker locker (GetObjectFileMutex ());
962 ObjectFileInstances &instances = GetObjectFileInstances ();
963
964 ObjectFileInstances::iterator pos, end = instances.end();
965 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966 {
Greg Claytonab65b342011-04-13 22:47:15 +0000967 if (name_sref.equals (pos->name))
968 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000969 }
970 }
971 return NULL;
972}
973
974
Greg Claytonc9660542012-02-05 02:38:54 +0000975ObjectFileCreateMemoryInstance
976PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const char *name)
977{
978 if (name && name[0])
979 {
980 llvm::StringRef name_sref(name);
981 Mutex::Locker locker (GetObjectFileMutex ());
982 ObjectFileInstances &instances = GetObjectFileInstances ();
983
984 ObjectFileInstances::iterator pos, end = instances.end();
985 for (pos = instances.begin(); pos != end; ++ pos)
986 {
987 if (name_sref.equals (pos->name))
988 return pos->create_memory_callback;
989 }
990 }
991 return NULL;
992}
993
994
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995
996#pragma mark ObjectContainer
997
Jason Molenda743e86a2010-06-11 23:44:18 +0000998struct ObjectContainerInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999{
1000 ObjectContainerInstance() :
1001 name(),
1002 description(),
1003 create_callback(NULL)
1004 {
1005 }
1006
1007 std::string name;
1008 std::string description;
1009 ObjectContainerCreateInstance create_callback;
1010};
1011
1012typedef std::vector<ObjectContainerInstance> ObjectContainerInstances;
1013
Greg Claytonab65b342011-04-13 22:47:15 +00001014static Mutex &
1015GetObjectContainerMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016{
Greg Claytonab65b342011-04-13 22:47:15 +00001017 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1018 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019}
1020
Greg Claytonab65b342011-04-13 22:47:15 +00001021static ObjectContainerInstances &
1022GetObjectContainerInstances ()
1023{
1024 static ObjectContainerInstances g_instances;
1025 return g_instances;
1026}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027
1028bool
1029PluginManager::RegisterPlugin
1030(
1031 const char *name,
1032 const char *description,
1033 ObjectContainerCreateInstance create_callback
1034)
1035{
1036 if (create_callback)
1037 {
1038 ObjectContainerInstance instance;
1039 assert (name && name[0]);
1040 instance.name = name;
1041 if (description && description[0])
1042 instance.description = description;
1043 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001044 Mutex::Locker locker (GetObjectContainerMutex ());
1045 GetObjectContainerInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046 }
1047 return false;
1048}
1049
1050bool
1051PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback)
1052{
1053 if (create_callback)
1054 {
Greg Claytonab65b342011-04-13 22:47:15 +00001055 Mutex::Locker locker (GetObjectContainerMutex ());
1056 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1057
1058 ObjectContainerInstances::iterator pos, end = instances.end();
1059 for (pos = instances.begin(); pos != end; ++ pos)
1060 {
1061 if (pos->create_callback == create_callback)
1062 {
1063 instances.erase(pos);
1064 return true;
1065 }
1066 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001067 }
1068 return false;
1069}
1070
1071ObjectContainerCreateInstance
1072PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx)
1073{
Greg Claytonab65b342011-04-13 22:47:15 +00001074 Mutex::Locker locker (GetObjectContainerMutex ());
1075 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1076 if (idx < instances.size())
1077 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001078 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079}
Greg Claytonab65b342011-04-13 22:47:15 +00001080
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081ObjectContainerCreateInstance
1082PluginManager::GetObjectContainerCreateCallbackForPluginName (const char *name)
1083{
1084 if (name && name[0])
1085 {
Greg Claytonab65b342011-04-13 22:47:15 +00001086 llvm::StringRef name_sref(name);
1087 Mutex::Locker locker (GetObjectContainerMutex ());
1088 ObjectContainerInstances &instances = GetObjectContainerInstances ();
1089
1090 ObjectContainerInstances::iterator pos, end = instances.end();
1091 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092 {
Greg Claytonab65b342011-04-13 22:47:15 +00001093 if (name_sref.equals (pos->name))
1094 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001095 }
1096 }
1097 return NULL;
1098}
1099
1100#pragma mark LogChannel
1101
Greg Claytonab65b342011-04-13 22:47:15 +00001102struct LogInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103{
Greg Claytonab65b342011-04-13 22:47:15 +00001104 LogInstance() :
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001105 name(),
1106 description(),
1107 create_callback(NULL)
1108 {
1109 }
1110
1111 std::string name;
1112 std::string description;
1113 LogChannelCreateInstance create_callback;
1114};
1115
Greg Claytonab65b342011-04-13 22:47:15 +00001116typedef std::vector<LogInstance> LogInstances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001117
Greg Claytonab65b342011-04-13 22:47:15 +00001118static Mutex &
1119GetLogMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120{
Greg Claytonab65b342011-04-13 22:47:15 +00001121 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1122 return g_instances_mutex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001123}
1124
Greg Claytonab65b342011-04-13 22:47:15 +00001125static LogInstances &
1126GetLogInstances ()
1127{
1128 static LogInstances g_instances;
1129 return g_instances;
1130}
1131
1132
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133
1134bool
1135PluginManager::RegisterPlugin
1136(
1137 const char *name,
1138 const char *description,
1139 LogChannelCreateInstance create_callback
1140)
1141{
1142 if (create_callback)
1143 {
Greg Claytonab65b342011-04-13 22:47:15 +00001144 LogInstance instance;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145 assert (name && name[0]);
1146 instance.name = name;
1147 if (description && description[0])
1148 instance.description = description;
1149 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001150 Mutex::Locker locker (GetLogMutex ());
1151 GetLogInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152 }
1153 return false;
1154}
1155
1156bool
1157PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback)
1158{
1159 if (create_callback)
1160 {
Greg Claytonab65b342011-04-13 22:47:15 +00001161 Mutex::Locker locker (GetLogMutex ());
1162 LogInstances &instances = GetLogInstances ();
1163
1164 LogInstances::iterator pos, end = instances.end();
1165 for (pos = instances.begin(); pos != end; ++ pos)
1166 {
1167 if (pos->create_callback == create_callback)
1168 {
1169 instances.erase(pos);
1170 return true;
1171 }
1172 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 }
1174 return false;
1175}
1176
1177const char *
1178PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx)
1179{
Greg Claytonab65b342011-04-13 22:47:15 +00001180 Mutex::Locker locker (GetLogMutex ());
1181 LogInstances &instances = GetLogInstances ();
1182 if (idx < instances.size())
1183 return instances[idx].name.c_str();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 return NULL;
1185}
1186
1187
1188LogChannelCreateInstance
1189PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx)
1190{
Greg Claytonab65b342011-04-13 22:47:15 +00001191 Mutex::Locker locker (GetLogMutex ());
1192 LogInstances &instances = GetLogInstances ();
1193 if (idx < instances.size())
1194 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001195 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196}
1197
1198LogChannelCreateInstance
1199PluginManager::GetLogChannelCreateCallbackForPluginName (const char *name)
1200{
1201 if (name && name[0])
1202 {
Greg Claytonab65b342011-04-13 22:47:15 +00001203 llvm::StringRef name_sref(name);
1204 Mutex::Locker locker (GetLogMutex ());
1205 LogInstances &instances = GetLogInstances ();
1206
1207 LogInstances::iterator pos, end = instances.end();
1208 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 {
Greg Claytonab65b342011-04-13 22:47:15 +00001210 if (name_sref.equals (pos->name))
1211 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 }
1214 return NULL;
1215}
1216
Greg Claytone996fd32011-03-08 22:40:15 +00001217#pragma mark Platform
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218
Greg Claytone996fd32011-03-08 22:40:15 +00001219struct PlatformInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220{
Greg Claytone996fd32011-03-08 22:40:15 +00001221 PlatformInstance() :
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 name(),
1223 description(),
1224 create_callback(NULL)
1225 {
1226 }
Greg Claytone996fd32011-03-08 22:40:15 +00001227
1228 std::string name;
1229 std::string description;
1230 PlatformCreateInstance create_callback;
1231};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232
Greg Claytone996fd32011-03-08 22:40:15 +00001233typedef std::vector<PlatformInstance> PlatformInstances;
1234
Greg Claytonded470d2011-03-19 01:12:21 +00001235static Mutex &
1236GetPlatformInstancesMutex ()
Greg Claytone996fd32011-03-08 22:40:15 +00001237{
Greg Claytonded470d2011-03-19 01:12:21 +00001238 static Mutex g_platform_instances_mutex (Mutex::eMutexTypeRecursive);
1239 return g_platform_instances_mutex;
Greg Claytone996fd32011-03-08 22:40:15 +00001240}
1241
Greg Claytonded470d2011-03-19 01:12:21 +00001242static PlatformInstances &
1243GetPlatformInstances ()
1244{
1245 static PlatformInstances g_platform_instances;
1246 return g_platform_instances;
1247}
Greg Claytone996fd32011-03-08 22:40:15 +00001248
Greg Claytonab65b342011-04-13 22:47:15 +00001249
Greg Claytone996fd32011-03-08 22:40:15 +00001250bool
1251PluginManager::RegisterPlugin (const char *name,
1252 const char *description,
1253 PlatformCreateInstance create_callback)
1254{
1255 if (create_callback)
1256 {
Greg Claytonded470d2011-03-19 01:12:21 +00001257 Mutex::Locker locker (GetPlatformInstancesMutex ());
1258
Greg Claytone996fd32011-03-08 22:40:15 +00001259 PlatformInstance instance;
1260 assert (name && name[0]);
1261 instance.name = name;
1262 if (description && description[0])
1263 instance.description = description;
1264 instance.create_callback = create_callback;
Greg Claytonded470d2011-03-19 01:12:21 +00001265 GetPlatformInstances ().push_back (instance);
1266 return true;
Greg Claytone996fd32011-03-08 22:40:15 +00001267 }
1268 return false;
1269}
1270
1271const char *
1272PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx)
1273{
Greg Claytonded470d2011-03-19 01:12:21 +00001274 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001275 PlatformInstances &instances = GetPlatformInstances ();
1276 if (idx < instances.size())
1277 return instances[idx].name.c_str();
Greg Claytone996fd32011-03-08 22:40:15 +00001278 return NULL;
1279}
1280
1281const char *
1282PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx)
1283{
Greg Claytonded470d2011-03-19 01:12:21 +00001284 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001285 PlatformInstances &instances = GetPlatformInstances ();
1286 if (idx < instances.size())
1287 return instances[idx].description.c_str();
Greg Claytone996fd32011-03-08 22:40:15 +00001288 return NULL;
1289}
1290
1291bool
1292PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback)
1293{
1294 if (create_callback)
1295 {
Greg Claytonded470d2011-03-19 01:12:21 +00001296 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001297 PlatformInstances &instances = GetPlatformInstances ();
Greg Claytonded470d2011-03-19 01:12:21 +00001298
Greg Claytonab65b342011-04-13 22:47:15 +00001299 PlatformInstances::iterator pos, end = instances.end();
1300 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytonded470d2011-03-19 01:12:21 +00001301 {
1302 if (pos->create_callback == create_callback)
1303 {
Greg Claytonab65b342011-04-13 22:47:15 +00001304 instances.erase(pos);
Greg Claytonded470d2011-03-19 01:12:21 +00001305 return true;
1306 }
1307 }
Greg Claytone996fd32011-03-08 22:40:15 +00001308 }
1309 return false;
1310}
1311
1312PlatformCreateInstance
1313PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx)
1314{
Greg Claytonded470d2011-03-19 01:12:21 +00001315 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001316 PlatformInstances &instances = GetPlatformInstances ();
1317 if (idx < instances.size())
1318 return instances[idx].create_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001319 return NULL;
1320}
1321
1322PlatformCreateInstance
1323PluginManager::GetPlatformCreateCallbackForPluginName (const char *name)
1324{
1325 if (name && name[0])
1326 {
Greg Claytonded470d2011-03-19 01:12:21 +00001327 Mutex::Locker locker (GetPlatformInstancesMutex ());
Greg Claytonab65b342011-04-13 22:47:15 +00001328 PlatformInstances &instances = GetPlatformInstances ();
1329 llvm::StringRef name_sref(name);
Greg Claytonded470d2011-03-19 01:12:21 +00001330
Greg Claytonab65b342011-04-13 22:47:15 +00001331 PlatformInstances::iterator pos, end = instances.end();
1332 for (pos = instances.begin(); pos != end; ++ pos)
Greg Claytone996fd32011-03-08 22:40:15 +00001333 {
Greg Clayton7260f622011-04-18 08:33:37 +00001334 if (name_sref.equals (pos->name))
Greg Claytonded470d2011-03-19 01:12:21 +00001335 return pos->create_callback;
Greg Claytone996fd32011-03-08 22:40:15 +00001336 }
1337 }
1338 return NULL;
1339}
1340
Greg Claytonab65b342011-04-13 22:47:15 +00001341uint32_t
1342PluginManager::AutoCompletePlatformName (const char *name, StringList &matches)
1343{
1344 if (name && name[0])
1345 {
1346 Mutex::Locker locker (GetPlatformInstancesMutex ());
1347 PlatformInstances &instances = GetPlatformInstances ();
1348 llvm::StringRef name_sref(name);
1349
1350 PlatformInstances::iterator pos, end = instances.end();
1351 for (pos = instances.begin(); pos != end; ++ pos)
1352 {
Greg Clayton7260f622011-04-18 08:33:37 +00001353 llvm::StringRef plugin_name (pos->name);
1354 if (plugin_name.startswith(name_sref))
1355 matches.AppendString (plugin_name.data());
Greg Claytonab65b342011-04-13 22:47:15 +00001356 }
1357 }
1358 return matches.GetSize();
1359}
1360
Greg Claytone996fd32011-03-08 22:40:15 +00001361#pragma mark Process
1362
1363struct ProcessInstance
1364{
1365 ProcessInstance() :
1366 name(),
1367 description(),
1368 create_callback(NULL)
1369 {
1370 }
1371
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372 std::string name;
1373 std::string description;
1374 ProcessCreateInstance create_callback;
1375};
1376
1377typedef std::vector<ProcessInstance> ProcessInstances;
1378
Greg Claytonab65b342011-04-13 22:47:15 +00001379static Mutex &
1380GetProcessMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381{
Greg Claytonab65b342011-04-13 22:47:15 +00001382 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1383 return g_instances_mutex;
1384}
1385
1386static ProcessInstances &
1387GetProcessInstances ()
1388{
1389 static ProcessInstances g_instances;
1390 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391}
1392
1393
1394bool
1395PluginManager::RegisterPlugin
1396(
Greg Claytone996fd32011-03-08 22:40:15 +00001397 const char *name,
1398 const char *description,
1399 ProcessCreateInstance create_callback
1400 )
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001401{
1402 if (create_callback)
1403 {
1404 ProcessInstance instance;
1405 assert (name && name[0]);
1406 instance.name = name;
1407 if (description && description[0])
1408 instance.description = description;
1409 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001410 Mutex::Locker locker (GetProcessMutex ());
1411 GetProcessInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412 }
1413 return false;
1414}
1415
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001416const char *
1417PluginManager::GetProcessPluginNameAtIndex (uint32_t idx)
1418{
Greg Claytonab65b342011-04-13 22:47:15 +00001419 Mutex::Locker locker (GetProcessMutex ());
1420 ProcessInstances &instances = GetProcessInstances ();
1421 if (idx < instances.size())
1422 return instances[idx].name.c_str();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001423 return NULL;
1424}
1425
1426const char *
1427PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx)
1428{
Greg Claytonab65b342011-04-13 22:47:15 +00001429 Mutex::Locker locker (GetProcessMutex ());
1430 ProcessInstances &instances = GetProcessInstances ();
1431 if (idx < instances.size())
1432 return instances[idx].description.c_str();
Greg Claytonbfe5f3b2011-02-18 01:44:25 +00001433 return NULL;
1434}
1435
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436bool
1437PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback)
1438{
1439 if (create_callback)
1440 {
Greg Claytonab65b342011-04-13 22:47:15 +00001441 Mutex::Locker locker (GetProcessMutex ());
1442 ProcessInstances &instances = GetProcessInstances ();
1443
1444 ProcessInstances::iterator pos, end = instances.end();
1445 for (pos = instances.begin(); pos != end; ++ pos)
1446 {
1447 if (pos->create_callback == create_callback)
1448 {
1449 instances.erase(pos);
1450 return true;
1451 }
1452 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453 }
1454 return false;
1455}
1456
1457ProcessCreateInstance
1458PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx)
1459{
Greg Claytonab65b342011-04-13 22:47:15 +00001460 Mutex::Locker locker (GetProcessMutex ());
1461 ProcessInstances &instances = GetProcessInstances ();
1462 if (idx < instances.size())
1463 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001464 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465}
1466
Greg Claytonab65b342011-04-13 22:47:15 +00001467
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468ProcessCreateInstance
1469PluginManager::GetProcessCreateCallbackForPluginName (const char *name)
1470{
1471 if (name && name[0])
1472 {
Greg Claytonab65b342011-04-13 22:47:15 +00001473 llvm::StringRef name_sref(name);
1474 Mutex::Locker locker (GetProcessMutex ());
1475 ProcessInstances &instances = GetProcessInstances ();
1476
1477 ProcessInstances::iterator pos, end = instances.end();
1478 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001479 {
Greg Claytonab65b342011-04-13 22:47:15 +00001480 if (name_sref.equals (pos->name))
1481 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 }
1483 }
1484 return NULL;
1485}
1486
1487#pragma mark SymbolFile
1488
Jason Molenda743e86a2010-06-11 23:44:18 +00001489struct SymbolFileInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490{
1491 SymbolFileInstance() :
1492 name(),
1493 description(),
1494 create_callback(NULL)
1495 {
1496 }
1497
1498 std::string name;
1499 std::string description;
1500 SymbolFileCreateInstance create_callback;
1501};
1502
1503typedef std::vector<SymbolFileInstance> SymbolFileInstances;
1504
Greg Claytonab65b342011-04-13 22:47:15 +00001505static Mutex &
1506GetSymbolFileMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001507{
Greg Claytonab65b342011-04-13 22:47:15 +00001508 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1509 return g_instances_mutex;
1510}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001511
Greg Claytonab65b342011-04-13 22:47:15 +00001512static SymbolFileInstances &
1513GetSymbolFileInstances ()
1514{
1515 static SymbolFileInstances g_instances;
1516 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001517}
1518
1519
1520bool
1521PluginManager::RegisterPlugin
1522(
1523 const char *name,
1524 const char *description,
1525 SymbolFileCreateInstance create_callback
1526)
1527{
1528 if (create_callback)
1529 {
1530 SymbolFileInstance instance;
1531 assert (name && name[0]);
1532 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 (GetSymbolFileMutex ());
1537 GetSymbolFileInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001538 }
1539 return false;
1540}
1541
1542bool
1543PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback)
1544{
1545 if (create_callback)
1546 {
Greg Claytonab65b342011-04-13 22:47:15 +00001547 Mutex::Locker locker (GetSymbolFileMutex ());
1548 SymbolFileInstances &instances = GetSymbolFileInstances ();
1549
1550 SymbolFileInstances::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
1563SymbolFileCreateInstance
1564PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx)
1565{
Greg Claytonab65b342011-04-13 22:47:15 +00001566 Mutex::Locker locker (GetSymbolFileMutex ());
1567 SymbolFileInstances &instances = GetSymbolFileInstances ();
1568 if (idx < instances.size())
1569 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001570 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571}
Greg Claytonab65b342011-04-13 22:47:15 +00001572
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001573SymbolFileCreateInstance
1574PluginManager::GetSymbolFileCreateCallbackForPluginName (const char *name)
1575{
1576 if (name && name[0])
1577 {
Greg Claytonab65b342011-04-13 22:47:15 +00001578 llvm::StringRef name_sref(name);
1579 Mutex::Locker locker (GetSymbolFileMutex ());
1580 SymbolFileInstances &instances = GetSymbolFileInstances ();
1581
1582 SymbolFileInstances::iterator pos, end = instances.end();
1583 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001584 {
Greg Claytonab65b342011-04-13 22:47:15 +00001585 if (name_sref.equals (pos->name))
1586 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001587 }
1588 }
1589 return NULL;
1590}
1591
1592
1593
1594#pragma mark SymbolVendor
1595
Jason Molenda743e86a2010-06-11 23:44:18 +00001596struct SymbolVendorInstance
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597{
1598 SymbolVendorInstance() :
1599 name(),
1600 description(),
1601 create_callback(NULL)
1602 {
1603 }
1604
1605 std::string name;
1606 std::string description;
1607 SymbolVendorCreateInstance create_callback;
1608};
1609
1610typedef std::vector<SymbolVendorInstance> SymbolVendorInstances;
1611
Greg Claytonab65b342011-04-13 22:47:15 +00001612static Mutex &
1613GetSymbolVendorMutex ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001614{
Greg Claytonab65b342011-04-13 22:47:15 +00001615 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1616 return g_instances_mutex;
1617}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618
Greg Claytonab65b342011-04-13 22:47:15 +00001619static SymbolVendorInstances &
1620GetSymbolVendorInstances ()
1621{
1622 static SymbolVendorInstances g_instances;
1623 return g_instances;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001624}
1625
1626bool
1627PluginManager::RegisterPlugin
1628(
1629 const char *name,
1630 const char *description,
1631 SymbolVendorCreateInstance create_callback
1632)
1633{
1634 if (create_callback)
1635 {
1636 SymbolVendorInstance instance;
1637 assert (name && name[0]);
1638 instance.name = name;
1639 if (description && description[0])
1640 instance.description = description;
1641 instance.create_callback = create_callback;
Greg Claytonab65b342011-04-13 22:47:15 +00001642 Mutex::Locker locker (GetSymbolVendorMutex ());
1643 GetSymbolVendorInstances ().push_back (instance);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 }
1645 return false;
1646}
1647
1648bool
1649PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback)
1650{
1651 if (create_callback)
1652 {
Greg Claytonab65b342011-04-13 22:47:15 +00001653 Mutex::Locker locker (GetSymbolVendorMutex ());
1654 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
1655
1656 SymbolVendorInstances::iterator pos, end = instances.end();
1657 for (pos = instances.begin(); pos != end; ++ pos)
1658 {
1659 if (pos->create_callback == create_callback)
1660 {
1661 instances.erase(pos);
1662 return true;
1663 }
1664 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001665 }
1666 return false;
1667}
1668
1669SymbolVendorCreateInstance
1670PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx)
1671{
Greg Claytonab65b342011-04-13 22:47:15 +00001672 Mutex::Locker locker (GetSymbolVendorMutex ());
1673 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
1674 if (idx < instances.size())
1675 return instances[idx].create_callback;
Jason Molenda743e86a2010-06-11 23:44:18 +00001676 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677}
1678
Greg Claytonab65b342011-04-13 22:47:15 +00001679
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001680SymbolVendorCreateInstance
1681PluginManager::GetSymbolVendorCreateCallbackForPluginName (const char *name)
1682{
1683 if (name && name[0])
1684 {
Greg Claytonab65b342011-04-13 22:47:15 +00001685 llvm::StringRef name_sref(name);
1686 Mutex::Locker locker (GetSymbolVendorMutex ());
1687 SymbolVendorInstances &instances = GetSymbolVendorInstances ();
1688
1689 SymbolVendorInstances::iterator pos, end = instances.end();
1690 for (pos = instances.begin(); pos != end; ++ pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001691 {
Greg Claytonab65b342011-04-13 22:47:15 +00001692 if (name_sref.equals (pos->name))
1693 return pos->create_callback;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001694 }
1695 }
1696 return NULL;
1697}
1698
1699
Greg Clayton7be25422011-04-25 21:14:26 +00001700#pragma mark UnwindAssembly
Jason Molendafbcb7f22010-09-10 07:49:16 +00001701
Greg Clayton7be25422011-04-25 21:14:26 +00001702struct UnwindAssemblyInstance
Jason Molendafbcb7f22010-09-10 07:49:16 +00001703{
Greg Clayton7be25422011-04-25 21:14:26 +00001704 UnwindAssemblyInstance() :
Jason Molendafbcb7f22010-09-10 07:49:16 +00001705 name(),
1706 description(),
1707 create_callback(NULL)
1708 {
1709 }
1710
1711 std::string name;
1712 std::string description;
Greg Clayton7be25422011-04-25 21:14:26 +00001713 UnwindAssemblyCreateInstance create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001714};
1715
Greg Clayton7be25422011-04-25 21:14:26 +00001716typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001717
Greg Claytonab65b342011-04-13 22:47:15 +00001718static Mutex &
Greg Clayton7be25422011-04-25 21:14:26 +00001719GetUnwindAssemblyMutex ()
Jason Molendafbcb7f22010-09-10 07:49:16 +00001720{
Greg Claytonab65b342011-04-13 22:47:15 +00001721 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
1722 return g_instances_mutex;
1723}
Jason Molendafbcb7f22010-09-10 07:49:16 +00001724
Greg Clayton7be25422011-04-25 21:14:26 +00001725static UnwindAssemblyInstances &
1726GetUnwindAssemblyInstances ()
Greg Claytonab65b342011-04-13 22:47:15 +00001727{
Greg Clayton7be25422011-04-25 21:14:26 +00001728 static UnwindAssemblyInstances g_instances;
Greg Claytonab65b342011-04-13 22:47:15 +00001729 return g_instances;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001730}
1731
1732bool
1733PluginManager::RegisterPlugin
1734(
1735 const char *name,
1736 const char *description,
Greg Clayton7be25422011-04-25 21:14:26 +00001737 UnwindAssemblyCreateInstance create_callback
Jason Molendafbcb7f22010-09-10 07:49:16 +00001738)
1739{
1740 if (create_callback)
1741 {
Greg Clayton7be25422011-04-25 21:14:26 +00001742 UnwindAssemblyInstance instance;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001743 assert (name && name[0]);
1744 instance.name = name;
1745 if (description && description[0])
1746 instance.description = description;
1747 instance.create_callback = create_callback;
Greg Clayton7be25422011-04-25 21:14:26 +00001748 Mutex::Locker locker (GetUnwindAssemblyMutex ());
1749 GetUnwindAssemblyInstances ().push_back (instance);
Jason Molendafbcb7f22010-09-10 07:49:16 +00001750 }
1751 return false;
1752}
1753
1754bool
Greg Clayton7be25422011-04-25 21:14:26 +00001755PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback)
Jason Molendafbcb7f22010-09-10 07:49:16 +00001756{
1757 if (create_callback)
1758 {
Greg Clayton7be25422011-04-25 21:14:26 +00001759 Mutex::Locker locker (GetUnwindAssemblyMutex ());
1760 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00001761
Greg Clayton7be25422011-04-25 21:14:26 +00001762 UnwindAssemblyInstances::iterator pos, end = instances.end();
Greg Claytonab65b342011-04-13 22:47:15 +00001763 for (pos = instances.begin(); pos != end; ++ pos)
1764 {
1765 if (pos->create_callback == create_callback)
1766 {
1767 instances.erase(pos);
1768 return true;
1769 }
1770 }
Jason Molendafbcb7f22010-09-10 07:49:16 +00001771 }
1772 return false;
1773}
1774
Greg Clayton7be25422011-04-25 21:14:26 +00001775UnwindAssemblyCreateInstance
1776PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx)
Jason Molendafbcb7f22010-09-10 07:49:16 +00001777{
Greg Clayton7be25422011-04-25 21:14:26 +00001778 Mutex::Locker locker (GetUnwindAssemblyMutex ());
1779 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00001780 if (idx < instances.size())
1781 return instances[idx].create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001782 return NULL;
1783}
1784
Greg Claytonab65b342011-04-13 22:47:15 +00001785
Greg Clayton7be25422011-04-25 21:14:26 +00001786UnwindAssemblyCreateInstance
1787PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const char *name)
Jason Molendafbcb7f22010-09-10 07:49:16 +00001788{
1789 if (name && name[0])
1790 {
Greg Claytonab65b342011-04-13 22:47:15 +00001791 llvm::StringRef name_sref(name);
Greg Clayton7be25422011-04-25 21:14:26 +00001792 Mutex::Locker locker (GetUnwindAssemblyMutex ());
1793 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
Greg Claytonab65b342011-04-13 22:47:15 +00001794
Greg Clayton7be25422011-04-25 21:14:26 +00001795 UnwindAssemblyInstances::iterator pos, end = instances.end();
Greg Claytonab65b342011-04-13 22:47:15 +00001796 for (pos = instances.begin(); pos != end; ++ pos)
Jason Molendafbcb7f22010-09-10 07:49:16 +00001797 {
Greg Claytonab65b342011-04-13 22:47:15 +00001798 if (name_sref.equals (pos->name))
1799 return pos->create_callback;
Jason Molendafbcb7f22010-09-10 07:49:16 +00001800 }
1801 }
1802 return NULL;
1803}
1804