• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 #include "lldb/Core/PluginManager.h"
10 
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/HostInfo.h"
14 #include "lldb/Interpreter/OptionValueProperties.h"
15 #include "lldb/Utility/ConstString.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/StringList.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)
31 #include "lldb/Host/windows/PosixApi.h"
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 {
PluginInfoPluginInfo41   PluginInfo() : plugin_init_callback(nullptr), plugin_term_callback(nullptr) {}
42 
43   llvm::sys::DynamicLibrary library;
44   PluginInitCallback plugin_init_callback;
45   PluginTermCallback plugin_term_callback;
46 };
47 
48 typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
49 
GetPluginMapMutex()50 static std::recursive_mutex &GetPluginMapMutex() {
51   static std::recursive_mutex g_plugin_map_mutex;
52   return g_plugin_map_mutex;
53 }
54 
GetPluginMap()55 static PluginTerminateMap &GetPluginMap() {
56   static PluginTerminateMap g_plugin_map;
57   return g_plugin_map;
58 }
59 
PluginIsLoaded(const FileSpec & plugin_file_spec)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 
SetPluginInfo(const FileSpec & plugin_file_spec,const PluginInfo & plugin_info)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 
CastToFPtr(void * VPtr)74 template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) {
75   return reinterpret_cast<FPtrTy>(VPtr);
76 }
77 
78 static FileSystem::EnumerateDirectoryResult
LoadPluginCallback(void * baton,llvm::sys::fs::file_type ft,llvm::StringRef path)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 
Initialize()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 
Terminate()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;
PluginInstancePluginInstance187   PluginInstance(ConstString name, std::string description,
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 
194   ConstString name;
195   std::string description;
196   Callback create_callback;
197   DebuggerInitializeCallback debugger_init_callback;
198 };
199 
200 template <typename Instance> class PluginInstances {
201 public:
202   template <typename... Args>
RegisterPlugin(ConstString name,const char * description,typename Instance::CallbackType callback,Args &&...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 
UnregisterPlugin(typename Instance::CallbackType callback)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 
GetCallbackAtIndex(uint32_t idx)229   typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) {
230     if (Instance *instance = GetInstanceAtIndex(idx))
231       return instance->create_callback;
232     return nullptr;
233   }
234 
GetDescriptionAtIndex(uint32_t idx)235   const char *GetDescriptionAtIndex(uint32_t idx) {
236     if (Instance *instance = GetInstanceAtIndex(idx))
237       return instance->description.c_str();
238     return nullptr;
239   }
240 
GetNameAtIndex(uint32_t idx)241   const char *GetNameAtIndex(uint32_t idx) {
242     if (Instance *instance = GetInstanceAtIndex(idx))
243       return instance->name.GetCString();
244     return nullptr;
245   }
246 
GetCallbackForName(ConstString name)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 
PerformDebuggerCallback(Debugger & debugger)257   void PerformDebuggerCallback(Debugger &debugger) {
258     for (auto &instance : m_instances) {
259       if (instance.debugger_init_callback)
260         instance.debugger_init_callback(debugger);
261     }
262   }
263 
GetInstances() const264   const std::vector<Instance> &GetInstances() const { return m_instances; }
GetInstances()265   std::vector<Instance> &GetInstances() { return m_instances; }
266 
GetInstanceAtIndex(uint32_t idx)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 
279 typedef PluginInstance<ABICreateInstance> ABIInstance;
280 typedef PluginInstances<ABIInstance> ABIInstances;
281 
GetABIInstances()282 static ABIInstances &GetABIInstances() {
283   static ABIInstances g_instances;
284   return g_instances;
285 }
286 
RegisterPlugin(ConstString name,const char * description,ABICreateInstance create_callback)287 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
288                                    ABICreateInstance create_callback) {
289   return GetABIInstances().RegisterPlugin(name, description, create_callback);
290 }
291 
UnregisterPlugin(ABICreateInstance create_callback)292 bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) {
293   return GetABIInstances().UnregisterPlugin(create_callback);
294 }
295 
GetABICreateCallbackAtIndex(uint32_t idx)296 ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) {
297   return GetABIInstances().GetCallbackAtIndex(idx);
298 }
299 
300 #pragma mark Architecture
301 
302 typedef PluginInstance<ArchitectureCreateInstance> ArchitectureInstance;
303 typedef std::vector<ArchitectureInstance> ArchitectureInstances;
304 
GetArchitectureInstances()305 static ArchitectureInstances &GetArchitectureInstances() {
306   static ArchitectureInstances g_instances;
307   return g_instances;
308 }
309 
RegisterPlugin(ConstString name,llvm::StringRef description,ArchitectureCreateInstance create_callback)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 
UnregisterPlugin(ArchitectureCreateInstance create_callback)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>
CreateArchitectureInstance(const ArchSpec & arch)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 
341 typedef PluginInstance<DisassemblerCreateInstance> DisassemblerInstance;
342 typedef PluginInstances<DisassemblerInstance> DisassemblerInstances;
343 
GetDisassemblerInstances()344 static DisassemblerInstances &GetDisassemblerInstances() {
345   static DisassemblerInstances g_instances;
346   return g_instances;
347 }
348 
RegisterPlugin(ConstString name,const char * description,DisassemblerCreateInstance create_callback)349 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
350                                    DisassemblerCreateInstance create_callback) {
351   return GetDisassemblerInstances().RegisterPlugin(name, description,
352                                                    create_callback);
353 }
354 
UnregisterPlugin(DisassemblerCreateInstance create_callback)355 bool PluginManager::UnregisterPlugin(
356     DisassemblerCreateInstance create_callback) {
357   return GetDisassemblerInstances().UnregisterPlugin(create_callback);
358 }
359 
360 DisassemblerCreateInstance
GetDisassemblerCreateCallbackAtIndex(uint32_t idx)361 PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) {
362   return GetDisassemblerInstances().GetCallbackAtIndex(idx);
363 }
364 
365 DisassemblerCreateInstance
GetDisassemblerCreateCallbackForPluginName(ConstString name)366 PluginManager::GetDisassemblerCreateCallbackForPluginName(ConstString name) {
367   return GetDisassemblerInstances().GetCallbackForName(name);
368 }
369 
370 #pragma mark DynamicLoader
371 
372 typedef PluginInstance<DynamicLoaderCreateInstance> DynamicLoaderInstance;
373 typedef PluginInstances<DynamicLoaderInstance> DynamicLoaderInstances;
374 
GetDynamicLoaderInstances()375 static DynamicLoaderInstances &GetDynamicLoaderInstances() {
376   static DynamicLoaderInstances g_instances;
377   return g_instances;
378 }
379 
RegisterPlugin(ConstString name,const char * description,DynamicLoaderCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)380 bool PluginManager::RegisterPlugin(
381     ConstString name, const char *description,
382     DynamicLoaderCreateInstance create_callback,
383     DebuggerInitializeCallback debugger_init_callback) {
384   return GetDynamicLoaderInstances().RegisterPlugin(
385       name, description, create_callback, debugger_init_callback);
386 }
387 
UnregisterPlugin(DynamicLoaderCreateInstance create_callback)388 bool PluginManager::UnregisterPlugin(
389     DynamicLoaderCreateInstance create_callback) {
390   return GetDynamicLoaderInstances().UnregisterPlugin(create_callback);
391 }
392 
393 DynamicLoaderCreateInstance
GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx)394 PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) {
395   return GetDynamicLoaderInstances().GetCallbackAtIndex(idx);
396 }
397 
398 DynamicLoaderCreateInstance
GetDynamicLoaderCreateCallbackForPluginName(ConstString name)399 PluginManager::GetDynamicLoaderCreateCallbackForPluginName(ConstString name) {
400   return GetDynamicLoaderInstances().GetCallbackForName(name);
401 }
402 
403 #pragma mark JITLoader
404 
405 typedef PluginInstance<JITLoaderCreateInstance> JITLoaderInstance;
406 typedef PluginInstances<JITLoaderInstance> JITLoaderInstances;
407 
GetJITLoaderInstances()408 static JITLoaderInstances &GetJITLoaderInstances() {
409   static JITLoaderInstances g_instances;
410   return g_instances;
411 }
412 
RegisterPlugin(ConstString name,const char * description,JITLoaderCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)413 bool PluginManager::RegisterPlugin(
414     ConstString name, const char *description,
415     JITLoaderCreateInstance create_callback,
416     DebuggerInitializeCallback debugger_init_callback) {
417   return GetJITLoaderInstances().RegisterPlugin(
418       name, description, create_callback, debugger_init_callback);
419 }
420 
UnregisterPlugin(JITLoaderCreateInstance create_callback)421 bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) {
422   return GetJITLoaderInstances().UnregisterPlugin(create_callback);
423 }
424 
425 JITLoaderCreateInstance
GetJITLoaderCreateCallbackAtIndex(uint32_t idx)426 PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) {
427   return GetJITLoaderInstances().GetCallbackAtIndex(idx);
428 }
429 
430 #pragma mark EmulateInstruction
431 
432 typedef PluginInstance<EmulateInstructionCreateInstance>
433     EmulateInstructionInstance;
434 typedef PluginInstances<EmulateInstructionInstance> EmulateInstructionInstances;
435 
GetEmulateInstructionInstances()436 static EmulateInstructionInstances &GetEmulateInstructionInstances() {
437   static EmulateInstructionInstances g_instances;
438   return g_instances;
439 }
440 
RegisterPlugin(ConstString name,const char * description,EmulateInstructionCreateInstance create_callback)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 
UnregisterPlugin(EmulateInstructionCreateInstance create_callback)448 bool PluginManager::UnregisterPlugin(
449     EmulateInstructionCreateInstance create_callback) {
450   return GetEmulateInstructionInstances().UnregisterPlugin(create_callback);
451 }
452 
453 EmulateInstructionCreateInstance
GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx)454 PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) {
455   return GetEmulateInstructionInstances().GetCallbackAtIndex(idx);
456 }
457 
458 EmulateInstructionCreateInstance
GetEmulateInstructionCreateCallbackForPluginName(ConstString name)459 PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
460     ConstString name) {
461   return GetEmulateInstructionInstances().GetCallbackForName(name);
462 }
463 
464 #pragma mark OperatingSystem
465 
466 typedef PluginInstance<OperatingSystemCreateInstance> OperatingSystemInstance;
467 typedef PluginInstances<OperatingSystemInstance> OperatingSystemInstances;
468 
GetOperatingSystemInstances()469 static OperatingSystemInstances &GetOperatingSystemInstances() {
470   static OperatingSystemInstances g_instances;
471   return g_instances;
472 }
473 
RegisterPlugin(ConstString name,const char * description,OperatingSystemCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)474 bool PluginManager::RegisterPlugin(
475     ConstString name, const char *description,
476     OperatingSystemCreateInstance create_callback,
477     DebuggerInitializeCallback debugger_init_callback) {
478   return GetOperatingSystemInstances().RegisterPlugin(
479       name, description, create_callback, debugger_init_callback);
480 }
481 
UnregisterPlugin(OperatingSystemCreateInstance create_callback)482 bool PluginManager::UnregisterPlugin(
483     OperatingSystemCreateInstance create_callback) {
484   return GetOperatingSystemInstances().UnregisterPlugin(create_callback);
485 }
486 
487 OperatingSystemCreateInstance
GetOperatingSystemCreateCallbackAtIndex(uint32_t idx)488 PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
489   return GetOperatingSystemInstances().GetCallbackAtIndex(idx);
490 }
491 
492 OperatingSystemCreateInstance
GetOperatingSystemCreateCallbackForPluginName(ConstString name)493 PluginManager::GetOperatingSystemCreateCallbackForPluginName(ConstString name) {
494   return GetOperatingSystemInstances().GetCallbackForName(name);
495 }
496 
497 #pragma mark Language
498 
499 typedef PluginInstance<LanguageCreateInstance> LanguageInstance;
500 typedef PluginInstances<LanguageInstance> LanguageInstances;
501 
GetLanguageInstances()502 static LanguageInstances &GetLanguageInstances() {
503   static LanguageInstances g_instances;
504   return g_instances;
505 }
506 
RegisterPlugin(ConstString name,const char * description,LanguageCreateInstance create_callback)507 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
508                                    LanguageCreateInstance create_callback) {
509   return GetLanguageInstances().RegisterPlugin(name, description,
510                                                create_callback);
511 }
512 
UnregisterPlugin(LanguageCreateInstance create_callback)513 bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
514   return GetLanguageInstances().UnregisterPlugin(create_callback);
515 }
516 
517 LanguageCreateInstance
GetLanguageCreateCallbackAtIndex(uint32_t idx)518 PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) {
519   return GetLanguageInstances().GetCallbackAtIndex(idx);
520 }
521 
522 #pragma mark LanguageRuntime
523 
524 struct LanguageRuntimeInstance
525     : public PluginInstance<LanguageRuntimeCreateInstance> {
LanguageRuntimeInstanceLanguageRuntimeInstance526   LanguageRuntimeInstance(
527       ConstString name, std::string description, CallbackType create_callback,
528       DebuggerInitializeCallback debugger_init_callback,
529       LanguageRuntimeGetCommandObject command_callback,
530       LanguageRuntimeGetExceptionPrecondition precondition_callback)
531       : PluginInstance<LanguageRuntimeCreateInstance>(
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 
541 typedef PluginInstances<LanguageRuntimeInstance> LanguageRuntimeInstances;
542 
GetLanguageRuntimeInstances()543 static LanguageRuntimeInstances &GetLanguageRuntimeInstances() {
544   static LanguageRuntimeInstances g_instances;
545   return g_instances;
546 }
547 
RegisterPlugin(ConstString name,const char * description,LanguageRuntimeCreateInstance create_callback,LanguageRuntimeGetCommandObject command_callback,LanguageRuntimeGetExceptionPrecondition precondition_callback)548 bool PluginManager::RegisterPlugin(
549     ConstString name, const char *description,
550     LanguageRuntimeCreateInstance create_callback,
551     LanguageRuntimeGetCommandObject command_callback,
552     LanguageRuntimeGetExceptionPrecondition precondition_callback) {
553   return GetLanguageRuntimeInstances().RegisterPlugin(
554       name, description, create_callback, nullptr, command_callback,
555       precondition_callback);
556 }
557 
UnregisterPlugin(LanguageRuntimeCreateInstance create_callback)558 bool PluginManager::UnregisterPlugin(
559     LanguageRuntimeCreateInstance create_callback) {
560   return GetLanguageRuntimeInstances().UnregisterPlugin(create_callback);
561 }
562 
563 LanguageRuntimeCreateInstance
GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx)564 PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
565   return GetLanguageRuntimeInstances().GetCallbackAtIndex(idx);
566 }
567 
568 LanguageRuntimeGetCommandObject
GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx)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
GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx)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 
586 typedef PluginInstance<SystemRuntimeCreateInstance> SystemRuntimeInstance;
587 typedef PluginInstances<SystemRuntimeInstance> SystemRuntimeInstances;
588 
GetSystemRuntimeInstances()589 static SystemRuntimeInstances &GetSystemRuntimeInstances() {
590   static SystemRuntimeInstances g_instances;
591   return g_instances;
592 }
593 
RegisterPlugin(ConstString name,const char * description,SystemRuntimeCreateInstance create_callback)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 
UnregisterPlugin(SystemRuntimeCreateInstance create_callback)601 bool PluginManager::UnregisterPlugin(
602     SystemRuntimeCreateInstance create_callback) {
603   return GetSystemRuntimeInstances().UnregisterPlugin(create_callback);
604 }
605 
606 SystemRuntimeCreateInstance
GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx)607 PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) {
608   return GetSystemRuntimeInstances().GetCallbackAtIndex(idx);
609 }
610 
611 #pragma mark ObjectFile
612 
613 struct ObjectFileInstance : public PluginInstance<ObjectFileCreateInstance> {
ObjectFileInstanceObjectFileInstance614   ObjectFileInstance(
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 };
629 typedef PluginInstances<ObjectFileInstance> ObjectFileInstances;
630 
GetObjectFileInstances()631 static ObjectFileInstances &GetObjectFileInstances() {
632   static ObjectFileInstances g_instances;
633   return g_instances;
634 }
635 
RegisterPlugin(ConstString name,const char * description,ObjectFileCreateInstance create_callback,ObjectFileCreateMemoryInstance create_memory_callback,ObjectFileGetModuleSpecifications get_module_specifications,ObjectFileSaveCore save_core)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) {
642   return GetObjectFileInstances().RegisterPlugin(
643       name, description, create_callback, create_memory_callback,
644       get_module_specifications, save_core);
645 }
646 
UnregisterPlugin(ObjectFileCreateInstance create_callback)647 bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
648   return GetObjectFileInstances().UnregisterPlugin(create_callback);
649 }
650 
651 ObjectFileCreateInstance
GetObjectFileCreateCallbackAtIndex(uint32_t idx)652 PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
653   return GetObjectFileInstances().GetCallbackAtIndex(idx);
654 }
655 
656 ObjectFileCreateMemoryInstance
GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx)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
GetObjectFileGetModuleSpecificationsCallbackAtIndex(uint32_t idx)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
GetObjectFileCreateMemoryCallbackForPluginName(ConstString name)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 
SaveCore(const lldb::ProcessSP & process_sp,const FileSpec & outfile)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 
701 struct ObjectContainerInstance
702     : public PluginInstance<ObjectContainerCreateInstance> {
ObjectContainerInstanceObjectContainerInstance703   ObjectContainerInstance(
704       ConstString name, std::string description, CallbackType create_callback,
705       ObjectFileGetModuleSpecifications get_module_specifications)
706       : PluginInstance<ObjectContainerCreateInstance>(
707             name, std::move(description), create_callback),
708         get_module_specifications(get_module_specifications) {}
709 
710   ObjectFileGetModuleSpecifications get_module_specifications;
711 };
712 typedef PluginInstances<ObjectContainerInstance> ObjectContainerInstances;
713 
GetObjectContainerInstances()714 static ObjectContainerInstances &GetObjectContainerInstances() {
715   static ObjectContainerInstances g_instances;
716   return g_instances;
717 }
718 
RegisterPlugin(ConstString name,const char * description,ObjectContainerCreateInstance create_callback,ObjectFileGetModuleSpecifications get_module_specifications)719 bool PluginManager::RegisterPlugin(
720     ConstString name, const char *description,
721     ObjectContainerCreateInstance create_callback,
722     ObjectFileGetModuleSpecifications get_module_specifications) {
723   return GetObjectContainerInstances().RegisterPlugin(
724       name, description, create_callback, get_module_specifications);
725 }
726 
UnregisterPlugin(ObjectContainerCreateInstance create_callback)727 bool PluginManager::UnregisterPlugin(
728     ObjectContainerCreateInstance create_callback) {
729   return GetObjectContainerInstances().UnregisterPlugin(create_callback);
730 }
731 
732 ObjectContainerCreateInstance
GetObjectContainerCreateCallbackAtIndex(uint32_t idx)733 PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
734   return GetObjectContainerInstances().GetCallbackAtIndex(idx);
735 }
736 
737 ObjectFileGetModuleSpecifications
GetObjectContainerGetModuleSpecificationsCallbackAtIndex(uint32_t idx)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 
748 typedef PluginInstance<PlatformCreateInstance> PlatformInstance;
749 typedef PluginInstances<PlatformInstance> PlatformInstances;
750 
GetPlatformInstances()751 static PlatformInstances &GetPlatformInstances() {
752   static PlatformInstances g_platform_instances;
753   return g_platform_instances;
754 }
755 
RegisterPlugin(ConstString name,const char * description,PlatformCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)756 bool PluginManager::RegisterPlugin(
757     ConstString name, const char *description,
758     PlatformCreateInstance create_callback,
759     DebuggerInitializeCallback debugger_init_callback) {
760   return GetPlatformInstances().RegisterPlugin(
761       name, description, create_callback, debugger_init_callback);
762 }
763 
UnregisterPlugin(PlatformCreateInstance create_callback)764 bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) {
765   return GetPlatformInstances().UnregisterPlugin(create_callback);
766 }
767 
GetPlatformPluginNameAtIndex(uint32_t idx)768 const char *PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) {
769   return GetPlatformInstances().GetNameAtIndex(idx);
770 }
771 
GetPlatformPluginDescriptionAtIndex(uint32_t idx)772 const char *PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) {
773   return GetPlatformInstances().GetDescriptionAtIndex(idx);
774 }
775 
776 PlatformCreateInstance
GetPlatformCreateCallbackAtIndex(uint32_t idx)777 PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) {
778   return GetPlatformInstances().GetCallbackAtIndex(idx);
779 }
780 
781 PlatformCreateInstance
GetPlatformCreateCallbackForPluginName(ConstString name)782 PluginManager::GetPlatformCreateCallbackForPluginName(ConstString name) {
783   return GetPlatformInstances().GetCallbackForName(name);
784 }
785 
AutoCompletePlatformName(llvm::StringRef name,CompletionRequest & request)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 
796 typedef PluginInstance<ProcessCreateInstance> ProcessInstance;
797 typedef PluginInstances<ProcessInstance> ProcessInstances;
798 
GetProcessInstances()799 static ProcessInstances &GetProcessInstances() {
800   static ProcessInstances g_instances;
801   return g_instances;
802 }
803 
RegisterPlugin(ConstString name,const char * description,ProcessCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)804 bool PluginManager::RegisterPlugin(
805     ConstString name, const char *description,
806     ProcessCreateInstance create_callback,
807     DebuggerInitializeCallback debugger_init_callback) {
808   return GetProcessInstances().RegisterPlugin(
809       name, description, create_callback, debugger_init_callback);
810 }
811 
UnregisterPlugin(ProcessCreateInstance create_callback)812 bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) {
813   return GetProcessInstances().UnregisterPlugin(create_callback);
814 }
815 
GetProcessPluginNameAtIndex(uint32_t idx)816 const char *PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) {
817   return GetProcessInstances().GetNameAtIndex(idx);
818 }
819 
GetProcessPluginDescriptionAtIndex(uint32_t idx)820 const char *PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) {
821   return GetProcessInstances().GetDescriptionAtIndex(idx);
822 }
823 
824 ProcessCreateInstance
GetProcessCreateCallbackAtIndex(uint32_t idx)825 PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) {
826   return GetProcessInstances().GetCallbackAtIndex(idx);
827 }
828 
829 ProcessCreateInstance
GetProcessCreateCallbackForPluginName(ConstString name)830 PluginManager::GetProcessCreateCallbackForPluginName(ConstString name) {
831   return GetProcessInstances().GetCallbackForName(name);
832 }
833 
AutoCompleteProcessName(llvm::StringRef name,CompletionRequest & request)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 
844 struct ScriptInterpreterInstance
845     : public PluginInstance<ScriptInterpreterCreateInstance> {
ScriptInterpreterInstanceScriptInterpreterInstance846   ScriptInterpreterInstance(ConstString name, std::string description,
847                             CallbackType create_callback,
848                             lldb::ScriptLanguage language)
849       : PluginInstance<ScriptInterpreterCreateInstance>(
850             name, std::move(description), create_callback),
851         language(language) {}
852 
853   lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
854 };
855 
856 typedef PluginInstances<ScriptInterpreterInstance> ScriptInterpreterInstances;
857 
GetScriptInterpreterInstances()858 static ScriptInterpreterInstances &GetScriptInterpreterInstances() {
859   static ScriptInterpreterInstances g_instances;
860   return g_instances;
861 }
862 
RegisterPlugin(ConstString name,const char * description,lldb::ScriptLanguage script_language,ScriptInterpreterCreateInstance create_callback)863 bool PluginManager::RegisterPlugin(
864     ConstString name, const char *description,
865     lldb::ScriptLanguage script_language,
866     ScriptInterpreterCreateInstance create_callback) {
867   return GetScriptInterpreterInstances().RegisterPlugin(
868       name, description, create_callback, script_language);
869 }
870 
UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)871 bool PluginManager::UnregisterPlugin(
872     ScriptInterpreterCreateInstance create_callback) {
873   return GetScriptInterpreterInstances().UnregisterPlugin(create_callback);
874 }
875 
876 ScriptInterpreterCreateInstance
GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)877 PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
878   return GetScriptInterpreterInstances().GetCallbackAtIndex(idx);
879 }
880 
881 lldb::ScriptInterpreterSP
GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,Debugger & debugger)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 
901 struct StructuredDataPluginInstance
902     : public PluginInstance<StructuredDataPluginCreateInstance> {
StructuredDataPluginInstanceStructuredDataPluginInstance903   StructuredDataPluginInstance(
904       ConstString name, std::string description, CallbackType create_callback,
905       DebuggerInitializeCallback debugger_init_callback,
906       StructuredDataFilterLaunchInfo filter_callback)
907       : PluginInstance<StructuredDataPluginCreateInstance>(
908             name, std::move(description), create_callback,
909             debugger_init_callback),
910         filter_callback(filter_callback) {}
911 
912   StructuredDataFilterLaunchInfo filter_callback = nullptr;
913 };
914 
915 typedef PluginInstances<StructuredDataPluginInstance>
916     StructuredDataPluginInstances;
917 
GetStructuredDataPluginInstances()918 static StructuredDataPluginInstances &GetStructuredDataPluginInstances() {
919   static StructuredDataPluginInstances g_instances;
920   return g_instances;
921 }
922 
RegisterPlugin(ConstString name,const char * description,StructuredDataPluginCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback,StructuredDataFilterLaunchInfo filter_callback)923 bool PluginManager::RegisterPlugin(
924     ConstString name, const char *description,
925     StructuredDataPluginCreateInstance create_callback,
926     DebuggerInitializeCallback debugger_init_callback,
927     StructuredDataFilterLaunchInfo filter_callback) {
928   return GetStructuredDataPluginInstances().RegisterPlugin(
929       name, description, create_callback, debugger_init_callback,
930       filter_callback);
931 }
932 
UnregisterPlugin(StructuredDataPluginCreateInstance create_callback)933 bool PluginManager::UnregisterPlugin(
934     StructuredDataPluginCreateInstance create_callback) {
935   return GetStructuredDataPluginInstances().UnregisterPlugin(create_callback);
936 }
937 
938 StructuredDataPluginCreateInstance
GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx)939 PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
940   return GetStructuredDataPluginInstances().GetCallbackAtIndex(idx);
941 }
942 
943 StructuredDataFilterLaunchInfo
GetStructuredDataFilterCallbackAtIndex(uint32_t idx,bool & iteration_complete)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 
958 typedef PluginInstance<SymbolFileCreateInstance> SymbolFileInstance;
959 typedef PluginInstances<SymbolFileInstance> SymbolFileInstances;
960 
GetSymbolFileInstances()961 static SymbolFileInstances &GetSymbolFileInstances() {
962   static SymbolFileInstances g_instances;
963   return g_instances;
964 }
965 
RegisterPlugin(ConstString name,const char * description,SymbolFileCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)966 bool PluginManager::RegisterPlugin(
967     ConstString name, const char *description,
968     SymbolFileCreateInstance create_callback,
969     DebuggerInitializeCallback debugger_init_callback) {
970   return GetSymbolFileInstances().RegisterPlugin(
971       name, description, create_callback, debugger_init_callback);
972 }
973 
UnregisterPlugin(SymbolFileCreateInstance create_callback)974 bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) {
975   return GetSymbolFileInstances().UnregisterPlugin(create_callback);
976 }
977 
978 SymbolFileCreateInstance
GetSymbolFileCreateCallbackAtIndex(uint32_t idx)979 PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) {
980   return GetSymbolFileInstances().GetCallbackAtIndex(idx);
981 }
982 
983 #pragma mark SymbolVendor
984 
985 typedef PluginInstance<SymbolVendorCreateInstance> SymbolVendorInstance;
986 typedef PluginInstances<SymbolVendorInstance> SymbolVendorInstances;
987 
GetSymbolVendorInstances()988 static SymbolVendorInstances &GetSymbolVendorInstances() {
989   static SymbolVendorInstances g_instances;
990   return g_instances;
991 }
992 
RegisterPlugin(ConstString name,const char * description,SymbolVendorCreateInstance create_callback)993 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
994                                    SymbolVendorCreateInstance create_callback) {
995   return GetSymbolVendorInstances().RegisterPlugin(name, description,
996                                                    create_callback);
997 }
998 
UnregisterPlugin(SymbolVendorCreateInstance create_callback)999 bool PluginManager::UnregisterPlugin(
1000     SymbolVendorCreateInstance create_callback) {
1001   return GetSymbolVendorInstances().UnregisterPlugin(create_callback);
1002 }
1003 
1004 SymbolVendorCreateInstance
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx)1005 PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
1006   return GetSymbolVendorInstances().GetCallbackAtIndex(idx);
1007 }
1008 
1009 #pragma mark Trace
1010 
1011 struct TraceInstance : public PluginInstance<TraceCreateInstance> {
TraceInstanceTraceInstance1012   TraceInstance(ConstString name, std::string description,
1013                 CallbackType create_callback, llvm::StringRef schema,
1014                 TraceGetStartCommand get_start_command)
1015       : PluginInstance<TraceCreateInstance>(name, std::move(description),
1016                                             create_callback),
1017         schema(schema), get_start_command(get_start_command) {}
1018 
1019   llvm::StringRef schema;
1020   TraceGetStartCommand get_start_command;
1021 };
1022 
1023 typedef PluginInstances<TraceInstance> TraceInstances;
1024 
GetTracePluginInstances()1025 static TraceInstances &GetTracePluginInstances() {
1026   static TraceInstances g_instances;
1027   return g_instances;
1028 }
1029 
RegisterPlugin(ConstString name,const char * description,TraceCreateInstance create_callback,llvm::StringRef schema,TraceGetStartCommand get_start_command)1030 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
1031                                    TraceCreateInstance create_callback,
1032                                    llvm::StringRef schema,
1033                                    TraceGetStartCommand get_start_command) {
1034   return GetTracePluginInstances().RegisterPlugin(
1035       name, description, create_callback, schema, get_start_command);
1036 }
1037 
UnregisterPlugin(TraceCreateInstance create_callback)1038 bool PluginManager::UnregisterPlugin(TraceCreateInstance create_callback) {
1039   return GetTracePluginInstances().UnregisterPlugin(create_callback);
1040 }
1041 
1042 TraceCreateInstance
GetTraceCreateCallback(ConstString plugin_name)1043 PluginManager::GetTraceCreateCallback(ConstString plugin_name) {
1044   return GetTracePluginInstances().GetCallbackForName(plugin_name);
1045 }
1046 
GetTraceSchema(ConstString plugin_name)1047 llvm::StringRef PluginManager::GetTraceSchema(ConstString plugin_name) {
1048   for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1049     if (instance.name == plugin_name)
1050       return instance.schema;
1051   return llvm::StringRef();
1052 }
1053 
1054 CommandObjectSP
GetTraceStartCommand(llvm::StringRef plugin_name,CommandInterpreter & interpreter)1055 PluginManager::GetTraceStartCommand(llvm::StringRef plugin_name,
1056                                     CommandInterpreter &interpreter) {
1057   for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1058     if (instance.name.GetStringRef() == plugin_name)
1059       return instance.get_start_command(interpreter);
1060   return CommandObjectSP();
1061 }
1062 
GetTraceSchema(size_t index)1063 llvm::StringRef PluginManager::GetTraceSchema(size_t index) {
1064   if (TraceInstance *instance =
1065           GetTracePluginInstances().GetInstanceAtIndex(index))
1066     return instance->schema;
1067   return llvm::StringRef();
1068 }
1069 
1070 #pragma mark UnwindAssembly
1071 
1072 typedef PluginInstance<UnwindAssemblyCreateInstance> UnwindAssemblyInstance;
1073 typedef PluginInstances<UnwindAssemblyInstance> UnwindAssemblyInstances;
1074 
GetUnwindAssemblyInstances()1075 static UnwindAssemblyInstances &GetUnwindAssemblyInstances() {
1076   static UnwindAssemblyInstances g_instances;
1077   return g_instances;
1078 }
1079 
RegisterPlugin(ConstString name,const char * description,UnwindAssemblyCreateInstance create_callback)1080 bool PluginManager::RegisterPlugin(
1081     ConstString name, const char *description,
1082     UnwindAssemblyCreateInstance create_callback) {
1083   return GetUnwindAssemblyInstances().RegisterPlugin(name, description,
1084                                                      create_callback);
1085 }
1086 
UnregisterPlugin(UnwindAssemblyCreateInstance create_callback)1087 bool PluginManager::UnregisterPlugin(
1088     UnwindAssemblyCreateInstance create_callback) {
1089   return GetUnwindAssemblyInstances().UnregisterPlugin(create_callback);
1090 }
1091 
1092 UnwindAssemblyCreateInstance
GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx)1093 PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) {
1094   return GetUnwindAssemblyInstances().GetCallbackAtIndex(idx);
1095 }
1096 
1097 #pragma mark MemoryHistory
1098 
1099 typedef PluginInstance<MemoryHistoryCreateInstance> MemoryHistoryInstance;
1100 typedef PluginInstances<MemoryHistoryInstance> MemoryHistoryInstances;
1101 
GetMemoryHistoryInstances()1102 static MemoryHistoryInstances &GetMemoryHistoryInstances() {
1103   static MemoryHistoryInstances g_instances;
1104   return g_instances;
1105 }
1106 
RegisterPlugin(ConstString name,const char * description,MemoryHistoryCreateInstance create_callback)1107 bool PluginManager::RegisterPlugin(
1108     ConstString name, const char *description,
1109     MemoryHistoryCreateInstance create_callback) {
1110   return GetMemoryHistoryInstances().RegisterPlugin(name, description,
1111                                                     create_callback);
1112 }
1113 
UnregisterPlugin(MemoryHistoryCreateInstance create_callback)1114 bool PluginManager::UnregisterPlugin(
1115     MemoryHistoryCreateInstance create_callback) {
1116   return GetMemoryHistoryInstances().UnregisterPlugin(create_callback);
1117 }
1118 
1119 MemoryHistoryCreateInstance
GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx)1120 PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) {
1121   return GetMemoryHistoryInstances().GetCallbackAtIndex(idx);
1122 }
1123 
1124 #pragma mark InstrumentationRuntime
1125 
1126 struct InstrumentationRuntimeInstance
1127     : public PluginInstance<InstrumentationRuntimeCreateInstance> {
InstrumentationRuntimeInstanceInstrumentationRuntimeInstance1128   InstrumentationRuntimeInstance(
1129       ConstString name, std::string description, CallbackType create_callback,
1130       InstrumentationRuntimeGetType get_type_callback)
1131       : PluginInstance<InstrumentationRuntimeCreateInstance>(
1132             name, std::move(description), create_callback),
1133         get_type_callback(get_type_callback) {}
1134 
1135   InstrumentationRuntimeGetType get_type_callback = nullptr;
1136 };
1137 
1138 typedef PluginInstances<InstrumentationRuntimeInstance>
1139     InstrumentationRuntimeInstances;
1140 
GetInstrumentationRuntimeInstances()1141 static InstrumentationRuntimeInstances &GetInstrumentationRuntimeInstances() {
1142   static InstrumentationRuntimeInstances g_instances;
1143   return g_instances;
1144 }
1145 
RegisterPlugin(ConstString name,const char * description,InstrumentationRuntimeCreateInstance create_callback,InstrumentationRuntimeGetType get_type_callback)1146 bool PluginManager::RegisterPlugin(
1147     ConstString name, const char *description,
1148     InstrumentationRuntimeCreateInstance create_callback,
1149     InstrumentationRuntimeGetType get_type_callback) {
1150   return GetInstrumentationRuntimeInstances().RegisterPlugin(
1151       name, description, create_callback, get_type_callback);
1152 }
1153 
UnregisterPlugin(InstrumentationRuntimeCreateInstance create_callback)1154 bool PluginManager::UnregisterPlugin(
1155     InstrumentationRuntimeCreateInstance create_callback) {
1156   return GetInstrumentationRuntimeInstances().UnregisterPlugin(create_callback);
1157 }
1158 
1159 InstrumentationRuntimeGetType
GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx)1160 PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
1161   const auto &instances = GetInstrumentationRuntimeInstances().GetInstances();
1162   if (idx < instances.size())
1163     return instances[idx].get_type_callback;
1164   return nullptr;
1165 }
1166 
1167 InstrumentationRuntimeCreateInstance
GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx)1168 PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) {
1169   return GetInstrumentationRuntimeInstances().GetCallbackAtIndex(idx);
1170 }
1171 
1172 #pragma mark TypeSystem
1173 
1174 struct TypeSystemInstance : public PluginInstance<TypeSystemCreateInstance> {
TypeSystemInstanceTypeSystemInstance1175   TypeSystemInstance(ConstString name, std::string description,
1176                      CallbackType create_callback,
1177                      LanguageSet supported_languages_for_types,
1178                      LanguageSet supported_languages_for_expressions)
1179       : PluginInstance<TypeSystemCreateInstance>(name, std::move(description),
1180                                                  create_callback),
1181         supported_languages_for_types(supported_languages_for_types),
1182         supported_languages_for_expressions(
1183             supported_languages_for_expressions) {}
1184 
1185   LanguageSet supported_languages_for_types;
1186   LanguageSet supported_languages_for_expressions;
1187 };
1188 
1189 typedef PluginInstances<TypeSystemInstance> TypeSystemInstances;
1190 
GetTypeSystemInstances()1191 static TypeSystemInstances &GetTypeSystemInstances() {
1192   static TypeSystemInstances g_instances;
1193   return g_instances;
1194 }
1195 
RegisterPlugin(ConstString name,const char * description,TypeSystemCreateInstance create_callback,LanguageSet supported_languages_for_types,LanguageSet supported_languages_for_expressions)1196 bool PluginManager::RegisterPlugin(
1197     ConstString name, const char *description,
1198     TypeSystemCreateInstance create_callback,
1199     LanguageSet supported_languages_for_types,
1200     LanguageSet supported_languages_for_expressions) {
1201   return GetTypeSystemInstances().RegisterPlugin(
1202       name, description, create_callback, supported_languages_for_types,
1203       supported_languages_for_expressions);
1204 }
1205 
UnregisterPlugin(TypeSystemCreateInstance create_callback)1206 bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
1207   return GetTypeSystemInstances().UnregisterPlugin(create_callback);
1208 }
1209 
1210 TypeSystemCreateInstance
GetTypeSystemCreateCallbackAtIndex(uint32_t idx)1211 PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
1212   return GetTypeSystemInstances().GetCallbackAtIndex(idx);
1213 }
1214 
GetAllTypeSystemSupportedLanguagesForTypes()1215 LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
1216   const auto &instances = GetTypeSystemInstances().GetInstances();
1217   LanguageSet all;
1218   for (unsigned i = 0; i < instances.size(); ++i)
1219     all.bitvector |= instances[i].supported_languages_for_types.bitvector;
1220   return all;
1221 }
1222 
GetAllTypeSystemSupportedLanguagesForExpressions()1223 LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
1224   const auto &instances = GetTypeSystemInstances().GetInstances();
1225   LanguageSet all;
1226   for (unsigned i = 0; i < instances.size(); ++i)
1227     all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
1228   return all;
1229 }
1230 
1231 #pragma mark REPL
1232 
1233 struct REPLInstance : public PluginInstance<REPLCreateInstance> {
REPLInstanceREPLInstance1234   REPLInstance(ConstString name, std::string description,
1235                CallbackType create_callback, LanguageSet supported_languages)
1236       : PluginInstance<REPLCreateInstance>(name, std::move(description),
1237                                            create_callback),
1238         supported_languages(supported_languages) {}
1239 
1240   LanguageSet supported_languages;
1241 };
1242 
1243 typedef PluginInstances<REPLInstance> REPLInstances;
1244 
GetREPLInstances()1245 static REPLInstances &GetREPLInstances() {
1246   static REPLInstances g_instances;
1247   return g_instances;
1248 }
1249 
RegisterPlugin(ConstString name,const char * description,REPLCreateInstance create_callback,LanguageSet supported_languages)1250 bool PluginManager::RegisterPlugin(ConstString name, const char *description,
1251                                    REPLCreateInstance create_callback,
1252                                    LanguageSet supported_languages) {
1253   return GetREPLInstances().RegisterPlugin(name, description, create_callback,
1254                                            supported_languages);
1255 }
1256 
UnregisterPlugin(REPLCreateInstance create_callback)1257 bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) {
1258   return GetREPLInstances().UnregisterPlugin(create_callback);
1259 }
1260 
GetREPLCreateCallbackAtIndex(uint32_t idx)1261 REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
1262   return GetREPLInstances().GetCallbackAtIndex(idx);
1263 }
1264 
GetREPLAllTypeSystemSupportedLanguages()1265 LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
1266   const auto &instances = GetREPLInstances().GetInstances();
1267   LanguageSet all;
1268   for (unsigned i = 0; i < instances.size(); ++i)
1269     all.bitvector |= instances[i].supported_languages.bitvector;
1270   return all;
1271 }
1272 
1273 #pragma mark PluginManager
1274 
DebuggerInitialize(Debugger & debugger)1275 void PluginManager::DebuggerInitialize(Debugger &debugger) {
1276   GetDynamicLoaderInstances().PerformDebuggerCallback(debugger);
1277   GetJITLoaderInstances().PerformDebuggerCallback(debugger);
1278   GetPlatformInstances().PerformDebuggerCallback(debugger);
1279   GetProcessInstances().PerformDebuggerCallback(debugger);
1280   GetSymbolFileInstances().PerformDebuggerCallback(debugger);
1281   GetOperatingSystemInstances().PerformDebuggerCallback(debugger);
1282   GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
1283   GetTracePluginInstances().PerformDebuggerCallback(debugger);
1284 }
1285 
1286 // This is the preferred new way to register plugin specific settings.  e.g.
1287 // This will put a plugin's settings under e.g.
1288 // "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
1289 static lldb::OptionValuePropertiesSP
GetDebuggerPropertyForPlugins(Debugger & debugger,ConstString plugin_type_name,ConstString plugin_type_desc,bool can_create)1290 GetDebuggerPropertyForPlugins(Debugger &debugger, ConstString plugin_type_name,
1291                               ConstString plugin_type_desc, bool can_create) {
1292   lldb::OptionValuePropertiesSP parent_properties_sp(
1293       debugger.GetValueProperties());
1294   if (parent_properties_sp) {
1295     static ConstString g_property_name("plugin");
1296 
1297     OptionValuePropertiesSP plugin_properties_sp =
1298         parent_properties_sp->GetSubProperty(nullptr, g_property_name);
1299     if (!plugin_properties_sp && can_create) {
1300       plugin_properties_sp =
1301           std::make_shared<OptionValueProperties>(g_property_name);
1302       parent_properties_sp->AppendProperty(
1303           g_property_name, ConstString("Settings specify to plugins."), true,
1304           plugin_properties_sp);
1305     }
1306 
1307     if (plugin_properties_sp) {
1308       lldb::OptionValuePropertiesSP plugin_type_properties_sp =
1309           plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
1310       if (!plugin_type_properties_sp && can_create) {
1311         plugin_type_properties_sp =
1312             std::make_shared<OptionValueProperties>(plugin_type_name);
1313         plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
1314                                              true, plugin_type_properties_sp);
1315       }
1316       return plugin_type_properties_sp;
1317     }
1318   }
1319   return lldb::OptionValuePropertiesSP();
1320 }
1321 
1322 // This is deprecated way to register plugin specific settings.  e.g.
1323 // "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform
1324 // generic settings would be under "platform.SETTINGNAME".
GetDebuggerPropertyForPluginsOldStyle(Debugger & debugger,ConstString plugin_type_name,ConstString plugin_type_desc,bool can_create)1325 static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(
1326     Debugger &debugger, ConstString plugin_type_name,
1327     ConstString plugin_type_desc, bool can_create) {
1328   static ConstString g_property_name("plugin");
1329   lldb::OptionValuePropertiesSP parent_properties_sp(
1330       debugger.GetValueProperties());
1331   if (parent_properties_sp) {
1332     OptionValuePropertiesSP plugin_properties_sp =
1333         parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
1334     if (!plugin_properties_sp && can_create) {
1335       plugin_properties_sp =
1336           std::make_shared<OptionValueProperties>(plugin_type_name);
1337       parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
1338                                            true, plugin_properties_sp);
1339     }
1340 
1341     if (plugin_properties_sp) {
1342       lldb::OptionValuePropertiesSP plugin_type_properties_sp =
1343           plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
1344       if (!plugin_type_properties_sp && can_create) {
1345         plugin_type_properties_sp =
1346             std::make_shared<OptionValueProperties>(g_property_name);
1347         plugin_properties_sp->AppendProperty(
1348             g_property_name, ConstString("Settings specific to plugins"), true,
1349             plugin_type_properties_sp);
1350       }
1351       return plugin_type_properties_sp;
1352     }
1353   }
1354   return lldb::OptionValuePropertiesSP();
1355 }
1356 
1357 namespace {
1358 
1359 typedef lldb::OptionValuePropertiesSP
1360 GetDebuggerPropertyForPluginsPtr(Debugger &, ConstString, ConstString,
1361                                  bool can_create);
1362 
1363 lldb::OptionValuePropertiesSP
GetSettingForPlugin(Debugger & debugger,ConstString setting_name,ConstString plugin_type_name,GetDebuggerPropertyForPluginsPtr get_debugger_property=GetDebuggerPropertyForPlugins)1364 GetSettingForPlugin(Debugger &debugger, ConstString setting_name,
1365                     ConstString plugin_type_name,
1366                     GetDebuggerPropertyForPluginsPtr get_debugger_property =
1367                         GetDebuggerPropertyForPlugins) {
1368   lldb::OptionValuePropertiesSP properties_sp;
1369   lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property(
1370       debugger, plugin_type_name,
1371       ConstString(), // not creating to so we don't need the description
1372       false));
1373   if (plugin_type_properties_sp)
1374     properties_sp =
1375         plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1376   return properties_sp;
1377 }
1378 
CreateSettingForPlugin(Debugger & debugger,ConstString plugin_type_name,ConstString plugin_type_desc,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property,GetDebuggerPropertyForPluginsPtr get_debugger_property=GetDebuggerPropertyForPlugins)1379 bool CreateSettingForPlugin(
1380     Debugger &debugger, ConstString plugin_type_name,
1381     ConstString plugin_type_desc,
1382     const lldb::OptionValuePropertiesSP &properties_sp, ConstString description,
1383     bool is_global_property,
1384     GetDebuggerPropertyForPluginsPtr get_debugger_property =
1385         GetDebuggerPropertyForPlugins) {
1386   if (properties_sp) {
1387     lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1388         get_debugger_property(debugger, plugin_type_name, plugin_type_desc,
1389                               true));
1390     if (plugin_type_properties_sp) {
1391       plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
1392                                                 description, is_global_property,
1393                                                 properties_sp);
1394       return true;
1395     }
1396   }
1397   return false;
1398 }
1399 
1400 const char *kDynamicLoaderPluginName("dynamic-loader");
1401 const char *kPlatformPluginName("platform");
1402 const char *kProcessPluginName("process");
1403 const char *kSymbolFilePluginName("symbol-file");
1404 const char *kJITLoaderPluginName("jit-loader");
1405 const char *kStructuredDataPluginName("structured-data");
1406 
1407 } // anonymous namespace
1408 
1409 lldb::OptionValuePropertiesSP
GetSettingForDynamicLoaderPlugin(Debugger & debugger,ConstString setting_name)1410 PluginManager::GetSettingForDynamicLoaderPlugin(Debugger &debugger,
1411                                                 ConstString setting_name) {
1412   return GetSettingForPlugin(debugger, setting_name,
1413                              ConstString(kDynamicLoaderPluginName));
1414 }
1415 
CreateSettingForDynamicLoaderPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1416 bool PluginManager::CreateSettingForDynamicLoaderPlugin(
1417     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1418     ConstString description, bool is_global_property) {
1419   return CreateSettingForPlugin(
1420       debugger, ConstString(kDynamicLoaderPluginName),
1421       ConstString("Settings for dynamic loader plug-ins"), properties_sp,
1422       description, is_global_property);
1423 }
1424 
1425 lldb::OptionValuePropertiesSP
GetSettingForPlatformPlugin(Debugger & debugger,ConstString setting_name)1426 PluginManager::GetSettingForPlatformPlugin(Debugger &debugger,
1427                                            ConstString setting_name) {
1428   return GetSettingForPlugin(debugger, setting_name,
1429                              ConstString(kPlatformPluginName),
1430                              GetDebuggerPropertyForPluginsOldStyle);
1431 }
1432 
CreateSettingForPlatformPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1433 bool PluginManager::CreateSettingForPlatformPlugin(
1434     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1435     ConstString description, bool is_global_property) {
1436   return CreateSettingForPlugin(debugger, ConstString(kPlatformPluginName),
1437                                 ConstString("Settings for platform plug-ins"),
1438                                 properties_sp, description, is_global_property,
1439                                 GetDebuggerPropertyForPluginsOldStyle);
1440 }
1441 
1442 lldb::OptionValuePropertiesSP
GetSettingForProcessPlugin(Debugger & debugger,ConstString setting_name)1443 PluginManager::GetSettingForProcessPlugin(Debugger &debugger,
1444                                           ConstString setting_name) {
1445   return GetSettingForPlugin(debugger, setting_name,
1446                              ConstString(kProcessPluginName));
1447 }
1448 
CreateSettingForProcessPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1449 bool PluginManager::CreateSettingForProcessPlugin(
1450     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1451     ConstString description, bool is_global_property) {
1452   return CreateSettingForPlugin(debugger, ConstString(kProcessPluginName),
1453                                 ConstString("Settings for process plug-ins"),
1454                                 properties_sp, description, is_global_property);
1455 }
1456 
1457 lldb::OptionValuePropertiesSP
GetSettingForSymbolFilePlugin(Debugger & debugger,ConstString setting_name)1458 PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger,
1459                                              ConstString setting_name) {
1460   return GetSettingForPlugin(debugger, setting_name,
1461                              ConstString(kSymbolFilePluginName));
1462 }
1463 
CreateSettingForSymbolFilePlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1464 bool PluginManager::CreateSettingForSymbolFilePlugin(
1465     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1466     ConstString description, bool is_global_property) {
1467   return CreateSettingForPlugin(
1468       debugger, ConstString(kSymbolFilePluginName),
1469       ConstString("Settings for symbol file plug-ins"), properties_sp,
1470       description, is_global_property);
1471 }
1472 
1473 lldb::OptionValuePropertiesSP
GetSettingForJITLoaderPlugin(Debugger & debugger,ConstString setting_name)1474 PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger,
1475                                             ConstString setting_name) {
1476   return GetSettingForPlugin(debugger, setting_name,
1477                              ConstString(kJITLoaderPluginName));
1478 }
1479 
CreateSettingForJITLoaderPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1480 bool PluginManager::CreateSettingForJITLoaderPlugin(
1481     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1482     ConstString description, bool is_global_property) {
1483   return CreateSettingForPlugin(debugger, ConstString(kJITLoaderPluginName),
1484                                 ConstString("Settings for JIT loader plug-ins"),
1485                                 properties_sp, description, is_global_property);
1486 }
1487 
1488 static const char *kOperatingSystemPluginName("os");
1489 
1490 lldb::OptionValuePropertiesSP
GetSettingForOperatingSystemPlugin(Debugger & debugger,ConstString setting_name)1491 PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger,
1492                                                   ConstString setting_name) {
1493   lldb::OptionValuePropertiesSP properties_sp;
1494   lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1495       GetDebuggerPropertyForPlugins(
1496           debugger, ConstString(kOperatingSystemPluginName),
1497           ConstString(), // not creating to so we don't need the description
1498           false));
1499   if (plugin_type_properties_sp)
1500     properties_sp =
1501         plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1502   return properties_sp;
1503 }
1504 
CreateSettingForOperatingSystemPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1505 bool PluginManager::CreateSettingForOperatingSystemPlugin(
1506     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1507     ConstString description, bool is_global_property) {
1508   if (properties_sp) {
1509     lldb::OptionValuePropertiesSP plugin_type_properties_sp(
1510         GetDebuggerPropertyForPlugins(
1511             debugger, ConstString(kOperatingSystemPluginName),
1512             ConstString("Settings for operating system plug-ins"), true));
1513     if (plugin_type_properties_sp) {
1514       plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
1515                                                 description, is_global_property,
1516                                                 properties_sp);
1517       return true;
1518     }
1519   }
1520   return false;
1521 }
1522 
1523 lldb::OptionValuePropertiesSP
GetSettingForStructuredDataPlugin(Debugger & debugger,ConstString setting_name)1524 PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger,
1525                                                  ConstString setting_name) {
1526   return GetSettingForPlugin(debugger, setting_name,
1527                              ConstString(kStructuredDataPluginName));
1528 }
1529 
CreateSettingForStructuredDataPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,ConstString description,bool is_global_property)1530 bool PluginManager::CreateSettingForStructuredDataPlugin(
1531     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1532     ConstString description, bool is_global_property) {
1533   return CreateSettingForPlugin(
1534       debugger, ConstString(kStructuredDataPluginName),
1535       ConstString("Settings for structured data plug-ins"), properties_sp,
1536       description, is_global_property);
1537 }
1538