LLDB  mainline
PluginManager.cpp
Go to the documentation of this file.
1 //===-- PluginManager.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/HostInfo.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/Utility/Status.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/DynamicLibrary.h"
21 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include <assert.h>
24 #include <map>
25 #include <memory>
26 #include <mutex>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 #if defined(_WIN32)
32 #endif
33 
34 using namespace lldb;
35 using namespace lldb_private;
36 
37 typedef bool (*PluginInitCallback)();
38 typedef void (*PluginTermCallback)();
39 
40 struct PluginInfo {
41  PluginInfo() : plugin_init_callback(nullptr), plugin_term_callback(nullptr) {}
42 
43  llvm::sys::DynamicLibrary library;
46 };
47 
48 typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
49 
50 static std::recursive_mutex &GetPluginMapMutex() {
51  static std::recursive_mutex g_plugin_map_mutex;
52  return g_plugin_map_mutex;
53 }
54 
56  static PluginTerminateMap g_plugin_map;
57  return g_plugin_map;
58 }
59 
60 static bool PluginIsLoaded(const FileSpec &plugin_file_spec) {
61  std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
62  PluginTerminateMap &plugin_map = GetPluginMap();
63  return plugin_map.find(plugin_file_spec) != plugin_map.end();
64 }
65 
66 static void SetPluginInfo(const FileSpec &plugin_file_spec,
67  const PluginInfo &plugin_info) {
68  std::lock_guard<std::recursive_mutex> guard(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 template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) {
75  return reinterpret_cast<FPtrTy>(VPtr);
76 }
77 
79 LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
80  llvm::StringRef path) {
81  Status error;
82 
83  namespace fs = llvm::sys::fs;
84  // If we have a regular file, a symbolic link or unknown file type, try and
85  // process the file. We must handle unknown as sometimes the directory
86  // enumeration might be enumerating a file system that doesn't have correct
87  // file type information.
88  if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
89  ft == fs::file_type::type_unknown) {
90  FileSpec plugin_file_spec(path);
91  FileSystem::Instance().Resolve(plugin_file_spec);
92 
93  if (PluginIsLoaded(plugin_file_spec))
94  return FileSystem::eEnumerateDirectoryResultNext;
95  else {
96  PluginInfo plugin_info;
97 
98  std::string pluginLoadError;
99  plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary(
100  plugin_file_spec.GetPath().c_str(), &pluginLoadError);
101  if (plugin_info.library.isValid()) {
102  bool success = false;
103  plugin_info.plugin_init_callback = CastToFPtr<PluginInitCallback>(
104  plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
105  if (plugin_info.plugin_init_callback) {
106  // Call the plug-in "bool LLDBPluginInitialize(void)" function
107  success = plugin_info.plugin_init_callback();
108  }
109 
110  if (success) {
111  // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
112  plugin_info.plugin_term_callback = CastToFPtr<PluginTermCallback>(
113  plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate"));
114  } else {
115  // The initialize function returned FALSE which means the plug-in
116  // might not be compatible, or might be too new or too old, or might
117  // not want to run on this machine. Set it to a default-constructed
118  // instance to invalidate it.
119  plugin_info = PluginInfo();
120  }
121 
122  // Regardless of success or failure, cache the plug-in load in our
123  // plug-in info so we don't try to load it again and again.
124  SetPluginInfo(plugin_file_spec, plugin_info);
125 
126  return FileSystem::eEnumerateDirectoryResultNext;
127  }
128  }
129  }
130 
131  if (ft == fs::file_type::directory_file ||
132  ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) {
133  // Try and recurse into anything that a directory or symbolic link. We must
134  // also do this for unknown as sometimes the directory enumeration might be
135  // enumerating a file system that doesn't have correct file type
136  // information.
137  return FileSystem::eEnumerateDirectoryResultEnter;
138  }
139 
140  return FileSystem::eEnumerateDirectoryResultNext;
141 }
142 
143 void PluginManager::Initialize() {
144  const bool find_directories = true;
145  const bool find_files = true;
146  const bool find_other = true;
147  char dir_path[PATH_MAX];
148  if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
149  if (FileSystem::Instance().Exists(dir_spec) &&
150  dir_spec.GetPath(dir_path, sizeof(dir_path))) {
151  FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
152  find_files, find_other,
153  LoadPluginCallback, nullptr);
154  }
155  }
156 
157  if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
158  if (FileSystem::Instance().Exists(dir_spec) &&
159  dir_spec.GetPath(dir_path, sizeof(dir_path))) {
160  FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
161  find_files, find_other,
162  LoadPluginCallback, nullptr);
163  }
164  }
165 }
166 
167 void PluginManager::Terminate() {
168  std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
169  PluginTerminateMap &plugin_map = GetPluginMap();
170 
171  PluginTerminateMap::const_iterator pos, end = plugin_map.end();
172  for (pos = plugin_map.begin(); pos != end; ++pos) {
173  // Call the plug-in "void LLDBPluginTerminate (void)" function if there is
174  // one (if the symbol was not nullptr).
175  if (pos->second.library.isValid()) {
176  if (pos->second.plugin_term_callback)
177  pos->second.plugin_term_callback();
178  }
179  }
180  plugin_map.clear();
181 }
182 
183 template <typename Callback> struct PluginInstance {
184  typedef Callback CallbackType;
185 
186  PluginInstance() = default;
188  Callback create_callback = nullptr,
189  DebuggerInitializeCallback debugger_init_callback = nullptr)
190  : name(name), description(std::move(description)),
191  create_callback(create_callback),
192  debugger_init_callback(debugger_init_callback) {}
193 
196  Callback create_callback;
198 };
199 
200 template <typename Instance> class PluginInstances {
201 public:
202  template <typename... Args>
203  bool RegisterPlugin(ConstString name, const char *description,
204  typename Instance::CallbackType callback,
205  Args &&... args) {
206  if (!callback)
207  return false;
208  assert((bool)name);
209  Instance instance =
210  Instance(name, description, callback, std::forward<Args>(args)...);
211  m_instances.push_back(instance);
212  return false;
213  }
214 
215  bool UnregisterPlugin(typename Instance::CallbackType callback) {
216  if (!callback)
217  return false;
218  auto pos = m_instances.begin();
219  auto end = m_instances.end();
220  for (; pos != end; ++pos) {
221  if (pos->create_callback == callback) {
222  m_instances.erase(pos);
223  return true;
224  }
225  }
226  return false;
227  }
228 
229  typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) {
230  if (Instance *instance = GetInstanceAtIndex(idx))
231  return instance->create_callback;
232  return nullptr;
233  }
234 
235  const char *GetDescriptionAtIndex(uint32_t idx) {
236  if (Instance *instance = GetInstanceAtIndex(idx))
237  return instance->description.c_str();
238  return nullptr;
239  }
240 
241  const char *GetNameAtIndex(uint32_t idx) {
242  if (Instance *instance = GetInstanceAtIndex(idx))
243  return instance->name.GetCString();
244  return nullptr;
245  }
246 
247  typename Instance::CallbackType GetCallbackForName(ConstString name) {
248  if (!name)
249  return nullptr;
250  for (auto &instance : m_instances) {
251  if (name == instance.name)
252  return instance.create_callback;
253  }
254  return nullptr;
255  }
256 
258  for (auto &instance : m_instances) {
259  if (instance.debugger_init_callback)
260  instance.debugger_init_callback(debugger);
261  }
262  }
263 
264  const std::vector<Instance> &GetInstances() const { return m_instances; }
265  std::vector<Instance> &GetInstances() { return m_instances; }
266 
267  Instance *GetInstanceAtIndex(uint32_t idx) {
268  if (idx < m_instances.size())
269  return &m_instances[idx];
270  return nullptr;
271  }
272 
273 private:
274  std::vector<Instance> m_instances;
275 };
276 
277 #pragma mark ABI
278 
281 
283  static ABIInstances g_instances;
284  return g_instances;
285 }
286 
287 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
288  ABICreateInstance create_callback) {
289  return GetABIInstances().RegisterPlugin(name, description, create_callback);
290 }
291 
292 bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) {
293  return GetABIInstances().UnregisterPlugin(create_callback);
294 }
295 
296 ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) {
297  return GetABIInstances().GetCallbackAtIndex(idx);
298 }
299 
300 #pragma mark Architecture
301 
303 typedef std::vector<ArchitectureInstance> ArchitectureInstances;
304 
306  static ArchitectureInstances g_instances;
307  return g_instances;
308 }
309 
310 void PluginManager::RegisterPlugin(ConstString name,
311  llvm::StringRef description,
312  ArchitectureCreateInstance create_callback) {
313  GetArchitectureInstances().push_back(
314  {name, std::string(description), create_callback});
315 }
316 
317 void PluginManager::UnregisterPlugin(
318  ArchitectureCreateInstance create_callback) {
319  auto &instances = GetArchitectureInstances();
320 
321  for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) {
322  if (pos->create_callback == create_callback) {
323  instances.erase(pos);
324  return;
325  }
326  }
327  llvm_unreachable("Plugin not found");
328 }
329 
330 std::unique_ptr<Architecture>
331 PluginManager::CreateArchitectureInstance(const ArchSpec &arch) {
332  for (const auto &instances : GetArchitectureInstances()) {
333  if (auto plugin_up = instances.create_callback(arch))
334  return plugin_up;
335  }
336  return nullptr;
337 }
338 
339 #pragma mark Disassembler
340 
343 
345  static DisassemblerInstances g_instances;
346  return g_instances;
347 }
348 
349 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
350  DisassemblerCreateInstance create_callback) {
351  return GetDisassemblerInstances().RegisterPlugin(name, description,
352  create_callback);
353 }
354 
355 bool PluginManager::UnregisterPlugin(
356  DisassemblerCreateInstance create_callback) {
357  return GetDisassemblerInstances().UnregisterPlugin(create_callback);
358 }
359 
360 DisassemblerCreateInstance
361 PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) {
363 }
364 
365 DisassemblerCreateInstance
366 PluginManager::GetDisassemblerCreateCallbackForPluginName(ConstString name) {
368 }
369 
370 #pragma mark DynamicLoader
371 
374 
376  static DynamicLoaderInstances g_instances;
377  return g_instances;
378 }
379 
380 bool PluginManager::RegisterPlugin(
381  ConstString name, const char *description,
382  DynamicLoaderCreateInstance create_callback,
383  DebuggerInitializeCallback debugger_init_callback) {
385  name, description, create_callback, debugger_init_callback);
386 }
387 
388 bool PluginManager::UnregisterPlugin(
389  DynamicLoaderCreateInstance create_callback) {
390  return GetDynamicLoaderInstances().UnregisterPlugin(create_callback);
391 }
392 
393 DynamicLoaderCreateInstance
394 PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) {
396 }
397 
398 DynamicLoaderCreateInstance
399 PluginManager::GetDynamicLoaderCreateCallbackForPluginName(ConstString name) {
401 }
402 
403 #pragma mark JITLoader
404 
407 
409  static JITLoaderInstances g_instances;
410  return g_instances;
411 }
412 
413 bool PluginManager::RegisterPlugin(
414  ConstString name, const char *description,
415  JITLoaderCreateInstance create_callback,
416  DebuggerInitializeCallback debugger_init_callback) {
418  name, description, create_callback, debugger_init_callback);
419 }
420 
421 bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) {
422  return GetJITLoaderInstances().UnregisterPlugin(create_callback);
423 }
424 
425 JITLoaderCreateInstance
426 PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) {
428 }
429 
430 #pragma mark EmulateInstruction
431 
435 
437  static EmulateInstructionInstances g_instances;
438  return g_instances;
439 }
440 
441 bool PluginManager::RegisterPlugin(
442  ConstString name, const char *description,
443  EmulateInstructionCreateInstance create_callback) {
444  return GetEmulateInstructionInstances().RegisterPlugin(name, description,
445  create_callback);
446 }
447 
448 bool PluginManager::UnregisterPlugin(
449  EmulateInstructionCreateInstance create_callback) {
450  return GetEmulateInstructionInstances().UnregisterPlugin(create_callback);
451 }
452 
453 EmulateInstructionCreateInstance
454 PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) {
456 }
457 
458 EmulateInstructionCreateInstance
459 PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
460  ConstString name) {
462 }
463 
464 #pragma mark OperatingSystem
465 
468 
470  static OperatingSystemInstances g_instances;
471  return g_instances;
472 }
473 
474 bool PluginManager::RegisterPlugin(
475  ConstString name, const char *description,
476  OperatingSystemCreateInstance create_callback,
477  DebuggerInitializeCallback debugger_init_callback) {
479  name, description, create_callback, debugger_init_callback);
480 }
481 
482 bool PluginManager::UnregisterPlugin(
483  OperatingSystemCreateInstance create_callback) {
484  return GetOperatingSystemInstances().UnregisterPlugin(create_callback);
485 }
486 
487 OperatingSystemCreateInstance
488 PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
490 }
491 
492 OperatingSystemCreateInstance
493 PluginManager::GetOperatingSystemCreateCallbackForPluginName(ConstString name) {
495 }
496 
497 #pragma mark Language
498 
501 
503  static LanguageInstances g_instances;
504  return g_instances;
505 }
506 
507 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
508  LanguageCreateInstance create_callback) {
509  return GetLanguageInstances().RegisterPlugin(name, description,
510  create_callback);
511 }
512 
513 bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
514  return GetLanguageInstances().UnregisterPlugin(create_callback);
515 }
516 
517 LanguageCreateInstance
518 PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) {
520 }
521 
522 #pragma mark LanguageRuntime
523 
525  : public PluginInstance<LanguageRuntimeCreateInstance> {
527  ConstString name, std::string description, CallbackType create_callback,
528  DebuggerInitializeCallback debugger_init_callback,
529  LanguageRuntimeGetCommandObject command_callback,
530  LanguageRuntimeGetExceptionPrecondition precondition_callback)
532  name, std::move(description), create_callback,
533  debugger_init_callback),
534  command_callback(command_callback),
535  precondition_callback(precondition_callback) {}
536 
537  LanguageRuntimeGetCommandObject command_callback;
538  LanguageRuntimeGetExceptionPrecondition precondition_callback;
539 };
540 
542 
544  static LanguageRuntimeInstances g_instances;
545  return g_instances;
546 }
547 
548 bool PluginManager::RegisterPlugin(
549  ConstString name, const char *description,
550  LanguageRuntimeCreateInstance create_callback,
551  LanguageRuntimeGetCommandObject command_callback,
552  LanguageRuntimeGetExceptionPrecondition precondition_callback) {
554  name, description, create_callback, nullptr, command_callback,
555  precondition_callback);
556 }
557 
558 bool PluginManager::UnregisterPlugin(
559  LanguageRuntimeCreateInstance create_callback) {
560  return GetLanguageRuntimeInstances().UnregisterPlugin(create_callback);
561 }
562 
564 PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
566 }
567 
568 LanguageRuntimeGetCommandObject
569 PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
570  const auto &instances = GetLanguageRuntimeInstances().GetInstances();
571  if (idx < instances.size())
572  return instances[idx].command_callback;
573  return nullptr;
574 }
575 
576 LanguageRuntimeGetExceptionPrecondition
577 PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) {
578  const auto &instances = GetLanguageRuntimeInstances().GetInstances();
579  if (idx < instances.size())
580  return instances[idx].precondition_callback;
581  return nullptr;
582 }
583 
584 #pragma mark SystemRuntime
585 
588 
590  static SystemRuntimeInstances g_instances;
591  return g_instances;
592 }
593 
594 bool PluginManager::RegisterPlugin(
595  ConstString name, const char *description,
596  SystemRuntimeCreateInstance create_callback) {
597  return GetSystemRuntimeInstances().RegisterPlugin(name, description,
598  create_callback);
599 }
600 
601 bool PluginManager::UnregisterPlugin(
602  SystemRuntimeCreateInstance create_callback) {
603  return GetSystemRuntimeInstances().UnregisterPlugin(create_callback);
604 }
605 
606 SystemRuntimeCreateInstance
607 PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) {
609 }
610 
611 #pragma mark ObjectFile
612 
613 struct ObjectFileInstance : public PluginInstance<ObjectFileCreateInstance> {
615  ConstString name, std::string description, CallbackType create_callback,
616  ObjectFileCreateMemoryInstance create_memory_callback,
617  ObjectFileGetModuleSpecifications get_module_specifications,
618  ObjectFileSaveCore save_core)
619  : PluginInstance<ObjectFileCreateInstance>(name, std::move(description),
620  create_callback),
621  create_memory_callback(create_memory_callback),
622  get_module_specifications(get_module_specifications),
623  save_core(save_core) {}
624 
625  ObjectFileCreateMemoryInstance create_memory_callback;
626  ObjectFileGetModuleSpecifications get_module_specifications;
627  ObjectFileSaveCore save_core;
628 };
630 
632  static ObjectFileInstances g_instances;
633  return g_instances;
634 }
635 
636 bool PluginManager::RegisterPlugin(
637  ConstString name, const char *description,
638  ObjectFileCreateInstance create_callback,
639  ObjectFileCreateMemoryInstance create_memory_callback,
640  ObjectFileGetModuleSpecifications get_module_specifications,
641  ObjectFileSaveCore save_core) {
643  name, description, create_callback, create_memory_callback,
644  get_module_specifications, save_core);
645 }
646 
647 bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
648  return GetObjectFileInstances().UnregisterPlugin(create_callback);
649 }
650 
652 PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
654 }
655 
656 ObjectFileCreateMemoryInstance
657 PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) {
658  const auto &instances = GetObjectFileInstances().GetInstances();
659  if (idx < instances.size())
660  return instances[idx].create_memory_callback;
661  return nullptr;
662 }
663 
664 ObjectFileGetModuleSpecifications
665 PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
666  uint32_t idx) {
667  const auto &instances = GetObjectFileInstances().GetInstances();
668  if (idx < instances.size())
669  return instances[idx].get_module_specifications;
670  return nullptr;
671 }
672 
673 ObjectFileCreateMemoryInstance
674 PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
675  ConstString name) {
676  if (!name)
677  return nullptr;
678  const auto &instances = GetObjectFileInstances().GetInstances();
679  for (auto &instance : instances) {
680  if (instance.name == name)
681  return instance.create_memory_callback;
682  }
683  return nullptr;
684 }
685 
686 Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
687  const FileSpec &outfile) {
688  Status error;
689  auto &instances = GetObjectFileInstances().GetInstances();
690  for (auto &instance : instances) {
691  if (instance.save_core && instance.save_core(process_sp, outfile, error))
692  return error;
693  }
694  error.SetErrorString(
695  "no ObjectFile plugins were able to save a core for this process");
696  return error;
697 }
698 
699 #pragma mark ObjectContainer
700 
702  : public PluginInstance<ObjectContainerCreateInstance> {
704  ConstString name, std::string description, CallbackType create_callback,
705  ObjectFileGetModuleSpecifications get_module_specifications)
707  name, std::move(description), create_callback),
708  get_module_specifications(get_module_specifications) {}
709 
710  ObjectFileGetModuleSpecifications get_module_specifications;
711 };
713 
715  static ObjectContainerInstances g_instances;
716  return g_instances;
717 }
718 
719 bool PluginManager::RegisterPlugin(
720  ConstString name, const char *description,
721  ObjectContainerCreateInstance create_callback,
722  ObjectFileGetModuleSpecifications get_module_specifications) {
724  name, description, create_callback, get_module_specifications);
725 }
726 
727 bool PluginManager::UnregisterPlugin(
728  ObjectContainerCreateInstance create_callback) {
729  return GetObjectContainerInstances().UnregisterPlugin(create_callback);
730 }
731 
733 PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
735 }
736 
737 ObjectFileGetModuleSpecifications
738 PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
739  uint32_t idx) {
740  const auto &instances = GetObjectContainerInstances().GetInstances();
741  if (idx < instances.size())
742  return instances[idx].get_module_specifications;
743  return nullptr;
744 }
745 
746 #pragma mark Platform
747 
750 
752  static PlatformInstances g_platform_instances;
753  return g_platform_instances;
754 }
755 
756 bool PluginManager::RegisterPlugin(
757  ConstString name, const char *description,
758  PlatformCreateInstance create_callback,
759  DebuggerInitializeCallback debugger_init_callback) {
761  name, description, create_callback, debugger_init_callback);
762 }
763 
764 bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) {
765  return GetPlatformInstances().UnregisterPlugin(create_callback);
766 }
767 
768 const char *PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) {
769  return GetPlatformInstances().GetNameAtIndex(idx);
770 }
771 
772 const char *PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) {
774 }
775 
776 PlatformCreateInstance
777 PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) {
779 }
780 
781 PlatformCreateInstance
782 PluginManager::GetPlatformCreateCallbackForPluginName(ConstString name) {
784 }
785 
786 void PluginManager::AutoCompletePlatformName(llvm::StringRef name,
787  CompletionRequest &request) {
788  for (const auto &instance : GetPlatformInstances().GetInstances()) {
789  if (instance.name.GetStringRef().startswith(name))
790  request.AddCompletion(instance.name.GetCString());
791  }
792 }
793 
794 #pragma mark Process
795 
798 
800  static ProcessInstances g_instances;
801  return g_instances;
802 }
803 
804 bool PluginManager::RegisterPlugin(
805  ConstString name, const char *description,
806  ProcessCreateInstance create_callback,
807  DebuggerInitializeCallback debugger_init_callback) {
809  name, description, create_callback, debugger_init_callback);
810 }
811 
812 bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) {
813  return GetProcessInstances().UnregisterPlugin(create_callback);
814 }
815 
816 const char *PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) {
817  return GetProcessInstances().GetNameAtIndex(idx);
818 }
819 
820 const char *PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) {
822 }
823 
824 ProcessCreateInstance
825 PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) {
827 }
828 
829 ProcessCreateInstance
830 PluginManager::GetProcessCreateCallbackForPluginName(ConstString name) {
832 }
833 
834 void PluginManager::AutoCompleteProcessName(llvm::StringRef name,
835  CompletionRequest &request) {
836  for (const auto &instance : GetProcessInstances().GetInstances()) {
837  if (instance.name.GetStringRef().startswith(name))
838  request.AddCompletion(instance.name.GetCString(), instance.description);
839  }
840 }
841 
842 #pragma mark ScriptInterpreter
843 
845  : public PluginInstance<ScriptInterpreterCreateInstance> {
847  CallbackType create_callback,
848  lldb::ScriptLanguage language)
850  name, std::move(description), create_callback),
851  language(language) {}
852 
854 };
855 
857 
859  static ScriptInterpreterInstances g_instances;
860  return g_instances;
861 }
862 
863 bool PluginManager::RegisterPlugin(
864  ConstString name, const char *description,
865  lldb::ScriptLanguage script_language,
866  ScriptInterpreterCreateInstance create_callback) {
868  name, description, create_callback, script_language);
869 }
870 
871 bool PluginManager::UnregisterPlugin(
872  ScriptInterpreterCreateInstance create_callback) {
873  return GetScriptInterpreterInstances().UnregisterPlugin(create_callback);
874 }
875 
877 PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
879 }
880 
881 lldb::ScriptInterpreterSP
882 PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
883  Debugger &debugger) {
884  const auto &instances = GetScriptInterpreterInstances().GetInstances();
885  ScriptInterpreterCreateInstance none_instance = nullptr;
886  for (const auto &instance : instances) {
887  if (instance.language == lldb::eScriptLanguageNone)
888  none_instance = instance.create_callback;
889 
890  if (script_lang == instance.language)
891  return instance.create_callback(debugger);
892  }
893 
894  // If we didn't find one, return the ScriptInterpreter for the null language.
895  assert(none_instance != nullptr);
896  return none_instance(debugger);
897 }
898 
899 #pragma mark StructuredDataPlugin
900 
902  : public PluginInstance<StructuredDataPluginCreateInstance> {
904  ConstString name, std::string description, CallbackType create_callback,
905  DebuggerInitializeCallback debugger_init_callback,
906  StructuredDataFilterLaunchInfo filter_callback)
908  name, std::move(description), create_callback,
909  debugger_init_callback),
910  filter_callback(filter_callback) {}
911 
912  StructuredDataFilterLaunchInfo filter_callback = nullptr;
913 };
914 
917 
919  static StructuredDataPluginInstances g_instances;
920  return g_instances;
921 }
922 
923 bool PluginManager::RegisterPlugin(
924  ConstString name, const char *description,
925  StructuredDataPluginCreateInstance create_callback,
926  DebuggerInitializeCallback debugger_init_callback,
927  StructuredDataFilterLaunchInfo filter_callback) {
929  name, description, create_callback, debugger_init_callback,
930  filter_callback);
931 }
932 
933 bool PluginManager::UnregisterPlugin(
934  StructuredDataPluginCreateInstance create_callback) {
935  return GetStructuredDataPluginInstances().UnregisterPlugin(create_callback);
936 }
937 
939 PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
941 }
942 
943 StructuredDataFilterLaunchInfo
944 PluginManager::GetStructuredDataFilterCallbackAtIndex(
945  uint32_t idx, bool &iteration_complete) {
946  const auto &instances = GetStructuredDataPluginInstances().GetInstances();
947  if (idx < instances.size()) {
948  iteration_complete = false;
949  return instances[idx].filter_callback;
950  } else {
951  iteration_complete = true;
952  }
953  return nullptr;
954 }
955 
956 #pragma mark SymbolFile
957 
960 
962  static SymbolFileInstances g_instances;
963  return g_instances;
964 }
965 
966 bool PluginManager::RegisterPlugin(
967  ConstString name, const char *description,
968  SymbolFileCreateInstance create_callback,
969  DebuggerInitializeCallback debugger_init_callback) {
971  name, description, create_callback, debugger_init_callback);
972 }
973 
974 bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) {
975  return GetSymbolFileInstances().UnregisterPlugin(create_callback);
976 }
977 
978 SymbolFileCreateInstance
979 PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) {
981 }
982 
983 #pragma mark SymbolVendor
984 
987 
989  static SymbolVendorInstances g_instances;
990  return g_instances;
991 }
992 
993 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
994  SymbolVendorCreateInstance create_callback) {
995  return GetSymbolVendorInstances().RegisterPlugin(name, description,
996  create_callback);
997 }
998 
999 bool PluginManager::UnregisterPlugin(
1000  SymbolVendorCreateInstance create_callback) {
1001  return GetSymbolVendorInstances().UnregisterPlugin(create_callback);
1002 }
1003 
1004 SymbolVendorCreateInstance
1005 PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
1007 }
1008 
1009 #pragma mark Trace
1010 
1012  : public PluginInstance<TraceCreateInstanceForSessionFile> {
1014  ConstString name, std::string description,
1015  CallbackType create_callback_for_session_file,
1016  TraceCreateInstanceForLiveProcess create_callback_for_live_process,
1017  llvm::StringRef schema)
1019  name, std::move(description), create_callback_for_session_file),
1020  schema(schema),
1021  create_callback_for_live_process(create_callback_for_live_process) {}
1022 
1023  llvm::StringRef schema;
1024  TraceCreateInstanceForLiveProcess create_callback_for_live_process;
1025 };
1026 
1028 
1030  static TraceInstances g_instances;
1031  return g_instances;
1032 }
1033 
1034 bool PluginManager::RegisterPlugin(
1035  ConstString name, const char *description,
1036  TraceCreateInstanceForSessionFile create_callback_for_session_file,
1037  TraceCreateInstanceForLiveProcess create_callback_for_live_process,
1038  llvm::StringRef schema) {
1040  name, description, create_callback_for_session_file,
1041  create_callback_for_live_process, schema);
1042 }
1043 
1044 bool PluginManager::UnregisterPlugin(
1045  TraceCreateInstanceForSessionFile create_callback_for_session_file) {
1047  create_callback_for_session_file);
1048 }
1049 
1051 PluginManager::GetTraceCreateCallback(ConstString plugin_name) {
1052  return GetTracePluginInstances().GetCallbackForName(plugin_name);
1053 }
1054 
1055 TraceCreateInstanceForLiveProcess
1056 PluginManager::GetTraceCreateCallbackForLiveProcess(ConstString plugin_name) {
1057  for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1058  if (instance.name == plugin_name)
1059  return instance.create_callback_for_live_process;
1060  return nullptr;
1061 }
1062 
1063 llvm::StringRef PluginManager::GetTraceSchema(ConstString plugin_name) {
1064  for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1065  if (instance.name == plugin_name)
1066  return instance.schema;
1067  return llvm::StringRef();
1068 }
1069 
1070 llvm::StringRef PluginManager::GetTraceSchema(size_t index) {
1071  if (TraceInstance *instance =
1072  GetTracePluginInstances().GetInstanceAtIndex(index))
1073  return instance->schema;
1074  return llvm::StringRef();
1075 }
1076 
1077 #pragma mark UnwindAssembly
1078 
1081 
1083  static UnwindAssemblyInstances g_instances;
1084  return g_instances;
1085 }
1086 
1087 bool PluginManager::RegisterPlugin(
1088  ConstString name, const char *description,
1089  UnwindAssemblyCreateInstance create_callback) {
1090  return GetUnwindAssemblyInstances().RegisterPlugin(name, description,
1091  create_callback);
1092 }
1093 
1094 bool PluginManager::UnregisterPlugin(
1095  UnwindAssemblyCreateInstance create_callback) {
1096  return GetUnwindAssemblyInstances().UnregisterPlugin(create_callback);
1097 }
1098 
1099 UnwindAssemblyCreateInstance
1100 PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) {
1102 }
1103 
1104 #pragma mark MemoryHistory
1105 
1108 
1110  static MemoryHistoryInstances g_instances;
1111  return g_instances;
1112 }
1113 
1114 bool PluginManager::RegisterPlugin(
1115  ConstString name, const char *description,
1116  MemoryHistoryCreateInstance create_callback) {
1117  return GetMemoryHistoryInstances().RegisterPlugin(name, description,
1118  create_callback);
1119 }
1120 
1121 bool PluginManager::UnregisterPlugin(
1122  MemoryHistoryCreateInstance create_callback) {
1123  return GetMemoryHistoryInstances().UnregisterPlugin(create_callback);
1124 }
1125 
1126 MemoryHistoryCreateInstance
1127 PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) {
1129 }
1130 
1131 #pragma mark InstrumentationRuntime
1132 
1134  : public PluginInstance<InstrumentationRuntimeCreateInstance> {
1136  ConstString name, std::string description, CallbackType create_callback,
1137  InstrumentationRuntimeGetType get_type_callback)
1139  name, std::move(description), create_callback),
1140  get_type_callback(get_type_callback) {}
1141 
1142  InstrumentationRuntimeGetType get_type_callback = nullptr;
1143 };
1144 
1147 
1149  static InstrumentationRuntimeInstances g_instances;
1150  return g_instances;
1151 }
1152 
1153 bool PluginManager::RegisterPlugin(
1154  ConstString name, const char *description,
1155  InstrumentationRuntimeCreateInstance create_callback,
1156  InstrumentationRuntimeGetType get_type_callback) {
1158  name, description, create_callback, get_type_callback);
1159 }
1160 
1161 bool PluginManager::UnregisterPlugin(
1162  InstrumentationRuntimeCreateInstance create_callback) {
1163  return GetInstrumentationRuntimeInstances().UnregisterPlugin(create_callback);
1164 }
1165 
1166 InstrumentationRuntimeGetType
1167 PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
1168  const auto &instances = GetInstrumentationRuntimeInstances().GetInstances();
1169  if (idx < instances.size())
1170  return instances[idx].get_type_callback;
1171  return nullptr;
1172 }
1173 
1175 PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) {
1177 }
1178 
1179 #pragma mark TypeSystem
1180 
1181 struct TypeSystemInstance : public PluginInstance<TypeSystemCreateInstance> {
1183  CallbackType create_callback,
1184  LanguageSet supported_languages_for_types,
1185  LanguageSet supported_languages_for_expressions)
1186  : PluginInstance<TypeSystemCreateInstance>(name, std::move(description),
1187  create_callback),
1188  supported_languages_for_types(supported_languages_for_types),
1189  supported_languages_for_expressions(
1190  supported_languages_for_expressions) {}
1191 
1194 };
1195 
1197 
1199  static TypeSystemInstances g_instances;
1200  return g_instances;
1201 }
1202 
1203 bool PluginManager::RegisterPlugin(
1204  ConstString name, const char *description,
1205  TypeSystemCreateInstance create_callback,
1206  LanguageSet supported_languages_for_types,
1207  LanguageSet supported_languages_for_expressions) {
1209  name, description, create_callback, supported_languages_for_types,
1210  supported_languages_for_expressions);
1211 }
1212 
1213 bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
1214  return GetTypeSystemInstances().UnregisterPlugin(create_callback);
1215 }
1216 
1218 PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
1220 }
1221 
1222 LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
1223  const auto &instances = GetTypeSystemInstances().GetInstances();
1224  LanguageSet all;
1225  for (unsigned i = 0; i < instances.size(); ++i)
1226  all.bitvector |= instances[i].supported_languages_for_types.bitvector;
1227  return all;
1228 }
1229 
1230 LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
1231  const auto &instances = GetTypeSystemInstances().GetInstances();
1232  LanguageSet all;
1233  for (unsigned i = 0; i < instances.size(); ++i)
1234  all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
1235  return all;
1236 }
1237 
1238 #pragma mark REPL
1239 
1240 struct REPLInstance : public PluginInstance<REPLCreateInstance> {
1242  CallbackType create_callback, LanguageSet supported_languages)
1243  : PluginInstance<REPLCreateInstance>(name, std::move(description),
1244  create_callback),
1245  supported_languages(supported_languages) {}
1246 
1248 };
1249 
1251 
1253  static REPLInstances g_instances;
1254  return g_instances;
1255 }
1256 
1257 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
1258  REPLCreateInstance create_callback,
1259  LanguageSet supported_languages) {
1260  return GetREPLInstances().RegisterPlugin(name, description, create_callback,
1261  supported_languages);
1262 }
1263 
1264 bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) {
1265  return GetREPLInstances().UnregisterPlugin(create_callback);
1266 }
1267 
1268 REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
1269  return GetREPLInstances().GetCallbackAtIndex(idx);
1270 }
1271 
1272 LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
1273  const auto &instances = GetREPLInstances().GetInstances();
1274  LanguageSet all;
1275  for (unsigned i = 0; i < instances.size(); ++i)
1276  all.bitvector |= instances[i].supported_languages.bitvector;
1277  return all;
1278 }
1279 
1280 #pragma mark PluginManager
1281 
1282 void PluginManager::DebuggerInitialize(Debugger &debugger) {
1291 }
1292 
1293 // This is the preferred new way to register plugin specific settings. e.g.
1294 // This will put a plugin's settings under e.g.
1295 // "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
1296 static lldb::OptionValuePropertiesSP
1298  ConstString plugin_type_desc, bool can_create) {
1299  lldb::OptionValuePropertiesSP parent_properties_sp(
1300  debugger.GetValueProperties());
1301  if (parent_properties_sp) {
1302  static ConstString g_property_name("plugin");
1303 
1304  OptionValuePropertiesSP plugin_properties_sp =
1305  parent_properties_sp->GetSubProperty(nullptr, g_property_name);
1306  if (!plugin_properties_sp && can_create) {
1307  plugin_properties_sp =
1308  std::make_shared<OptionValueProperties>(g_property_name);
1309  parent_properties_sp->AppendProperty(
1310  g_property_name, ConstString("Settings specify to plugins."), true,
1311  plugin_properties_sp);
1312  }
1313 
1314  if (plugin_properties_sp) {
1315  lldb::OptionValuePropertiesSP plugin_type_properties_sp =
1316  plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
1317  if (!plugin_type_properties_sp && can_create) {
1318  plugin_type_properties_sp =
1319  std::make_shared<OptionValueProperties>(plugin_type_name);
1320  plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
1321  true, plugin_type_properties_sp);
1322  }
1323  return plugin_type_properties_sp;
1324  }
1325  }
1326  return lldb::OptionValuePropertiesSP();
1327 }
1328 
1329 // This is deprecated way to register plugin specific settings. e.g.
1330 // "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform
1331 // generic settings would be under "platform.SETTINGNAME".
1332 static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(
1333  Debugger &debugger, ConstString plugin_type_name,
1334  ConstString plugin_type_desc, bool can_create) {
1335  static ConstString g_property_name("plugin");
1336  lldb::OptionValuePropertiesSP parent_properties_sp(
1337  debugger.GetValueProperties());
1338  if (parent_properties_sp) {
1339  OptionValuePropertiesSP plugin_properties_sp =
1340  parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
1341  if (!plugin_properties_sp && can_create) {
1342  plugin_properties_sp =
1343  std::make_shared<OptionValueProperties>(plugin_type_name);
1344  parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
1345  true, plugin_properties_sp);
1346  }
1347 
1348  if (plugin_properties_sp) {
1349  lldb::OptionValuePropertiesSP plugin_type_properties_sp =
1350  plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
1351  if (!plugin_type_properties_sp && can_create) {
1352  plugin_type_properties_sp =
1353  std::make_shared<OptionValueProperties>(g_property_name);
1354  plugin_properties_sp->AppendProperty(
1355  g_property_name, ConstString("Settings specific to plugins"), true,
1356  plugin_type_properties_sp);
1357  }
1358  return plugin_type_properties_sp;
1359  }
1360  }
1361  return lldb::OptionValuePropertiesSP();
1362 }
1363 
1364 namespace {
1365 
1366 typedef lldb::OptionValuePropertiesSP
1367 GetDebuggerPropertyForPluginsPtr(Debugger &, ConstString, ConstString,
1368  bool can_create);
1369 
1370 lldb::OptionValuePropertiesSP
1371 GetSettingForPlugin(Debugger &debugger, ConstString setting_name,
1372  ConstString plugin_type_name,
1373  GetDebuggerPropertyForPluginsPtr get_debugger_property =
1375  lldb::OptionValuePropertiesSP properties_sp;
1376  lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property(
1377  debugger, plugin_type_name,
1378  ConstString(), // not creating to so we don't need the description
1379  false));
1380  if (plugin_type_properties_sp)
1381  properties_sp =
1382  plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1383  return properties_sp;
1384 }
1385 
1386 bool CreateSettingForPlugin(
1387  Debugger &debugger, ConstString plugin_type_name,
1388  ConstString plugin_type_desc,
1389  const lldb::OptionValuePropertiesSP &properties_sp, ConstString description,
1390  bool is_global_property,
1391  GetDebuggerPropertyForPluginsPtr get_debugger_property =
1393  if (properties_sp) {
1394  lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1395  get_debugger_property(debugger, plugin_type_name, plugin_type_desc,
1396  true));
1397  if (plugin_type_properties_sp) {
1398  plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
1399  description, is_global_property,
1400  properties_sp);
1401  return true;
1402  }
1403  }
1404  return false;
1405 }
1406 
1407 const char *kDynamicLoaderPluginName("dynamic-loader");
1408 const char *kPlatformPluginName("platform");
1409 const char *kProcessPluginName("process");
1410 const char *kSymbolFilePluginName("symbol-file");
1411 const char *kJITLoaderPluginName("jit-loader");
1412 const char *kStructuredDataPluginName("structured-data");
1413 
1414 } // anonymous namespace
1415 
1416 lldb::OptionValuePropertiesSP
1417 PluginManager::GetSettingForDynamicLoaderPlugin(Debugger &debugger,
1418  ConstString setting_name) {
1419  return GetSettingForPlugin(debugger, setting_name,
1420  ConstString(kDynamicLoaderPluginName));
1421 }
1422 
1423 bool PluginManager::CreateSettingForDynamicLoaderPlugin(
1424  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1425  ConstString description, bool is_global_property) {
1426  return CreateSettingForPlugin(
1427  debugger, ConstString(kDynamicLoaderPluginName),
1428  ConstString("Settings for dynamic loader plug-ins"), properties_sp,
1429  description, is_global_property);
1430 }
1431 
1432 lldb::OptionValuePropertiesSP
1433 PluginManager::GetSettingForPlatformPlugin(Debugger &debugger,
1434  ConstString setting_name) {
1435  return GetSettingForPlugin(debugger, setting_name,
1436  ConstString(kPlatformPluginName),
1438 }
1439 
1440 bool PluginManager::CreateSettingForPlatformPlugin(
1441  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1442  ConstString description, bool is_global_property) {
1443  return CreateSettingForPlugin(debugger, ConstString(kPlatformPluginName),
1444  ConstString("Settings for platform plug-ins"),
1445  properties_sp, description, is_global_property,
1447 }
1448 
1449 lldb::OptionValuePropertiesSP
1450 PluginManager::GetSettingForProcessPlugin(Debugger &debugger,
1451  ConstString setting_name) {
1452  return GetSettingForPlugin(debugger, setting_name,
1453  ConstString(kProcessPluginName));
1454 }
1455 
1456 bool PluginManager::CreateSettingForProcessPlugin(
1457  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1458  ConstString description, bool is_global_property) {
1459  return CreateSettingForPlugin(debugger, ConstString(kProcessPluginName),
1460  ConstString("Settings for process plug-ins"),
1461  properties_sp, description, is_global_property);
1462 }
1463 
1464 lldb::OptionValuePropertiesSP
1465 PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger,
1466  ConstString setting_name) {
1467  return GetSettingForPlugin(debugger, setting_name,
1468  ConstString(kSymbolFilePluginName));
1469 }
1470 
1471 bool PluginManager::CreateSettingForSymbolFilePlugin(
1472  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1473  ConstString description, bool is_global_property) {
1474  return CreateSettingForPlugin(
1475  debugger, ConstString(kSymbolFilePluginName),
1476  ConstString("Settings for symbol file plug-ins"), properties_sp,
1477  description, is_global_property);
1478 }
1479 
1480 lldb::OptionValuePropertiesSP
1481 PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger,
1482  ConstString setting_name) {
1483  return GetSettingForPlugin(debugger, setting_name,
1484  ConstString(kJITLoaderPluginName));
1485 }
1486 
1487 bool PluginManager::CreateSettingForJITLoaderPlugin(
1488  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1489  ConstString description, bool is_global_property) {
1490  return CreateSettingForPlugin(debugger, ConstString(kJITLoaderPluginName),
1491  ConstString("Settings for JIT loader plug-ins"),
1492  properties_sp, description, is_global_property);
1493 }
1494 
1495 static const char *kOperatingSystemPluginName("os");
1496 
1497 lldb::OptionValuePropertiesSP
1498 PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger,
1499  ConstString setting_name) {
1500  lldb::OptionValuePropertiesSP properties_sp;
1501  lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1504  ConstString(), // not creating to so we don't need the description
1505  false));
1506  if (plugin_type_properties_sp)
1507  properties_sp =
1508  plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1509  return properties_sp;
1510 }
1511 
1512 bool PluginManager::CreateSettingForOperatingSystemPlugin(
1513  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1514  ConstString description, bool is_global_property) {
1515  if (properties_sp) {
1516  lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1519  ConstString("Settings for operating system plug-ins"), true));
1520  if (plugin_type_properties_sp) {
1521  plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
1522  description, is_global_property,
1523  properties_sp);
1524  return true;
1525  }
1526  }
1527  return false;
1528 }
1529 
1530 lldb::OptionValuePropertiesSP
1531 PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger,
1532  ConstString setting_name) {
1533  return GetSettingForPlugin(debugger, setting_name,
1534  ConstString(kStructuredDataPluginName));
1535 }
1536 
1537 bool PluginManager::CreateSettingForStructuredDataPlugin(
1538  Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1539  ConstString description, bool is_global_property) {
1540  return CreateSettingForPlugin(
1541  debugger, ConstString(kStructuredDataPluginName),
1542  ConstString("Settings for structured data plug-ins"), properties_sp,
1543  description, is_global_property);
1544 }
OperatingSystemInstances
PluginInstances< OperatingSystemInstance > OperatingSystemInstances
Definition: PluginManager.cpp:467
TypeSystemInstance::supported_languages_for_expressions
LanguageSet supported_languages_for_expressions
Definition: PluginManager.cpp:1193
GetMemoryHistoryInstances
static MemoryHistoryInstances & GetMemoryHistoryInstances()
Definition: PluginManager.cpp:1109
LanguageRuntimeCreateInstance
GetDisassemblerInstances
static DisassemblerInstances & GetDisassemblerInstances()
Definition: PluginManager.cpp:344
MemoryHistoryInstance
PluginInstance< MemoryHistoryCreateInstance > MemoryHistoryInstance
Definition: PluginManager.cpp:1106
lldb::ScriptLanguage
ScriptLanguage
Script interpreter types.
Definition: lldb-enumerations.h:216
lldb_private::Properties::GetValueProperties
virtual lldb::OptionValuePropertiesSP GetValueProperties() const
Definition: UserSettingsController.h:42
lldb_private::ArchSpec
Definition: ArchSpec.h:33
FileSystem.h
TypeSystemInstances
PluginInstances< TypeSystemInstance > TypeSystemInstances
Definition: PluginManager.cpp:1196
GetPluginMapMutex
static std::recursive_mutex & GetPluginMapMutex()
Definition: PluginManager.cpp:50
ABIInstances
PluginInstances< ABIInstance > ABIInstances
Definition: PluginManager.cpp:280
PluginTerminateMap
std::map< FileSpec, PluginInfo > PluginTerminateMap
Definition: PluginManager.cpp:48
GetREPLInstances
static REPLInstances & GetREPLInstances()
Definition: PluginManager.cpp:1252
GetJITLoaderInstances
static JITLoaderInstances & GetJITLoaderInstances()
Definition: PluginManager.cpp:408
TypeSystemCreateInstance
LanguageRuntimeInstance
Definition: PluginManager.cpp:524
PluginInstance::create_callback
Callback create_callback
Definition: PluginManager.cpp:196
SymbolFileInstance
PluginInstance< SymbolFileCreateInstance > SymbolFileInstance
Definition: PluginManager.cpp:958
DisassemblerInstances
PluginInstances< DisassemblerInstance > DisassemblerInstances
Definition: PluginManager.cpp:342
GetObjectFileInstances
static ObjectFileInstances & GetObjectFileInstances()
Definition: PluginManager.cpp:631
GetDebuggerPropertyForPluginsOldStyle
static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(Debugger &debugger, ConstString plugin_type_name, ConstString plugin_type_desc, bool can_create)
Definition: PluginManager.cpp:1332
StructuredDataPluginInstances
PluginInstances< StructuredDataPluginInstance > StructuredDataPluginInstances
Definition: PluginManager.cpp:916
ObjectContainerInstance::get_module_specifications
ObjectFileGetModuleSpecifications get_module_specifications
Definition: PluginManager.cpp:710
EmulateInstructionInstance
PluginInstance< EmulateInstructionCreateInstance > EmulateInstructionInstance
Definition: PluginManager.cpp:433
PluginTermCallback
void(* PluginTermCallback)()
Definition: PluginManager.cpp:38
StructuredDataPluginCreateInstance
REPLInstance
Definition: PluginManager.cpp:1240
CastToFPtr
static FPtrTy CastToFPtr(void *VPtr)
Definition: PluginManager.cpp:74
PluginInstances::m_instances
std::vector< Instance > m_instances
Definition: PluginManager.cpp:274
InstrumentationRuntimeCreateInstance
lldb_private::Args
Definition: Args.h:33
GetDynamicLoaderInstances
static DynamicLoaderInstances & GetDynamicLoaderInstances()
Definition: PluginManager.cpp:375
Debugger.h
LanguageRuntimeInstance::command_callback
LanguageRuntimeGetCommandObject command_callback
Definition: PluginManager.cpp:537
PluginInstances::GetInstances
const std::vector< Instance > & GetInstances() const
Definition: PluginManager.cpp:264
TraceCreateInstanceForSessionFile
PluginInstance::name
ConstString name
Definition: PluginManager.cpp:194
LanguageRuntimeInstances
PluginInstances< LanguageRuntimeInstance > LanguageRuntimeInstances
Definition: PluginManager.cpp:541
GetPlatformInstances
static PlatformInstances & GetPlatformInstances()
Definition: PluginManager.cpp:751
lldb::eScriptLanguageNone
@ eScriptLanguageNone
Definition: lldb-enumerations.h:217
GetLanguageRuntimeInstances
static LanguageRuntimeInstances & GetLanguageRuntimeInstances()
Definition: PluginManager.cpp:543
GetSymbolVendorInstances
static SymbolVendorInstances & GetSymbolVendorInstances()
Definition: PluginManager.cpp:988
SymbolVendorInstance
PluginInstance< SymbolVendorCreateInstance > SymbolVendorInstance
Definition: PluginManager.cpp:985
PluginInstances
Definition: PluginManager.cpp:200
PluginInfo
Definition: PluginManager.cpp:40
TraceInstances
PluginInstances< TraceInstance > TraceInstances
Definition: PluginManager.cpp:1027
ObjectFileInstances
PluginInstances< ObjectFileInstance > ObjectFileInstances
Definition: PluginManager.cpp:629
InstrumentationRuntimeInstance::InstrumentationRuntimeInstance
InstrumentationRuntimeInstance(ConstString name, std::string description, CallbackType create_callback, InstrumentationRuntimeGetType get_type_callback)
Definition: PluginManager.cpp:1135
GetUnwindAssemblyInstances
static UnwindAssemblyInstances & GetUnwindAssemblyInstances()
Definition: PluginManager.cpp:1082
lldb_private::FileSpec
Definition: FileSpec.h:56
ObjectFileInstance::save_core
ObjectFileSaveCore save_core
Definition: PluginManager.cpp:627
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
GetStructuredDataPluginInstances
static StructuredDataPluginInstances & GetStructuredDataPluginInstances()
Definition: PluginManager.cpp:918
UnwindAssemblyInstance
PluginInstance< UnwindAssemblyCreateInstance > UnwindAssemblyInstance
Definition: PluginManager.cpp:1079
LoadPluginCallback
static FileSystem::EnumerateDirectoryResult LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path)
Definition: PluginManager.cpp:79
lldb_private::LanguageSet::bitvector
llvm::SmallBitVector bitvector
Definition: TypeSystem.h:41
PluginInstances::GetCallbackAtIndex
Instance::CallbackType GetCallbackAtIndex(uint32_t idx)
Definition: PluginManager.cpp:229
PluginInstance::description
std::string description
Definition: PluginManager.cpp:195
REPLInstance::REPLInstance
REPLInstance(ConstString name, std::string description, CallbackType create_callback, LanguageSet supported_languages)
Definition: PluginManager.cpp:1241
LanguageRuntimeInstance::LanguageRuntimeInstance
LanguageRuntimeInstance(ConstString name, std::string description, CallbackType create_callback, DebuggerInitializeCallback debugger_init_callback, LanguageRuntimeGetCommandObject command_callback, LanguageRuntimeGetExceptionPrecondition precondition_callback)
Definition: PluginManager.cpp:526
GetScriptInterpreterInstances
static ScriptInterpreterInstances & GetScriptInterpreterInstances()
Definition: PluginManager.cpp:858
REPLInstance::supported_languages
LanguageSet supported_languages
Definition: PluginManager.cpp:1247
GetTracePluginInstances
static TraceInstances & GetTracePluginInstances()
Definition: PluginManager.cpp:1029
PluginInstances::UnregisterPlugin
bool UnregisterPlugin(typename Instance::CallbackType callback)
Definition: PluginManager.cpp:215
PluginInstances::RegisterPlugin
bool RegisterPlugin(ConstString name, const char *description, typename Instance::CallbackType callback, Args &&... args)
Definition: PluginManager.cpp:203
JITLoaderInstances
PluginInstances< JITLoaderInstance > JITLoaderInstances
Definition: PluginManager.cpp:406
ArchitectureInstance
PluginInstance< ArchitectureCreateInstance > ArchitectureInstance
Definition: PluginManager.cpp:302
GetProcessInstances
static ProcessInstances & GetProcessInstances()
Definition: PluginManager.cpp:799
GetTypeSystemInstances
static TypeSystemInstances & GetTypeSystemInstances()
Definition: PluginManager.cpp:1198
DynamicLoaderInstances
PluginInstances< DynamicLoaderInstance > DynamicLoaderInstances
Definition: PluginManager.cpp:373
ObjectContainerInstances
PluginInstances< ObjectContainerInstance > ObjectContainerInstances
Definition: PluginManager.cpp:712
lldb_private::FileSystem::EnumerateDirectoryResult
EnumerateDirectoryResult
Definition: FileSystem.h:162
OperatingSystemInstance
PluginInstance< OperatingSystemCreateInstance > OperatingSystemInstance
Definition: PluginManager.cpp:466
LanguageRuntimeInstance::precondition_callback
LanguageRuntimeGetExceptionPrecondition precondition_callback
Definition: PluginManager.cpp:538
TypeSystemInstance::supported_languages_for_types
LanguageSet supported_languages_for_types
Definition: PluginManager.cpp:1192
lldb_private::ConstString
Definition: ConstString.h:40
TraceInstance::schema
llvm::StringRef schema
Definition: PluginManager.cpp:1023
SymbolFileInstances
PluginInstances< SymbolFileInstance > SymbolFileInstances
Definition: PluginManager.cpp:959
GetLanguageInstances
static LanguageInstances & GetLanguageInstances()
Definition: PluginManager.cpp:502
StructuredDataPluginInstance::StructuredDataPluginInstance
StructuredDataPluginInstance(ConstString name, std::string description, CallbackType create_callback, DebuggerInitializeCallback debugger_init_callback, StructuredDataFilterLaunchInfo filter_callback)
Definition: PluginManager.cpp:903
TraceInstance
Definition: PluginManager.cpp:1011
SymbolVendorInstances
PluginInstances< SymbolVendorInstance > SymbolVendorInstances
Definition: PluginManager.cpp:986
PluginInstances::PerformDebuggerCallback
void PerformDebuggerCallback(Debugger &debugger)
Definition: PluginManager.cpp:257
PlatformInstances
PluginInstances< PlatformInstance > PlatformInstances
Definition: PluginManager.cpp:749
ScriptInterpreterCreateInstance
ObjectContainerCreateInstance
PluginInstance
Definition: PluginManager.cpp:183
TypeSystemInstance
Definition: PluginManager.cpp:1181
GetABIInstances
static ABIInstances & GetABIInstances()
Definition: PluginManager.cpp:282
GetEmulateInstructionInstances
static EmulateInstructionInstances & GetEmulateInstructionInstances()
Definition: PluginManager.cpp:436
lldb_private::Debugger
Definition: Debugger.h:70
PluginInstances::GetCallbackForName
Instance::CallbackType GetCallbackForName(ConstString name)
Definition: PluginManager.cpp:247
HostInfo.h
UnwindAssemblyInstances
PluginInstances< UnwindAssemblyInstance > UnwindAssemblyInstances
Definition: PluginManager.cpp:1080
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
StringList.h
ProcessInstance
PluginInstance< ProcessCreateInstance > ProcessInstance
Definition: PluginManager.cpp:796
PluginInfo::plugin_term_callback
PluginTermCallback plugin_term_callback
Definition: PluginManager.cpp:45
ObjectFileInstance::get_module_specifications
ObjectFileGetModuleSpecifications get_module_specifications
Definition: PluginManager.cpp:626
ScriptInterpreterInstance
Definition: PluginManager.cpp:844
StructuredDataPluginInstance
Definition: PluginManager.cpp:901
OptionValueProperties.h
SystemRuntimeInstance
PluginInstance< SystemRuntimeCreateInstance > SystemRuntimeInstance
Definition: PluginManager.cpp:586
TraceInstance::TraceInstance
TraceInstance(ConstString name, std::string description, CallbackType create_callback_for_session_file, TraceCreateInstanceForLiveProcess create_callback_for_live_process, llvm::StringRef schema)
Definition: PluginManager.cpp:1013
ObjectFileInstance
Definition: PluginManager.cpp:613
PluginIsLoaded
static bool PluginIsLoaded(const FileSpec &plugin_file_spec)
Definition: PluginManager.cpp:60
PluginInstance::CallbackType
Callback CallbackType
Definition: PluginManager.cpp:184
PosixApi.h
lldb_private::Status
Definition: Status.h:44
PluginInfo::plugin_init_callback
PluginInitCallback plugin_init_callback
Definition: PluginManager.cpp:44
ObjectFileInstance::create_memory_callback
ObjectFileCreateMemoryInstance create_memory_callback
Definition: PluginManager.cpp:625
GetSystemRuntimeInstances
static SystemRuntimeInstances & GetSystemRuntimeInstances()
Definition: PluginManager.cpp:589
LanguageInstance
PluginInstance< LanguageCreateInstance > LanguageInstance
Definition: PluginManager.cpp:499
uint32_t
SystemRuntimeInstances
PluginInstances< SystemRuntimeInstance > SystemRuntimeInstances
Definition: PluginManager.cpp:587
PluginInstances::GetNameAtIndex
const char * GetNameAtIndex(uint32_t idx)
Definition: PluginManager.cpp:241
GetPluginMap
static PluginTerminateMap & GetPluginMap()
Definition: PluginManager.cpp:55
LanguageInstances
PluginInstances< LanguageInstance > LanguageInstances
Definition: PluginManager.cpp:500
GetOperatingSystemInstances
static OperatingSystemInstances & GetOperatingSystemInstances()
Definition: PluginManager.cpp:469
InstrumentationRuntimeInstances
PluginInstances< InstrumentationRuntimeInstance > InstrumentationRuntimeInstances
Definition: PluginManager.cpp:1146
ObjectContainerInstance::ObjectContainerInstance
ObjectContainerInstance(ConstString name, std::string description, CallbackType create_callback, ObjectFileGetModuleSpecifications get_module_specifications)
Definition: PluginManager.cpp:703
REPLInstances
PluginInstances< REPLInstance > REPLInstances
Definition: PluginManager.cpp:1250
DynamicLoaderInstance
PluginInstance< DynamicLoaderCreateInstance > DynamicLoaderInstance
Definition: PluginManager.cpp:372
PluginInitCallback
bool(* PluginInitCallback)()
Definition: PluginManager.cpp:37
PluginInstance::PluginInstance
PluginInstance(ConstString name, std::string description, Callback create_callback=nullptr, DebuggerInitializeCallback debugger_init_callback=nullptr)
Definition: PluginManager.cpp:187
TypeSystemInstance::TypeSystemInstance
TypeSystemInstance(ConstString name, std::string description, CallbackType create_callback, LanguageSet supported_languages_for_types, LanguageSet supported_languages_for_expressions)
Definition: PluginManager.cpp:1182
GetArchitectureInstances
static ArchitectureInstances & GetArchitectureInstances()
Definition: PluginManager.cpp:305
PluginManager.h
kOperatingSystemPluginName
static const char * kOperatingSystemPluginName("os")
PluginInfo::PluginInfo
PluginInfo()
Definition: PluginManager.cpp:41
Status.h
JITLoaderInstance
PluginInstance< JITLoaderCreateInstance > JITLoaderInstance
Definition: PluginManager.cpp:405
InstrumentationRuntimeInstance
Definition: PluginManager.cpp:1133
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
ObjectFileCreateInstance
ProcessInstances
PluginInstances< ProcessInstance > ProcessInstances
Definition: PluginManager.cpp:797
GetInstrumentationRuntimeInstances
static InstrumentationRuntimeInstances & GetInstrumentationRuntimeInstances()
Definition: PluginManager.cpp:1148
FileSpec.h
lldb_private::CompletionRequest::AddCompletion
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
Definition: CompletionRequest.h:167
ObjectFileInstance::ObjectFileInstance
ObjectFileInstance(ConstString name, std::string description, CallbackType create_callback, ObjectFileCreateMemoryInstance create_memory_callback, ObjectFileGetModuleSpecifications get_module_specifications, ObjectFileSaveCore save_core)
Definition: PluginManager.cpp:614
PluginInstance::debugger_init_callback
DebuggerInitializeCallback debugger_init_callback
Definition: PluginManager.cpp:197
ConstString.h
MemoryHistoryInstances
PluginInstances< MemoryHistoryInstance > MemoryHistoryInstances
Definition: PluginManager.cpp:1107
lldb_private::LanguageSet
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
ScriptInterpreterInstances
PluginInstances< ScriptInterpreterInstance > ScriptInterpreterInstances
Definition: PluginManager.cpp:856
DisassemblerInstance
PluginInstance< DisassemblerCreateInstance > DisassemblerInstance
Definition: PluginManager.cpp:341
EmulateInstructionInstances
PluginInstances< EmulateInstructionInstance > EmulateInstructionInstances
Definition: PluginManager.cpp:434
ObjectContainerInstance
Definition: PluginManager.cpp:701
ArchitectureInstances
std::vector< ArchitectureInstance > ArchitectureInstances
Definition: PluginManager.cpp:303
TraceInstance::create_callback_for_live_process
TraceCreateInstanceForLiveProcess create_callback_for_live_process
Definition: PluginManager.cpp:1024
PluginInfo::library
llvm::sys::DynamicLibrary library
Definition: PluginManager.cpp:43
REPLCreateInstance
GetSymbolFileInstances
static SymbolFileInstances & GetSymbolFileInstances()
Definition: PluginManager.cpp:961
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
ScriptInterpreterInstance::ScriptInterpreterInstance
ScriptInterpreterInstance(ConstString name, std::string description, CallbackType create_callback, lldb::ScriptLanguage language)
Definition: PluginManager.cpp:846
lldb
Definition: SBAddress.h:15
GetObjectContainerInstances
static ObjectContainerInstances & GetObjectContainerInstances()
Definition: PluginManager.cpp:714
PluginInstances::GetDescriptionAtIndex
const char * GetDescriptionAtIndex(uint32_t idx)
Definition: PluginManager.cpp:235
GetDebuggerPropertyForPlugins
static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins(Debugger &debugger, ConstString plugin_type_name, ConstString plugin_type_desc, bool can_create)
Definition: PluginManager.cpp:1297
SetPluginInfo
static void SetPluginInfo(const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
Definition: PluginManager.cpp:66
ABIInstance
PluginInstance< ABICreateInstance > ABIInstance
Definition: PluginManager.cpp:279
PluginInstances::GetInstanceAtIndex
Instance * GetInstanceAtIndex(uint32_t idx)
Definition: PluginManager.cpp:267
PluginInstances::GetInstances
std::vector< Instance > & GetInstances()
Definition: PluginManager.cpp:265
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
PlatformInstance
PluginInstance< PlatformCreateInstance > PlatformInstance
Definition: PluginManager.cpp:748
DebuggerInitializeCallback