xref: /src/contrib/llvm-project/lldb/source/Core/PluginManager.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1cfca06d7SDimitry Andric //===-- PluginManager.cpp -------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/Core/PluginManager.h"
10f034231aSEd Maste 
11f034231aSEd Maste #include "lldb/Core/Debugger.h"
1294994d37SDimitry Andric #include "lldb/Host/FileSystem.h"
130cac4ca3SEd Maste #include "lldb/Host/HostInfo.h"
14f034231aSEd Maste #include "lldb/Interpreter/OptionValueProperties.h"
15ac9a064cSDimitry Andric #include "lldb/Symbol/SaveCoreOptions.h"
16c0981da4SDimitry Andric #include "lldb/Target/Process.h"
1774a628f7SDimitry Andric #include "lldb/Utility/FileSpec.h"
18b76161e4SDimitry Andric #include "lldb/Utility/Status.h"
1994994d37SDimitry Andric #include "lldb/Utility/StringList.h"
2074a628f7SDimitry Andric #include "llvm/ADT/StringRef.h"
2174a628f7SDimitry Andric #include "llvm/Support/DynamicLibrary.h"
2294994d37SDimitry Andric #include "llvm/Support/FileSystem.h"
2394994d37SDimitry Andric #include "llvm/Support/raw_ostream.h"
24344a3780SDimitry Andric #include <cassert>
2594994d37SDimitry Andric #include <map>
2694994d37SDimitry Andric #include <memory>
2774a628f7SDimitry Andric #include <mutex>
2874a628f7SDimitry Andric #include <string>
2994994d37SDimitry Andric #include <utility>
3074a628f7SDimitry Andric #include <vector>
31cfca06d7SDimitry Andric #if defined(_WIN32)
32cfca06d7SDimitry Andric #include "lldb/Host/windows/PosixApi.h"
33cfca06d7SDimitry Andric #endif
34f034231aSEd Maste 
35f034231aSEd Maste using namespace lldb;
36f034231aSEd Maste using namespace lldb_private;
37f034231aSEd Maste 
38f3fbd1c0SDimitry Andric typedef bool (*PluginInitCallback)();
39f3fbd1c0SDimitry Andric typedef void (*PluginTermCallback)();
40f034231aSEd Maste 
4114f1b3e8SDimitry Andric struct PluginInfo {
42344a3780SDimitry Andric   PluginInfo() = default;
430cac4ca3SEd Maste 
440cac4ca3SEd Maste   llvm::sys::DynamicLibrary library;
45344a3780SDimitry Andric   PluginInitCallback plugin_init_callback = nullptr;
46344a3780SDimitry Andric   PluginTermCallback plugin_term_callback = nullptr;
47f034231aSEd Maste };
48f034231aSEd Maste 
49f034231aSEd Maste typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
50f034231aSEd Maste 
GetPluginMapMutex()5114f1b3e8SDimitry Andric static std::recursive_mutex &GetPluginMapMutex() {
52f3fbd1c0SDimitry Andric   static std::recursive_mutex g_plugin_map_mutex;
53f034231aSEd Maste   return g_plugin_map_mutex;
54f034231aSEd Maste }
55f034231aSEd Maste 
GetPluginMap()5614f1b3e8SDimitry Andric static PluginTerminateMap &GetPluginMap() {
57f034231aSEd Maste   static PluginTerminateMap g_plugin_map;
58f034231aSEd Maste   return g_plugin_map;
59f034231aSEd Maste }
60f034231aSEd Maste 
PluginIsLoaded(const FileSpec & plugin_file_spec)6114f1b3e8SDimitry Andric static bool PluginIsLoaded(const FileSpec &plugin_file_spec) {
62f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
63f034231aSEd Maste   PluginTerminateMap &plugin_map = GetPluginMap();
64f034231aSEd Maste   return plugin_map.find(plugin_file_spec) != plugin_map.end();
65f034231aSEd Maste }
66f034231aSEd Maste 
SetPluginInfo(const FileSpec & plugin_file_spec,const PluginInfo & plugin_info)6714f1b3e8SDimitry Andric static void SetPluginInfo(const FileSpec &plugin_file_spec,
6814f1b3e8SDimitry Andric                           const PluginInfo &plugin_info) {
69f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
70f034231aSEd Maste   PluginTerminateMap &plugin_map = GetPluginMap();
71f034231aSEd Maste   assert(plugin_map.find(plugin_file_spec) == plugin_map.end());
72f034231aSEd Maste   plugin_map[plugin_file_spec] = plugin_info;
73f034231aSEd Maste }
74f034231aSEd Maste 
CastToFPtr(void * VPtr)7514f1b3e8SDimitry Andric template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) {
76706b4fc4SDimitry Andric   return reinterpret_cast<FPtrTy>(VPtr);
770cac4ca3SEd Maste }
78f034231aSEd Maste 
7994994d37SDimitry Andric static FileSystem::EnumerateDirectoryResult
LoadPluginCallback(void * baton,llvm::sys::fs::file_type ft,llvm::StringRef path)8074a628f7SDimitry Andric LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
8194994d37SDimitry Andric                    llvm::StringRef path) {
82b76161e4SDimitry Andric   Status error;
83f034231aSEd Maste 
8474a628f7SDimitry Andric   namespace fs = llvm::sys::fs;
85f73363f1SDimitry Andric   // If we have a regular file, a symbolic link or unknown file type, try and
86f73363f1SDimitry Andric   // process the file. We must handle unknown as sometimes the directory
87f034231aSEd Maste   // enumeration might be enumerating a file system that doesn't have correct
88f034231aSEd Maste   // file type information.
8974a628f7SDimitry Andric   if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
9074a628f7SDimitry Andric       ft == fs::file_type::type_unknown) {
9194994d37SDimitry Andric     FileSpec plugin_file_spec(path);
9294994d37SDimitry Andric     FileSystem::Instance().Resolve(plugin_file_spec);
93f034231aSEd Maste 
94f034231aSEd Maste     if (PluginIsLoaded(plugin_file_spec))
9594994d37SDimitry Andric       return FileSystem::eEnumerateDirectoryResultNext;
9614f1b3e8SDimitry Andric     else {
970cac4ca3SEd Maste       PluginInfo plugin_info;
98f034231aSEd Maste 
990cac4ca3SEd Maste       std::string pluginLoadError;
10014f1b3e8SDimitry Andric       plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary(
10114f1b3e8SDimitry Andric           plugin_file_spec.GetPath().c_str(), &pluginLoadError);
10214f1b3e8SDimitry Andric       if (plugin_info.library.isValid()) {
103f034231aSEd Maste         bool success = false;
10414f1b3e8SDimitry Andric         plugin_info.plugin_init_callback = CastToFPtr<PluginInitCallback>(
10514f1b3e8SDimitry Andric             plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
10614f1b3e8SDimitry Andric         if (plugin_info.plugin_init_callback) {
107f034231aSEd Maste           // Call the plug-in "bool LLDBPluginInitialize(void)" function
108f034231aSEd Maste           success = plugin_info.plugin_init_callback();
109f034231aSEd Maste         }
110f034231aSEd Maste 
11114f1b3e8SDimitry Andric         if (success) {
112f3fbd1c0SDimitry Andric           // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
11314f1b3e8SDimitry Andric           plugin_info.plugin_term_callback = CastToFPtr<PluginTermCallback>(
11414f1b3e8SDimitry Andric               plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate"));
11514f1b3e8SDimitry Andric         } else {
11614f1b3e8SDimitry Andric           // The initialize function returned FALSE which means the plug-in
117f73363f1SDimitry Andric           // might not be compatible, or might be too new or too old, or might
118f73363f1SDimitry Andric           // not want to run on this machine.  Set it to a default-constructed
119f73363f1SDimitry Andric           // instance to invalidate it.
1200cac4ca3SEd Maste           plugin_info = PluginInfo();
121f034231aSEd Maste         }
122f034231aSEd Maste 
123f73363f1SDimitry Andric         // Regardless of success or failure, cache the plug-in load in our
124f73363f1SDimitry Andric         // plug-in info so we don't try to load it again and again.
125f034231aSEd Maste         SetPluginInfo(plugin_file_spec, plugin_info);
126f034231aSEd Maste 
12794994d37SDimitry Andric         return FileSystem::eEnumerateDirectoryResultNext;
128f034231aSEd Maste       }
129f034231aSEd Maste     }
130f034231aSEd Maste   }
131f034231aSEd Maste 
13274a628f7SDimitry Andric   if (ft == fs::file_type::directory_file ||
13374a628f7SDimitry Andric       ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) {
134f73363f1SDimitry Andric     // Try and recurse into anything that a directory or symbolic link. We must
135f73363f1SDimitry Andric     // also do this for unknown as sometimes the directory enumeration might be
136f73363f1SDimitry Andric     // enumerating a file system that doesn't have correct file type
137f034231aSEd Maste     // information.
13894994d37SDimitry Andric     return FileSystem::eEnumerateDirectoryResultEnter;
139f034231aSEd Maste   }
140f034231aSEd Maste 
14194994d37SDimitry Andric   return FileSystem::eEnumerateDirectoryResultNext;
142f034231aSEd Maste }
143f034231aSEd Maste 
Initialize()14414f1b3e8SDimitry Andric void PluginManager::Initialize() {
145f034231aSEd Maste   const bool find_directories = true;
146f034231aSEd Maste   const bool find_files = true;
147f034231aSEd Maste   const bool find_other = true;
148f034231aSEd Maste   char dir_path[PATH_MAX];
149f73363f1SDimitry Andric   if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
15094994d37SDimitry Andric     if (FileSystem::Instance().Exists(dir_spec) &&
15194994d37SDimitry Andric         dir_spec.GetPath(dir_path, sizeof(dir_path))) {
15294994d37SDimitry Andric       FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
15394994d37SDimitry Andric                                                 find_files, find_other,
15494994d37SDimitry Andric                                                 LoadPluginCallback, nullptr);
155f034231aSEd Maste     }
156f034231aSEd Maste   }
157f034231aSEd Maste 
158f73363f1SDimitry Andric   if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
15994994d37SDimitry Andric     if (FileSystem::Instance().Exists(dir_spec) &&
16094994d37SDimitry Andric         dir_spec.GetPath(dir_path, sizeof(dir_path))) {
16194994d37SDimitry Andric       FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
16294994d37SDimitry Andric                                                 find_files, find_other,
16394994d37SDimitry Andric                                                 LoadPluginCallback, nullptr);
164f034231aSEd Maste     }
165f034231aSEd Maste   }
166f034231aSEd Maste }
167f034231aSEd Maste 
Terminate()16814f1b3e8SDimitry Andric void PluginManager::Terminate() {
169f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
170f034231aSEd Maste   PluginTerminateMap &plugin_map = GetPluginMap();
171f034231aSEd Maste 
172f034231aSEd Maste   PluginTerminateMap::const_iterator pos, end = plugin_map.end();
17314f1b3e8SDimitry Andric   for (pos = plugin_map.begin(); pos != end; ++pos) {
174f73363f1SDimitry Andric     // Call the plug-in "void LLDBPluginTerminate (void)" function if there is
175f73363f1SDimitry Andric     // one (if the symbol was not nullptr).
17614f1b3e8SDimitry Andric     if (pos->second.library.isValid()) {
177f034231aSEd Maste       if (pos->second.plugin_term_callback)
178f034231aSEd Maste         pos->second.plugin_term_callback();
179f034231aSEd Maste     }
180f034231aSEd Maste   }
181f034231aSEd Maste   plugin_map.clear();
182f034231aSEd Maste }
183f034231aSEd Maste 
184cfca06d7SDimitry Andric template <typename Callback> struct PluginInstance {
185cfca06d7SDimitry Andric   typedef Callback CallbackType;
186f034231aSEd Maste 
187cfca06d7SDimitry Andric   PluginInstance() = default;
PluginInstancePluginInstance188c0981da4SDimitry Andric   PluginInstance(llvm::StringRef name, llvm::StringRef description,
189c0981da4SDimitry Andric                  Callback create_callback,
190cfca06d7SDimitry Andric                  DebuggerInitializeCallback debugger_init_callback = nullptr)
191c0981da4SDimitry Andric       : name(name), description(description), create_callback(create_callback),
192cfca06d7SDimitry Andric         debugger_init_callback(debugger_init_callback) {}
193f034231aSEd Maste 
194c0981da4SDimitry Andric   llvm::StringRef name;
195c0981da4SDimitry Andric   llvm::StringRef description;
196cfca06d7SDimitry Andric   Callback create_callback;
197cfca06d7SDimitry Andric   DebuggerInitializeCallback debugger_init_callback;
198f034231aSEd Maste };
199f034231aSEd Maste 
200cfca06d7SDimitry Andric template <typename Instance> class PluginInstances {
201cfca06d7SDimitry Andric public:
202cfca06d7SDimitry Andric   template <typename... Args>
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,typename Instance::CallbackType callback,Args &&...args)203c0981da4SDimitry Andric   bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
204cfca06d7SDimitry Andric                       typename Instance::CallbackType callback,
205cfca06d7SDimitry Andric                       Args &&...args) {
206cfca06d7SDimitry Andric     if (!callback)
207cfca06d7SDimitry Andric       return false;
208c0981da4SDimitry Andric     assert(!name.empty());
209cfca06d7SDimitry Andric     Instance instance =
210cfca06d7SDimitry Andric         Instance(name, description, callback, std::forward<Args>(args)...);
211cfca06d7SDimitry Andric     m_instances.push_back(instance);
212cfca06d7SDimitry Andric     return false;
213f034231aSEd Maste   }
214f034231aSEd Maste 
UnregisterPlugin(typename Instance::CallbackType callback)215cfca06d7SDimitry Andric   bool UnregisterPlugin(typename Instance::CallbackType callback) {
216cfca06d7SDimitry Andric     if (!callback)
217cfca06d7SDimitry Andric       return false;
218cfca06d7SDimitry Andric     auto pos = m_instances.begin();
219cfca06d7SDimitry Andric     auto end = m_instances.end();
220cfca06d7SDimitry Andric     for (; pos != end; ++pos) {
221cfca06d7SDimitry Andric       if (pos->create_callback == callback) {
222cfca06d7SDimitry Andric         m_instances.erase(pos);
223cfca06d7SDimitry Andric         return true;
224cfca06d7SDimitry Andric       }
225cfca06d7SDimitry Andric     }
226cfca06d7SDimitry Andric     return false;
227cfca06d7SDimitry Andric   }
228cfca06d7SDimitry Andric 
GetCallbackAtIndex(uint32_t idx)229cfca06d7SDimitry Andric   typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) {
230cfca06d7SDimitry Andric     if (Instance *instance = GetInstanceAtIndex(idx))
231cfca06d7SDimitry Andric       return instance->create_callback;
232cfca06d7SDimitry Andric     return nullptr;
233cfca06d7SDimitry Andric   }
234cfca06d7SDimitry Andric 
GetDescriptionAtIndex(uint32_t idx)235c0981da4SDimitry Andric   llvm::StringRef GetDescriptionAtIndex(uint32_t idx) {
236cfca06d7SDimitry Andric     if (Instance *instance = GetInstanceAtIndex(idx))
237c0981da4SDimitry Andric       return instance->description;
238c0981da4SDimitry Andric     return "";
239cfca06d7SDimitry Andric   }
240cfca06d7SDimitry Andric 
GetNameAtIndex(uint32_t idx)241c0981da4SDimitry Andric   llvm::StringRef GetNameAtIndex(uint32_t idx) {
242cfca06d7SDimitry Andric     if (Instance *instance = GetInstanceAtIndex(idx))
243c0981da4SDimitry Andric       return instance->name;
244c0981da4SDimitry Andric     return "";
245cfca06d7SDimitry Andric   }
246cfca06d7SDimitry Andric 
GetCallbackForName(llvm::StringRef name)247c0981da4SDimitry Andric   typename Instance::CallbackType GetCallbackForName(llvm::StringRef name) {
248c0981da4SDimitry Andric     if (name.empty())
249cfca06d7SDimitry Andric       return nullptr;
250cfca06d7SDimitry Andric     for (auto &instance : m_instances) {
251cfca06d7SDimitry Andric       if (name == instance.name)
252cfca06d7SDimitry Andric         return instance.create_callback;
253cfca06d7SDimitry Andric     }
254cfca06d7SDimitry Andric     return nullptr;
255cfca06d7SDimitry Andric   }
256cfca06d7SDimitry Andric 
PerformDebuggerCallback(Debugger & debugger)257cfca06d7SDimitry Andric   void PerformDebuggerCallback(Debugger &debugger) {
258cfca06d7SDimitry Andric     for (auto &instance : m_instances) {
259cfca06d7SDimitry Andric       if (instance.debugger_init_callback)
260cfca06d7SDimitry Andric         instance.debugger_init_callback(debugger);
261cfca06d7SDimitry Andric     }
262cfca06d7SDimitry Andric   }
263cfca06d7SDimitry Andric 
GetInstances() const264cfca06d7SDimitry Andric   const std::vector<Instance> &GetInstances() const { return m_instances; }
GetInstances()265cfca06d7SDimitry Andric   std::vector<Instance> &GetInstances() { return m_instances; }
266cfca06d7SDimitry Andric 
GetInstanceAtIndex(uint32_t idx)267cfca06d7SDimitry Andric   Instance *GetInstanceAtIndex(uint32_t idx) {
268cfca06d7SDimitry Andric     if (idx < m_instances.size())
269cfca06d7SDimitry Andric       return &m_instances[idx];
270cfca06d7SDimitry Andric     return nullptr;
271cfca06d7SDimitry Andric   }
272b60736ecSDimitry Andric 
273b60736ecSDimitry Andric private:
274cfca06d7SDimitry Andric   std::vector<Instance> m_instances;
275cfca06d7SDimitry Andric };
276cfca06d7SDimitry Andric 
277cfca06d7SDimitry Andric #pragma mark ABI
278cfca06d7SDimitry Andric 
279cfca06d7SDimitry Andric typedef PluginInstance<ABICreateInstance> ABIInstance;
280cfca06d7SDimitry Andric typedef PluginInstances<ABIInstance> ABIInstances;
281cfca06d7SDimitry Andric 
GetABIInstances()28214f1b3e8SDimitry Andric static ABIInstances &GetABIInstances() {
283f034231aSEd Maste   static ABIInstances g_instances;
284f034231aSEd Maste   return g_instances;
285f034231aSEd Maste }
286f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,ABICreateInstance create_callback)287c0981da4SDimitry Andric bool PluginManager::RegisterPlugin(llvm::StringRef name,
288c0981da4SDimitry Andric                                    llvm::StringRef description,
28914f1b3e8SDimitry Andric                                    ABICreateInstance create_callback) {
290cfca06d7SDimitry Andric   return GetABIInstances().RegisterPlugin(name, description, create_callback);
291f034231aSEd Maste }
292f034231aSEd Maste 
UnregisterPlugin(ABICreateInstance create_callback)29314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) {
294cfca06d7SDimitry Andric   return GetABIInstances().UnregisterPlugin(create_callback);
295f034231aSEd Maste }
296f034231aSEd Maste 
GetABICreateCallbackAtIndex(uint32_t idx)29714f1b3e8SDimitry Andric ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) {
298cfca06d7SDimitry Andric   return GetABIInstances().GetCallbackAtIndex(idx);
299f034231aSEd Maste }
300f034231aSEd Maste 
301ef5d0b5eSDimitry Andric #pragma mark Architecture
302ef5d0b5eSDimitry Andric 
303cfca06d7SDimitry Andric typedef PluginInstance<ArchitectureCreateInstance> ArchitectureInstance;
304ef5d0b5eSDimitry Andric typedef std::vector<ArchitectureInstance> ArchitectureInstances;
305ef5d0b5eSDimitry Andric 
GetArchitectureInstances()306ef5d0b5eSDimitry Andric static ArchitectureInstances &GetArchitectureInstances() {
307ef5d0b5eSDimitry Andric   static ArchitectureInstances g_instances;
308ef5d0b5eSDimitry Andric   return g_instances;
309ef5d0b5eSDimitry Andric }
310ef5d0b5eSDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,ArchitectureCreateInstance create_callback)311c0981da4SDimitry Andric void PluginManager::RegisterPlugin(llvm::StringRef name,
312ef5d0b5eSDimitry Andric                                    llvm::StringRef description,
313ef5d0b5eSDimitry Andric                                    ArchitectureCreateInstance create_callback) {
314c0981da4SDimitry Andric   GetArchitectureInstances().push_back({name, description, create_callback});
315ef5d0b5eSDimitry Andric }
316ef5d0b5eSDimitry Andric 
UnregisterPlugin(ArchitectureCreateInstance create_callback)317ef5d0b5eSDimitry Andric void PluginManager::UnregisterPlugin(
318ef5d0b5eSDimitry Andric     ArchitectureCreateInstance create_callback) {
319ef5d0b5eSDimitry Andric   auto &instances = GetArchitectureInstances();
320ef5d0b5eSDimitry Andric 
321ef5d0b5eSDimitry Andric   for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) {
322ef5d0b5eSDimitry Andric     if (pos->create_callback == create_callback) {
323ef5d0b5eSDimitry Andric       instances.erase(pos);
324ef5d0b5eSDimitry Andric       return;
325ef5d0b5eSDimitry Andric     }
326ef5d0b5eSDimitry Andric   }
327ef5d0b5eSDimitry Andric   llvm_unreachable("Plugin not found");
328ef5d0b5eSDimitry Andric }
329ef5d0b5eSDimitry Andric 
330ef5d0b5eSDimitry Andric std::unique_ptr<Architecture>
CreateArchitectureInstance(const ArchSpec & arch)331ef5d0b5eSDimitry Andric PluginManager::CreateArchitectureInstance(const ArchSpec &arch) {
332ef5d0b5eSDimitry Andric   for (const auto &instances : GetArchitectureInstances()) {
333ef5d0b5eSDimitry Andric     if (auto plugin_up = instances.create_callback(arch))
334ef5d0b5eSDimitry Andric       return plugin_up;
335ef5d0b5eSDimitry Andric   }
336ef5d0b5eSDimitry Andric   return nullptr;
337ef5d0b5eSDimitry Andric }
338ef5d0b5eSDimitry Andric 
339f034231aSEd Maste #pragma mark Disassembler
340f034231aSEd Maste 
341cfca06d7SDimitry Andric typedef PluginInstance<DisassemblerCreateInstance> DisassemblerInstance;
342cfca06d7SDimitry Andric typedef PluginInstances<DisassemblerInstance> DisassemblerInstances;
343f034231aSEd Maste 
GetDisassemblerInstances()34414f1b3e8SDimitry Andric static DisassemblerInstances &GetDisassemblerInstances() {
345f034231aSEd Maste   static DisassemblerInstances g_instances;
346f034231aSEd Maste   return g_instances;
347f034231aSEd Maste }
348f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,DisassemblerCreateInstance create_callback)349c0981da4SDimitry Andric bool PluginManager::RegisterPlugin(llvm::StringRef name,
350c0981da4SDimitry Andric                                    llvm::StringRef description,
35114f1b3e8SDimitry Andric                                    DisassemblerCreateInstance create_callback) {
352cfca06d7SDimitry Andric   return GetDisassemblerInstances().RegisterPlugin(name, description,
353cfca06d7SDimitry Andric                                                    create_callback);
354f034231aSEd Maste }
355f034231aSEd Maste 
UnregisterPlugin(DisassemblerCreateInstance create_callback)35614f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
35714f1b3e8SDimitry Andric     DisassemblerCreateInstance create_callback) {
358cfca06d7SDimitry Andric   return GetDisassemblerInstances().UnregisterPlugin(create_callback);
359f034231aSEd Maste }
360f034231aSEd Maste 
361f034231aSEd Maste DisassemblerCreateInstance
GetDisassemblerCreateCallbackAtIndex(uint32_t idx)36214f1b3e8SDimitry Andric PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) {
363cfca06d7SDimitry Andric   return GetDisassemblerInstances().GetCallbackAtIndex(idx);
364f034231aSEd Maste }
365f034231aSEd Maste 
366f034231aSEd Maste DisassemblerCreateInstance
GetDisassemblerCreateCallbackForPluginName(llvm::StringRef name)367c0981da4SDimitry Andric PluginManager::GetDisassemblerCreateCallbackForPluginName(
368c0981da4SDimitry Andric     llvm::StringRef name) {
369cfca06d7SDimitry Andric   return GetDisassemblerInstances().GetCallbackForName(name);
370f034231aSEd Maste }
371f034231aSEd Maste 
372f034231aSEd Maste #pragma mark DynamicLoader
373f034231aSEd Maste 
374cfca06d7SDimitry Andric typedef PluginInstance<DynamicLoaderCreateInstance> DynamicLoaderInstance;
375cfca06d7SDimitry Andric typedef PluginInstances<DynamicLoaderInstance> DynamicLoaderInstances;
376f034231aSEd Maste 
GetDynamicLoaderInstances()37714f1b3e8SDimitry Andric static DynamicLoaderInstances &GetDynamicLoaderInstances() {
378f034231aSEd Maste   static DynamicLoaderInstances g_instances;
379f034231aSEd Maste   return g_instances;
380f034231aSEd Maste }
381f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,DynamicLoaderCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)38214f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
383c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
384f034231aSEd Maste     DynamicLoaderCreateInstance create_callback,
38514f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
386cfca06d7SDimitry Andric   return GetDynamicLoaderInstances().RegisterPlugin(
387cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
388f034231aSEd Maste }
389f034231aSEd Maste 
UnregisterPlugin(DynamicLoaderCreateInstance create_callback)39014f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
39114f1b3e8SDimitry Andric     DynamicLoaderCreateInstance create_callback) {
392cfca06d7SDimitry Andric   return GetDynamicLoaderInstances().UnregisterPlugin(create_callback);
393f034231aSEd Maste }
394f034231aSEd Maste 
395f034231aSEd Maste DynamicLoaderCreateInstance
GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx)39614f1b3e8SDimitry Andric PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) {
397cfca06d7SDimitry Andric   return GetDynamicLoaderInstances().GetCallbackAtIndex(idx);
398f034231aSEd Maste }
399f034231aSEd Maste 
400f034231aSEd Maste DynamicLoaderCreateInstance
GetDynamicLoaderCreateCallbackForPluginName(llvm::StringRef name)401c0981da4SDimitry Andric PluginManager::GetDynamicLoaderCreateCallbackForPluginName(
402c0981da4SDimitry Andric     llvm::StringRef name) {
403cfca06d7SDimitry Andric   return GetDynamicLoaderInstances().GetCallbackForName(name);
404f034231aSEd Maste }
405f034231aSEd Maste 
4060cac4ca3SEd Maste #pragma mark JITLoader
4070cac4ca3SEd Maste 
408cfca06d7SDimitry Andric typedef PluginInstance<JITLoaderCreateInstance> JITLoaderInstance;
409cfca06d7SDimitry Andric typedef PluginInstances<JITLoaderInstance> JITLoaderInstances;
4100cac4ca3SEd Maste 
GetJITLoaderInstances()41114f1b3e8SDimitry Andric static JITLoaderInstances &GetJITLoaderInstances() {
4120cac4ca3SEd Maste   static JITLoaderInstances g_instances;
4130cac4ca3SEd Maste   return g_instances;
4140cac4ca3SEd Maste }
4150cac4ca3SEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,JITLoaderCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)41614f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
417c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
4180cac4ca3SEd Maste     JITLoaderCreateInstance create_callback,
41914f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
420cfca06d7SDimitry Andric   return GetJITLoaderInstances().RegisterPlugin(
421cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
4220cac4ca3SEd Maste }
4230cac4ca3SEd Maste 
UnregisterPlugin(JITLoaderCreateInstance create_callback)42414f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) {
425cfca06d7SDimitry Andric   return GetJITLoaderInstances().UnregisterPlugin(create_callback);
4260cac4ca3SEd Maste }
4270cac4ca3SEd Maste 
4280cac4ca3SEd Maste JITLoaderCreateInstance
GetJITLoaderCreateCallbackAtIndex(uint32_t idx)42914f1b3e8SDimitry Andric PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) {
430cfca06d7SDimitry Andric   return GetJITLoaderInstances().GetCallbackAtIndex(idx);
4310cac4ca3SEd Maste }
4320cac4ca3SEd Maste 
433f034231aSEd Maste #pragma mark EmulateInstruction
434f034231aSEd Maste 
435cfca06d7SDimitry Andric typedef PluginInstance<EmulateInstructionCreateInstance>
436cfca06d7SDimitry Andric     EmulateInstructionInstance;
437cfca06d7SDimitry Andric typedef PluginInstances<EmulateInstructionInstance> EmulateInstructionInstances;
438f034231aSEd Maste 
GetEmulateInstructionInstances()43914f1b3e8SDimitry Andric static EmulateInstructionInstances &GetEmulateInstructionInstances() {
440f034231aSEd Maste   static EmulateInstructionInstances g_instances;
441f034231aSEd Maste   return g_instances;
442f034231aSEd Maste }
443f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,EmulateInstructionCreateInstance create_callback)44414f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
445c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
44614f1b3e8SDimitry Andric     EmulateInstructionCreateInstance create_callback) {
447cfca06d7SDimitry Andric   return GetEmulateInstructionInstances().RegisterPlugin(name, description,
448cfca06d7SDimitry Andric                                                          create_callback);
449f034231aSEd Maste }
450f034231aSEd Maste 
UnregisterPlugin(EmulateInstructionCreateInstance create_callback)45114f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
45214f1b3e8SDimitry Andric     EmulateInstructionCreateInstance create_callback) {
453cfca06d7SDimitry Andric   return GetEmulateInstructionInstances().UnregisterPlugin(create_callback);
454f034231aSEd Maste }
455f034231aSEd Maste 
456f034231aSEd Maste EmulateInstructionCreateInstance
GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx)45714f1b3e8SDimitry Andric PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) {
458cfca06d7SDimitry Andric   return GetEmulateInstructionInstances().GetCallbackAtIndex(idx);
459f034231aSEd Maste }
460f034231aSEd Maste 
461f034231aSEd Maste EmulateInstructionCreateInstance
GetEmulateInstructionCreateCallbackForPluginName(llvm::StringRef name)46214f1b3e8SDimitry Andric PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
463c0981da4SDimitry Andric     llvm::StringRef name) {
464cfca06d7SDimitry Andric   return GetEmulateInstructionInstances().GetCallbackForName(name);
465f034231aSEd Maste }
466f034231aSEd Maste 
467f3fbd1c0SDimitry Andric #pragma mark OperatingSystem
468f034231aSEd Maste 
469cfca06d7SDimitry Andric typedef PluginInstance<OperatingSystemCreateInstance> OperatingSystemInstance;
470cfca06d7SDimitry Andric typedef PluginInstances<OperatingSystemInstance> OperatingSystemInstances;
471f034231aSEd Maste 
GetOperatingSystemInstances()47214f1b3e8SDimitry Andric static OperatingSystemInstances &GetOperatingSystemInstances() {
473f034231aSEd Maste   static OperatingSystemInstances g_instances;
474f034231aSEd Maste   return g_instances;
475f034231aSEd Maste }
476f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,OperatingSystemCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)47714f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
478c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
479e81d9d49SDimitry Andric     OperatingSystemCreateInstance create_callback,
48014f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
481cfca06d7SDimitry Andric   return GetOperatingSystemInstances().RegisterPlugin(
482cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
483f034231aSEd Maste }
484f034231aSEd Maste 
UnregisterPlugin(OperatingSystemCreateInstance create_callback)48514f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
48614f1b3e8SDimitry Andric     OperatingSystemCreateInstance create_callback) {
487cfca06d7SDimitry Andric   return GetOperatingSystemInstances().UnregisterPlugin(create_callback);
488f034231aSEd Maste }
489f034231aSEd Maste 
490f034231aSEd Maste OperatingSystemCreateInstance
GetOperatingSystemCreateCallbackAtIndex(uint32_t idx)49114f1b3e8SDimitry Andric PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
492cfca06d7SDimitry Andric   return GetOperatingSystemInstances().GetCallbackAtIndex(idx);
493f034231aSEd Maste }
494f034231aSEd Maste 
495f034231aSEd Maste OperatingSystemCreateInstance
GetOperatingSystemCreateCallbackForPluginName(llvm::StringRef name)496c0981da4SDimitry Andric PluginManager::GetOperatingSystemCreateCallbackForPluginName(
497c0981da4SDimitry Andric     llvm::StringRef name) {
498cfca06d7SDimitry Andric   return GetOperatingSystemInstances().GetCallbackForName(name);
499f034231aSEd Maste }
500f034231aSEd Maste 
501e81d9d49SDimitry Andric #pragma mark Language
502e81d9d49SDimitry Andric 
503cfca06d7SDimitry Andric typedef PluginInstance<LanguageCreateInstance> LanguageInstance;
504cfca06d7SDimitry Andric typedef PluginInstances<LanguageInstance> LanguageInstances;
505e81d9d49SDimitry Andric 
GetLanguageInstances()50614f1b3e8SDimitry Andric static LanguageInstances &GetLanguageInstances() {
507e81d9d49SDimitry Andric   static LanguageInstances g_instances;
508e81d9d49SDimitry Andric   return g_instances;
509e81d9d49SDimitry Andric }
510e81d9d49SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,LanguageCreateInstance create_callback)511c0981da4SDimitry Andric bool PluginManager::RegisterPlugin(llvm::StringRef name,
512c0981da4SDimitry Andric                                    llvm::StringRef description,
51314f1b3e8SDimitry Andric                                    LanguageCreateInstance create_callback) {
514cfca06d7SDimitry Andric   return GetLanguageInstances().RegisterPlugin(name, description,
515cfca06d7SDimitry Andric                                                create_callback);
516e81d9d49SDimitry Andric }
517e81d9d49SDimitry Andric 
UnregisterPlugin(LanguageCreateInstance create_callback)51814f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
519cfca06d7SDimitry Andric   return GetLanguageInstances().UnregisterPlugin(create_callback);
520e81d9d49SDimitry Andric }
521e81d9d49SDimitry Andric 
522e81d9d49SDimitry Andric LanguageCreateInstance
GetLanguageCreateCallbackAtIndex(uint32_t idx)52314f1b3e8SDimitry Andric PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) {
524cfca06d7SDimitry Andric   return GetLanguageInstances().GetCallbackAtIndex(idx);
525e81d9d49SDimitry Andric }
526e81d9d49SDimitry Andric 
527f034231aSEd Maste #pragma mark LanguageRuntime
528f034231aSEd Maste 
529cfca06d7SDimitry Andric struct LanguageRuntimeInstance
530cfca06d7SDimitry Andric     : public PluginInstance<LanguageRuntimeCreateInstance> {
LanguageRuntimeInstanceLanguageRuntimeInstance531cfca06d7SDimitry Andric   LanguageRuntimeInstance(
532c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
533c0981da4SDimitry Andric       CallbackType create_callback,
534cfca06d7SDimitry Andric       DebuggerInitializeCallback debugger_init_callback,
535cfca06d7SDimitry Andric       LanguageRuntimeGetCommandObject command_callback,
536cfca06d7SDimitry Andric       LanguageRuntimeGetExceptionPrecondition precondition_callback)
537cfca06d7SDimitry Andric       : PluginInstance<LanguageRuntimeCreateInstance>(
538c0981da4SDimitry Andric             name, description, create_callback, debugger_init_callback),
539cfca06d7SDimitry Andric         command_callback(command_callback),
540cfca06d7SDimitry Andric         precondition_callback(precondition_callback) {}
541f034231aSEd Maste 
5425e95aa85SEd Maste   LanguageRuntimeGetCommandObject command_callback;
5435f29bb8aSDimitry Andric   LanguageRuntimeGetExceptionPrecondition precondition_callback;
544f034231aSEd Maste };
545f034231aSEd Maste 
546cfca06d7SDimitry Andric typedef PluginInstances<LanguageRuntimeInstance> LanguageRuntimeInstances;
547f034231aSEd Maste 
GetLanguageRuntimeInstances()54814f1b3e8SDimitry Andric static LanguageRuntimeInstances &GetLanguageRuntimeInstances() {
549f034231aSEd Maste   static LanguageRuntimeInstances g_instances;
550f034231aSEd Maste   return g_instances;
551f034231aSEd Maste }
552f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,LanguageRuntimeCreateInstance create_callback,LanguageRuntimeGetCommandObject command_callback,LanguageRuntimeGetExceptionPrecondition precondition_callback)55314f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
554c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
5555e95aa85SEd Maste     LanguageRuntimeCreateInstance create_callback,
5565f29bb8aSDimitry Andric     LanguageRuntimeGetCommandObject command_callback,
5575f29bb8aSDimitry Andric     LanguageRuntimeGetExceptionPrecondition precondition_callback) {
558cfca06d7SDimitry Andric   return GetLanguageRuntimeInstances().RegisterPlugin(
559cfca06d7SDimitry Andric       name, description, create_callback, nullptr, command_callback,
560cfca06d7SDimitry Andric       precondition_callback);
561f034231aSEd Maste }
562f034231aSEd Maste 
UnregisterPlugin(LanguageRuntimeCreateInstance create_callback)56314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
56414f1b3e8SDimitry Andric     LanguageRuntimeCreateInstance create_callback) {
565cfca06d7SDimitry Andric   return GetLanguageRuntimeInstances().UnregisterPlugin(create_callback);
566f034231aSEd Maste }
567f034231aSEd Maste 
568f034231aSEd Maste LanguageRuntimeCreateInstance
GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx)56914f1b3e8SDimitry Andric PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
570cfca06d7SDimitry Andric   return GetLanguageRuntimeInstances().GetCallbackAtIndex(idx);
571f034231aSEd Maste }
572f034231aSEd Maste 
5735e95aa85SEd Maste LanguageRuntimeGetCommandObject
GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx)57414f1b3e8SDimitry Andric PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
575cfca06d7SDimitry Andric   const auto &instances = GetLanguageRuntimeInstances().GetInstances();
5765e95aa85SEd Maste   if (idx < instances.size())
5775e95aa85SEd Maste     return instances[idx].command_callback;
578f3fbd1c0SDimitry Andric   return nullptr;
5795e95aa85SEd Maste }
5805e95aa85SEd Maste 
5815f29bb8aSDimitry Andric LanguageRuntimeGetExceptionPrecondition
GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx)5825f29bb8aSDimitry Andric PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) {
583cfca06d7SDimitry Andric   const auto &instances = GetLanguageRuntimeInstances().GetInstances();
5845f29bb8aSDimitry Andric   if (idx < instances.size())
5855f29bb8aSDimitry Andric     return instances[idx].precondition_callback;
5865f29bb8aSDimitry Andric   return nullptr;
5875f29bb8aSDimitry Andric }
5885f29bb8aSDimitry Andric 
589f21a844fSEd Maste #pragma mark SystemRuntime
590f21a844fSEd Maste 
591cfca06d7SDimitry Andric typedef PluginInstance<SystemRuntimeCreateInstance> SystemRuntimeInstance;
592cfca06d7SDimitry Andric typedef PluginInstances<SystemRuntimeInstance> SystemRuntimeInstances;
593f21a844fSEd Maste 
GetSystemRuntimeInstances()59414f1b3e8SDimitry Andric static SystemRuntimeInstances &GetSystemRuntimeInstances() {
595f21a844fSEd Maste   static SystemRuntimeInstances g_instances;
596f21a844fSEd Maste   return g_instances;
597f21a844fSEd Maste }
598f21a844fSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,SystemRuntimeCreateInstance create_callback)59914f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
600c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
60114f1b3e8SDimitry Andric     SystemRuntimeCreateInstance create_callback) {
602cfca06d7SDimitry Andric   return GetSystemRuntimeInstances().RegisterPlugin(name, description,
603cfca06d7SDimitry Andric                                                     create_callback);
604f21a844fSEd Maste }
605f21a844fSEd Maste 
UnregisterPlugin(SystemRuntimeCreateInstance create_callback)60614f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
60714f1b3e8SDimitry Andric     SystemRuntimeCreateInstance create_callback) {
608cfca06d7SDimitry Andric   return GetSystemRuntimeInstances().UnregisterPlugin(create_callback);
609f21a844fSEd Maste }
610f21a844fSEd Maste 
611f21a844fSEd Maste SystemRuntimeCreateInstance
GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx)61214f1b3e8SDimitry Andric PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) {
613cfca06d7SDimitry Andric   return GetSystemRuntimeInstances().GetCallbackAtIndex(idx);
614f21a844fSEd Maste }
615f21a844fSEd Maste 
616f034231aSEd Maste #pragma mark ObjectFile
617f034231aSEd Maste 
618cfca06d7SDimitry Andric struct ObjectFileInstance : public PluginInstance<ObjectFileCreateInstance> {
ObjectFileInstanceObjectFileInstance619cfca06d7SDimitry Andric   ObjectFileInstance(
620c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
621c0981da4SDimitry Andric       CallbackType create_callback,
622cfca06d7SDimitry Andric       ObjectFileCreateMemoryInstance create_memory_callback,
623cfca06d7SDimitry Andric       ObjectFileGetModuleSpecifications get_module_specifications,
624145449b1SDimitry Andric       ObjectFileSaveCore save_core,
625145449b1SDimitry Andric       DebuggerInitializeCallback debugger_init_callback)
626145449b1SDimitry Andric       : PluginInstance<ObjectFileCreateInstance>(
627145449b1SDimitry Andric             name, description, create_callback, debugger_init_callback),
628cfca06d7SDimitry Andric         create_memory_callback(create_memory_callback),
629cfca06d7SDimitry Andric         get_module_specifications(get_module_specifications),
630cfca06d7SDimitry Andric         save_core(save_core) {}
631f034231aSEd Maste 
632f034231aSEd Maste   ObjectFileCreateMemoryInstance create_memory_callback;
633f034231aSEd Maste   ObjectFileGetModuleSpecifications get_module_specifications;
6340cac4ca3SEd Maste   ObjectFileSaveCore save_core;
635f034231aSEd Maste };
636cfca06d7SDimitry Andric typedef PluginInstances<ObjectFileInstance> ObjectFileInstances;
637f034231aSEd Maste 
GetObjectFileInstances()63814f1b3e8SDimitry Andric static ObjectFileInstances &GetObjectFileInstances() {
639f034231aSEd Maste   static ObjectFileInstances g_instances;
640f034231aSEd Maste   return g_instances;
641f034231aSEd Maste }
642f034231aSEd Maste 
IsRegisteredObjectFilePluginName(llvm::StringRef name)643ac9a064cSDimitry Andric bool PluginManager::IsRegisteredObjectFilePluginName(llvm::StringRef name) {
644ac9a064cSDimitry Andric   if (name.empty())
645ac9a064cSDimitry Andric     return false;
646ac9a064cSDimitry Andric 
647ac9a064cSDimitry Andric   const auto &instances = GetObjectFileInstances().GetInstances();
648ac9a064cSDimitry Andric   for (auto &instance : instances) {
649ac9a064cSDimitry Andric     if (instance.name == name)
650ac9a064cSDimitry Andric       return true;
651ac9a064cSDimitry Andric   }
652ac9a064cSDimitry Andric   return false;
653ac9a064cSDimitry Andric }
654ac9a064cSDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,ObjectFileCreateInstance create_callback,ObjectFileCreateMemoryInstance create_memory_callback,ObjectFileGetModuleSpecifications get_module_specifications,ObjectFileSaveCore save_core,DebuggerInitializeCallback debugger_init_callback)65514f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
656c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
657f034231aSEd Maste     ObjectFileCreateInstance create_callback,
658f034231aSEd Maste     ObjectFileCreateMemoryInstance create_memory_callback,
6590cac4ca3SEd Maste     ObjectFileGetModuleSpecifications get_module_specifications,
660145449b1SDimitry Andric     ObjectFileSaveCore save_core,
661145449b1SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
662cfca06d7SDimitry Andric   return GetObjectFileInstances().RegisterPlugin(
663cfca06d7SDimitry Andric       name, description, create_callback, create_memory_callback,
664145449b1SDimitry Andric       get_module_specifications, save_core, debugger_init_callback);
665f034231aSEd Maste }
666f034231aSEd Maste 
UnregisterPlugin(ObjectFileCreateInstance create_callback)66714f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
668cfca06d7SDimitry Andric   return GetObjectFileInstances().UnregisterPlugin(create_callback);
669f034231aSEd Maste }
670f034231aSEd Maste 
671f034231aSEd Maste ObjectFileCreateInstance
GetObjectFileCreateCallbackAtIndex(uint32_t idx)67214f1b3e8SDimitry Andric PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
673cfca06d7SDimitry Andric   return GetObjectFileInstances().GetCallbackAtIndex(idx);
674f034231aSEd Maste }
675f034231aSEd Maste 
676f034231aSEd Maste ObjectFileCreateMemoryInstance
GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx)67714f1b3e8SDimitry Andric PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) {
678cfca06d7SDimitry Andric   const auto &instances = GetObjectFileInstances().GetInstances();
679f034231aSEd Maste   if (idx < instances.size())
680f034231aSEd Maste     return instances[idx].create_memory_callback;
681f3fbd1c0SDimitry Andric   return nullptr;
682f034231aSEd Maste }
683f034231aSEd Maste 
684f034231aSEd Maste ObjectFileGetModuleSpecifications
GetObjectFileGetModuleSpecificationsCallbackAtIndex(uint32_t idx)68514f1b3e8SDimitry Andric PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
68614f1b3e8SDimitry Andric     uint32_t idx) {
687cfca06d7SDimitry Andric   const auto &instances = GetObjectFileInstances().GetInstances();
688f034231aSEd Maste   if (idx < instances.size())
689f034231aSEd Maste     return instances[idx].get_module_specifications;
690f3fbd1c0SDimitry Andric   return nullptr;
691f034231aSEd Maste }
692f034231aSEd Maste 
693f034231aSEd Maste ObjectFileCreateMemoryInstance
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name)69414f1b3e8SDimitry Andric PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
695c0981da4SDimitry Andric     llvm::StringRef name) {
696cfca06d7SDimitry Andric   const auto &instances = GetObjectFileInstances().GetInstances();
697cfca06d7SDimitry Andric   for (auto &instance : instances) {
698cfca06d7SDimitry Andric     if (instance.name == name)
699cfca06d7SDimitry Andric       return instance.create_memory_callback;
700f034231aSEd Maste   }
701f3fbd1c0SDimitry Andric   return nullptr;
702f034231aSEd Maste }
703f034231aSEd Maste 
SaveCore(const lldb::ProcessSP & process_sp,const lldb_private::SaveCoreOptions & options)704b76161e4SDimitry Andric Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
705ac9a064cSDimitry Andric                                const lldb_private::SaveCoreOptions &options) {
706ac9a064cSDimitry Andric   Status error;
707ac9a064cSDimitry Andric   if (!options.GetOutputFile()) {
708ac9a064cSDimitry Andric     error.SetErrorString("No output file specified");
709ac9a064cSDimitry Andric     return error;
710ac9a064cSDimitry Andric   }
711ac9a064cSDimitry Andric 
712ac9a064cSDimitry Andric   if (!process_sp) {
713ac9a064cSDimitry Andric     error.SetErrorString("Invalid process");
714ac9a064cSDimitry Andric     return error;
715ac9a064cSDimitry Andric   }
716ac9a064cSDimitry Andric 
717ac9a064cSDimitry Andric   if (!options.GetPluginName().has_value()) {
718c0981da4SDimitry Andric     // Try saving core directly from the process plugin first.
719ac9a064cSDimitry Andric     llvm::Expected<bool> ret =
720ac9a064cSDimitry Andric         process_sp->SaveCore(options.GetOutputFile()->GetPath());
721c0981da4SDimitry Andric     if (!ret)
722c0981da4SDimitry Andric       return Status(ret.takeError());
723c0981da4SDimitry Andric     if (ret.get())
724c0981da4SDimitry Andric       return Status();
725c0981da4SDimitry Andric   }
726c0981da4SDimitry Andric 
727c0981da4SDimitry Andric   // Fall back to object plugins.
728ac9a064cSDimitry Andric   const auto &plugin_name = options.GetPluginName().value_or("");
729cfca06d7SDimitry Andric   auto &instances = GetObjectFileInstances().GetInstances();
730cfca06d7SDimitry Andric   for (auto &instance : instances) {
731c0981da4SDimitry Andric     if (plugin_name.empty() || instance.name == plugin_name) {
732ac9a064cSDimitry Andric       if (instance.save_core && instance.save_core(process_sp, options, error))
7330cac4ca3SEd Maste         return error;
7340cac4ca3SEd Maste     }
735c0981da4SDimitry Andric   }
736ac9a064cSDimitry Andric 
737ac9a064cSDimitry Andric   // Check to see if any of the object file plugins tried and failed to save.
738ac9a064cSDimitry Andric   // If none ran, set the error message.
739ac9a064cSDimitry Andric   if (error.Success())
74014f1b3e8SDimitry Andric     error.SetErrorString(
74114f1b3e8SDimitry Andric         "no ObjectFile plugins were able to save a core for this process");
7420cac4ca3SEd Maste   return error;
7430cac4ca3SEd Maste }
744f034231aSEd Maste 
745f034231aSEd Maste #pragma mark ObjectContainer
746f034231aSEd Maste 
747cfca06d7SDimitry Andric struct ObjectContainerInstance
748cfca06d7SDimitry Andric     : public PluginInstance<ObjectContainerCreateInstance> {
ObjectContainerInstanceObjectContainerInstance749cfca06d7SDimitry Andric   ObjectContainerInstance(
750c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
751c0981da4SDimitry Andric       CallbackType create_callback,
752e3b55780SDimitry Andric       ObjectContainerCreateMemoryInstance create_memory_callback,
753cfca06d7SDimitry Andric       ObjectFileGetModuleSpecifications get_module_specifications)
754c0981da4SDimitry Andric       : PluginInstance<ObjectContainerCreateInstance>(name, description,
755c0981da4SDimitry Andric                                                       create_callback),
756e3b55780SDimitry Andric         create_memory_callback(create_memory_callback),
757cfca06d7SDimitry Andric         get_module_specifications(get_module_specifications) {}
758f034231aSEd Maste 
759e3b55780SDimitry Andric   ObjectContainerCreateMemoryInstance create_memory_callback;
760f034231aSEd Maste   ObjectFileGetModuleSpecifications get_module_specifications;
761f034231aSEd Maste };
762cfca06d7SDimitry Andric typedef PluginInstances<ObjectContainerInstance> ObjectContainerInstances;
763f034231aSEd Maste 
GetObjectContainerInstances()76414f1b3e8SDimitry Andric static ObjectContainerInstances &GetObjectContainerInstances() {
765f034231aSEd Maste   static ObjectContainerInstances g_instances;
766f034231aSEd Maste   return g_instances;
767f034231aSEd Maste }
768f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,ObjectContainerCreateInstance create_callback,ObjectFileGetModuleSpecifications get_module_specifications,ObjectContainerCreateMemoryInstance create_memory_callback)76914f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
770c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
771f034231aSEd Maste     ObjectContainerCreateInstance create_callback,
772e3b55780SDimitry Andric     ObjectFileGetModuleSpecifications get_module_specifications,
773e3b55780SDimitry Andric     ObjectContainerCreateMemoryInstance create_memory_callback) {
774cfca06d7SDimitry Andric   return GetObjectContainerInstances().RegisterPlugin(
775e3b55780SDimitry Andric       name, description, create_callback, create_memory_callback,
776e3b55780SDimitry Andric       get_module_specifications);
777f034231aSEd Maste }
778f034231aSEd Maste 
UnregisterPlugin(ObjectContainerCreateInstance create_callback)77914f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
78014f1b3e8SDimitry Andric     ObjectContainerCreateInstance create_callback) {
781cfca06d7SDimitry Andric   return GetObjectContainerInstances().UnregisterPlugin(create_callback);
782f034231aSEd Maste }
783f034231aSEd Maste 
784f034231aSEd Maste ObjectContainerCreateInstance
GetObjectContainerCreateCallbackAtIndex(uint32_t idx)78514f1b3e8SDimitry Andric PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
786cfca06d7SDimitry Andric   return GetObjectContainerInstances().GetCallbackAtIndex(idx);
787f034231aSEd Maste }
788f034231aSEd Maste 
789e3b55780SDimitry Andric ObjectContainerCreateMemoryInstance
GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx)790e3b55780SDimitry Andric PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx) {
791e3b55780SDimitry Andric   const auto &instances = GetObjectContainerInstances().GetInstances();
792e3b55780SDimitry Andric   if (idx < instances.size())
793e3b55780SDimitry Andric     return instances[idx].create_memory_callback;
794e3b55780SDimitry Andric   return nullptr;
795e3b55780SDimitry Andric }
796e3b55780SDimitry Andric 
797f034231aSEd Maste ObjectFileGetModuleSpecifications
GetObjectContainerGetModuleSpecificationsCallbackAtIndex(uint32_t idx)79814f1b3e8SDimitry Andric PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
79914f1b3e8SDimitry Andric     uint32_t idx) {
800cfca06d7SDimitry Andric   const auto &instances = GetObjectContainerInstances().GetInstances();
801f034231aSEd Maste   if (idx < instances.size())
802f034231aSEd Maste     return instances[idx].get_module_specifications;
803f3fbd1c0SDimitry Andric   return nullptr;
804f034231aSEd Maste }
805f034231aSEd Maste 
806f034231aSEd Maste #pragma mark Platform
807f034231aSEd Maste 
808cfca06d7SDimitry Andric typedef PluginInstance<PlatformCreateInstance> PlatformInstance;
809cfca06d7SDimitry Andric typedef PluginInstances<PlatformInstance> PlatformInstances;
810f034231aSEd Maste 
GetPlatformInstances()81114f1b3e8SDimitry Andric static PlatformInstances &GetPlatformInstances() {
812f034231aSEd Maste   static PlatformInstances g_platform_instances;
813f034231aSEd Maste   return g_platform_instances;
814f034231aSEd Maste }
815f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,PlatformCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)81614f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
817c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
818f034231aSEd Maste     PlatformCreateInstance create_callback,
81914f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
820cfca06d7SDimitry Andric   return GetPlatformInstances().RegisterPlugin(
821cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
822f034231aSEd Maste }
823f034231aSEd Maste 
UnregisterPlugin(PlatformCreateInstance create_callback)82414f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) {
825cfca06d7SDimitry Andric   return GetPlatformInstances().UnregisterPlugin(create_callback);
826cfca06d7SDimitry Andric }
827f034231aSEd Maste 
GetPlatformPluginNameAtIndex(uint32_t idx)828c0981da4SDimitry Andric llvm::StringRef PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) {
829cfca06d7SDimitry Andric   return GetPlatformInstances().GetNameAtIndex(idx);
830f034231aSEd Maste }
831cfca06d7SDimitry Andric 
832c0981da4SDimitry Andric llvm::StringRef
GetPlatformPluginDescriptionAtIndex(uint32_t idx)833c0981da4SDimitry Andric PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) {
834cfca06d7SDimitry Andric   return GetPlatformInstances().GetDescriptionAtIndex(idx);
835f034231aSEd Maste }
836f034231aSEd Maste 
837f034231aSEd Maste PlatformCreateInstance
GetPlatformCreateCallbackAtIndex(uint32_t idx)83814f1b3e8SDimitry Andric PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) {
839cfca06d7SDimitry Andric   return GetPlatformInstances().GetCallbackAtIndex(idx);
840f034231aSEd Maste }
841f034231aSEd Maste 
842f034231aSEd Maste PlatformCreateInstance
GetPlatformCreateCallbackForPluginName(llvm::StringRef name)843c0981da4SDimitry Andric PluginManager::GetPlatformCreateCallbackForPluginName(llvm::StringRef name) {
844cfca06d7SDimitry Andric   return GetPlatformInstances().GetCallbackForName(name);
845f034231aSEd Maste }
846f034231aSEd Maste 
AutoCompletePlatformName(llvm::StringRef name,CompletionRequest & request)847ead24645SDimitry Andric void PluginManager::AutoCompletePlatformName(llvm::StringRef name,
848ead24645SDimitry Andric                                              CompletionRequest &request) {
849cfca06d7SDimitry Andric   for (const auto &instance : GetPlatformInstances().GetInstances()) {
850312c0ed1SDimitry Andric     if (instance.name.starts_with(name))
851c0981da4SDimitry Andric       request.AddCompletion(instance.name);
852f034231aSEd Maste   }
853f034231aSEd Maste }
854f3fbd1c0SDimitry Andric 
855f034231aSEd Maste #pragma mark Process
856f034231aSEd Maste 
857cfca06d7SDimitry Andric typedef PluginInstance<ProcessCreateInstance> ProcessInstance;
858cfca06d7SDimitry Andric typedef PluginInstances<ProcessInstance> ProcessInstances;
859f034231aSEd Maste 
GetProcessInstances()86014f1b3e8SDimitry Andric static ProcessInstances &GetProcessInstances() {
861f034231aSEd Maste   static ProcessInstances g_instances;
862f034231aSEd Maste   return g_instances;
863f034231aSEd Maste }
864f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,ProcessCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)86514f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
866c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
867f034231aSEd Maste     ProcessCreateInstance create_callback,
86814f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
869cfca06d7SDimitry Andric   return GetProcessInstances().RegisterPlugin(
870cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
871f034231aSEd Maste }
872f034231aSEd Maste 
UnregisterPlugin(ProcessCreateInstance create_callback)87314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) {
874cfca06d7SDimitry Andric   return GetProcessInstances().UnregisterPlugin(create_callback);
875cfca06d7SDimitry Andric }
876f034231aSEd Maste 
GetProcessPluginNameAtIndex(uint32_t idx)877c0981da4SDimitry Andric llvm::StringRef PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) {
878cfca06d7SDimitry Andric   return GetProcessInstances().GetNameAtIndex(idx);
879f034231aSEd Maste }
880cfca06d7SDimitry Andric 
GetProcessPluginDescriptionAtIndex(uint32_t idx)881c0981da4SDimitry Andric llvm::StringRef PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) {
882cfca06d7SDimitry Andric   return GetProcessInstances().GetDescriptionAtIndex(idx);
883f034231aSEd Maste }
884f034231aSEd Maste 
885f034231aSEd Maste ProcessCreateInstance
GetProcessCreateCallbackAtIndex(uint32_t idx)88614f1b3e8SDimitry Andric PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) {
887cfca06d7SDimitry Andric   return GetProcessInstances().GetCallbackAtIndex(idx);
888f034231aSEd Maste }
889f034231aSEd Maste 
890f034231aSEd Maste ProcessCreateInstance
GetProcessCreateCallbackForPluginName(llvm::StringRef name)891c0981da4SDimitry Andric PluginManager::GetProcessCreateCallbackForPluginName(llvm::StringRef name) {
892cfca06d7SDimitry Andric   return GetProcessInstances().GetCallbackForName(name);
893cfca06d7SDimitry Andric }
894f034231aSEd Maste 
AutoCompleteProcessName(llvm::StringRef name,CompletionRequest & request)895cfca06d7SDimitry Andric void PluginManager::AutoCompleteProcessName(llvm::StringRef name,
896cfca06d7SDimitry Andric                                             CompletionRequest &request) {
897cfca06d7SDimitry Andric   for (const auto &instance : GetProcessInstances().GetInstances()) {
898312c0ed1SDimitry Andric     if (instance.name.starts_with(name))
899c0981da4SDimitry Andric       request.AddCompletion(instance.name, instance.description);
900f034231aSEd Maste   }
901f034231aSEd Maste }
902f034231aSEd Maste 
9037fa27ce4SDimitry Andric #pragma mark RegisterTypeBuilder
9047fa27ce4SDimitry Andric 
9057fa27ce4SDimitry Andric struct RegisterTypeBuilderInstance
9067fa27ce4SDimitry Andric     : public PluginInstance<RegisterTypeBuilderCreateInstance> {
RegisterTypeBuilderInstanceRegisterTypeBuilderInstance9077fa27ce4SDimitry Andric   RegisterTypeBuilderInstance(llvm::StringRef name, llvm::StringRef description,
9087fa27ce4SDimitry Andric                               CallbackType create_callback)
9097fa27ce4SDimitry Andric       : PluginInstance<RegisterTypeBuilderCreateInstance>(name, description,
9107fa27ce4SDimitry Andric                                                           create_callback) {}
9117fa27ce4SDimitry Andric };
9127fa27ce4SDimitry Andric 
9137fa27ce4SDimitry Andric typedef PluginInstances<RegisterTypeBuilderInstance>
9147fa27ce4SDimitry Andric     RegisterTypeBuilderInstances;
9157fa27ce4SDimitry Andric 
GetRegisterTypeBuilderInstances()9167fa27ce4SDimitry Andric static RegisterTypeBuilderInstances &GetRegisterTypeBuilderInstances() {
9177fa27ce4SDimitry Andric   static RegisterTypeBuilderInstances g_instances;
9187fa27ce4SDimitry Andric   return g_instances;
9197fa27ce4SDimitry Andric }
9207fa27ce4SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,RegisterTypeBuilderCreateInstance create_callback)9217fa27ce4SDimitry Andric bool PluginManager::RegisterPlugin(
9227fa27ce4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
9237fa27ce4SDimitry Andric     RegisterTypeBuilderCreateInstance create_callback) {
9247fa27ce4SDimitry Andric   return GetRegisterTypeBuilderInstances().RegisterPlugin(name, description,
9257fa27ce4SDimitry Andric                                                           create_callback);
9267fa27ce4SDimitry Andric }
9277fa27ce4SDimitry Andric 
UnregisterPlugin(RegisterTypeBuilderCreateInstance create_callback)9287fa27ce4SDimitry Andric bool PluginManager::UnregisterPlugin(
9297fa27ce4SDimitry Andric     RegisterTypeBuilderCreateInstance create_callback) {
9307fa27ce4SDimitry Andric   return GetRegisterTypeBuilderInstances().UnregisterPlugin(create_callback);
9317fa27ce4SDimitry Andric }
9327fa27ce4SDimitry Andric 
9337fa27ce4SDimitry Andric lldb::RegisterTypeBuilderSP
GetRegisterTypeBuilder(Target & target)9347fa27ce4SDimitry Andric PluginManager::GetRegisterTypeBuilder(Target &target) {
9357fa27ce4SDimitry Andric   const auto &instances = GetRegisterTypeBuilderInstances().GetInstances();
9367fa27ce4SDimitry Andric   // We assume that RegisterTypeBuilderClang is the only instance of this plugin
9377fa27ce4SDimitry Andric   // type and is always present.
9387fa27ce4SDimitry Andric   assert(instances.size());
9397fa27ce4SDimitry Andric   return instances[0].create_callback(target);
9407fa27ce4SDimitry Andric }
9417fa27ce4SDimitry Andric 
942e81d9d49SDimitry Andric #pragma mark ScriptInterpreter
943e81d9d49SDimitry Andric 
944cfca06d7SDimitry Andric struct ScriptInterpreterInstance
945cfca06d7SDimitry Andric     : public PluginInstance<ScriptInterpreterCreateInstance> {
ScriptInterpreterInstanceScriptInterpreterInstance946c0981da4SDimitry Andric   ScriptInterpreterInstance(llvm::StringRef name, llvm::StringRef description,
947cfca06d7SDimitry Andric                             CallbackType create_callback,
948cfca06d7SDimitry Andric                             lldb::ScriptLanguage language)
949c0981da4SDimitry Andric       : PluginInstance<ScriptInterpreterCreateInstance>(name, description,
950c0981da4SDimitry Andric                                                         create_callback),
951cfca06d7SDimitry Andric         language(language) {}
952e81d9d49SDimitry Andric 
953cfca06d7SDimitry Andric   lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
954e81d9d49SDimitry Andric };
955e81d9d49SDimitry Andric 
956cfca06d7SDimitry Andric typedef PluginInstances<ScriptInterpreterInstance> ScriptInterpreterInstances;
957e81d9d49SDimitry Andric 
GetScriptInterpreterInstances()95814f1b3e8SDimitry Andric static ScriptInterpreterInstances &GetScriptInterpreterInstances() {
959e81d9d49SDimitry Andric   static ScriptInterpreterInstances g_instances;
960e81d9d49SDimitry Andric   return g_instances;
961e81d9d49SDimitry Andric }
962e81d9d49SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,lldb::ScriptLanguage script_language,ScriptInterpreterCreateInstance create_callback)96314f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
964c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
96514f1b3e8SDimitry Andric     lldb::ScriptLanguage script_language,
96614f1b3e8SDimitry Andric     ScriptInterpreterCreateInstance create_callback) {
967cfca06d7SDimitry Andric   return GetScriptInterpreterInstances().RegisterPlugin(
968cfca06d7SDimitry Andric       name, description, create_callback, script_language);
969e81d9d49SDimitry Andric }
970e81d9d49SDimitry Andric 
UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)97114f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
97214f1b3e8SDimitry Andric     ScriptInterpreterCreateInstance create_callback) {
973cfca06d7SDimitry Andric   return GetScriptInterpreterInstances().UnregisterPlugin(create_callback);
974e81d9d49SDimitry Andric }
975e81d9d49SDimitry Andric 
976e81d9d49SDimitry Andric ScriptInterpreterCreateInstance
GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)97714f1b3e8SDimitry Andric PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
978cfca06d7SDimitry Andric   return GetScriptInterpreterInstances().GetCallbackAtIndex(idx);
979e81d9d49SDimitry Andric }
980e81d9d49SDimitry Andric 
9815f29bb8aSDimitry Andric lldb::ScriptInterpreterSP
GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,Debugger & debugger)9825f29bb8aSDimitry Andric PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang,
9835f29bb8aSDimitry Andric                                                Debugger &debugger) {
984cfca06d7SDimitry Andric   const auto &instances = GetScriptInterpreterInstances().GetInstances();
985e81d9d49SDimitry Andric   ScriptInterpreterCreateInstance none_instance = nullptr;
986cfca06d7SDimitry Andric   for (const auto &instance : instances) {
987cfca06d7SDimitry Andric     if (instance.language == lldb::eScriptLanguageNone)
988cfca06d7SDimitry Andric       none_instance = instance.create_callback;
989e81d9d49SDimitry Andric 
990cfca06d7SDimitry Andric     if (script_lang == instance.language)
991cfca06d7SDimitry Andric       return instance.create_callback(debugger);
992e81d9d49SDimitry Andric   }
993e81d9d49SDimitry Andric 
994e81d9d49SDimitry Andric   // If we didn't find one, return the ScriptInterpreter for the null language.
995e81d9d49SDimitry Andric   assert(none_instance != nullptr);
9965f29bb8aSDimitry Andric   return none_instance(debugger);
997e81d9d49SDimitry Andric }
998e81d9d49SDimitry Andric 
99914f1b3e8SDimitry Andric #pragma mark StructuredDataPlugin
100014f1b3e8SDimitry Andric 
1001cfca06d7SDimitry Andric struct StructuredDataPluginInstance
1002cfca06d7SDimitry Andric     : public PluginInstance<StructuredDataPluginCreateInstance> {
StructuredDataPluginInstanceStructuredDataPluginInstance1003cfca06d7SDimitry Andric   StructuredDataPluginInstance(
1004c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
1005c0981da4SDimitry Andric       CallbackType create_callback,
1006cfca06d7SDimitry Andric       DebuggerInitializeCallback debugger_init_callback,
1007cfca06d7SDimitry Andric       StructuredDataFilterLaunchInfo filter_callback)
1008cfca06d7SDimitry Andric       : PluginInstance<StructuredDataPluginCreateInstance>(
1009c0981da4SDimitry Andric             name, description, create_callback, debugger_init_callback),
1010cfca06d7SDimitry Andric         filter_callback(filter_callback) {}
101114f1b3e8SDimitry Andric 
1012cfca06d7SDimitry Andric   StructuredDataFilterLaunchInfo filter_callback = nullptr;
101314f1b3e8SDimitry Andric };
101414f1b3e8SDimitry Andric 
1015cfca06d7SDimitry Andric typedef PluginInstances<StructuredDataPluginInstance>
1016cfca06d7SDimitry Andric     StructuredDataPluginInstances;
101714f1b3e8SDimitry Andric 
GetStructuredDataPluginInstances()101814f1b3e8SDimitry Andric static StructuredDataPluginInstances &GetStructuredDataPluginInstances() {
101914f1b3e8SDimitry Andric   static StructuredDataPluginInstances g_instances;
102014f1b3e8SDimitry Andric   return g_instances;
102114f1b3e8SDimitry Andric }
102214f1b3e8SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,StructuredDataPluginCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback,StructuredDataFilterLaunchInfo filter_callback)102314f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
1024c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
102514f1b3e8SDimitry Andric     StructuredDataPluginCreateInstance create_callback,
102614f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback,
102714f1b3e8SDimitry Andric     StructuredDataFilterLaunchInfo filter_callback) {
1028cfca06d7SDimitry Andric   return GetStructuredDataPluginInstances().RegisterPlugin(
1029cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback,
1030cfca06d7SDimitry Andric       filter_callback);
103114f1b3e8SDimitry Andric }
103214f1b3e8SDimitry Andric 
UnregisterPlugin(StructuredDataPluginCreateInstance create_callback)103314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
103414f1b3e8SDimitry Andric     StructuredDataPluginCreateInstance create_callback) {
1035cfca06d7SDimitry Andric   return GetStructuredDataPluginInstances().UnregisterPlugin(create_callback);
103614f1b3e8SDimitry Andric }
103714f1b3e8SDimitry Andric 
103814f1b3e8SDimitry Andric StructuredDataPluginCreateInstance
GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx)103914f1b3e8SDimitry Andric PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
1040cfca06d7SDimitry Andric   return GetStructuredDataPluginInstances().GetCallbackAtIndex(idx);
104114f1b3e8SDimitry Andric }
104214f1b3e8SDimitry Andric 
104314f1b3e8SDimitry Andric StructuredDataFilterLaunchInfo
GetStructuredDataFilterCallbackAtIndex(uint32_t idx,bool & iteration_complete)104414f1b3e8SDimitry Andric PluginManager::GetStructuredDataFilterCallbackAtIndex(
104514f1b3e8SDimitry Andric     uint32_t idx, bool &iteration_complete) {
1046cfca06d7SDimitry Andric   const auto &instances = GetStructuredDataPluginInstances().GetInstances();
104714f1b3e8SDimitry Andric   if (idx < instances.size()) {
104814f1b3e8SDimitry Andric     iteration_complete = false;
104914f1b3e8SDimitry Andric     return instances[idx].filter_callback;
105014f1b3e8SDimitry Andric   } else {
105114f1b3e8SDimitry Andric     iteration_complete = true;
105214f1b3e8SDimitry Andric   }
105314f1b3e8SDimitry Andric   return nullptr;
105414f1b3e8SDimitry Andric }
105514f1b3e8SDimitry Andric 
1056f034231aSEd Maste #pragma mark SymbolFile
1057f034231aSEd Maste 
1058cfca06d7SDimitry Andric typedef PluginInstance<SymbolFileCreateInstance> SymbolFileInstance;
1059cfca06d7SDimitry Andric typedef PluginInstances<SymbolFileInstance> SymbolFileInstances;
1060f034231aSEd Maste 
GetSymbolFileInstances()106114f1b3e8SDimitry Andric static SymbolFileInstances &GetSymbolFileInstances() {
1062f034231aSEd Maste   static SymbolFileInstances g_instances;
1063f034231aSEd Maste   return g_instances;
1064f034231aSEd Maste }
1065f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,SymbolFileCreateInstance create_callback,DebuggerInitializeCallback debugger_init_callback)106614f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
1067c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1068e81d9d49SDimitry Andric     SymbolFileCreateInstance create_callback,
106914f1b3e8SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
1070cfca06d7SDimitry Andric   return GetSymbolFileInstances().RegisterPlugin(
1071cfca06d7SDimitry Andric       name, description, create_callback, debugger_init_callback);
1072f034231aSEd Maste }
1073f034231aSEd Maste 
UnregisterPlugin(SymbolFileCreateInstance create_callback)107414f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) {
1075cfca06d7SDimitry Andric   return GetSymbolFileInstances().UnregisterPlugin(create_callback);
1076f034231aSEd Maste }
1077f034231aSEd Maste 
1078f034231aSEd Maste SymbolFileCreateInstance
GetSymbolFileCreateCallbackAtIndex(uint32_t idx)107914f1b3e8SDimitry Andric PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) {
1080cfca06d7SDimitry Andric   return GetSymbolFileInstances().GetCallbackAtIndex(idx);
1081f034231aSEd Maste }
1082f034231aSEd Maste 
1083f034231aSEd Maste #pragma mark SymbolVendor
1084f034231aSEd Maste 
1085cfca06d7SDimitry Andric typedef PluginInstance<SymbolVendorCreateInstance> SymbolVendorInstance;
1086cfca06d7SDimitry Andric typedef PluginInstances<SymbolVendorInstance> SymbolVendorInstances;
1087f034231aSEd Maste 
GetSymbolVendorInstances()108814f1b3e8SDimitry Andric static SymbolVendorInstances &GetSymbolVendorInstances() {
1089f034231aSEd Maste   static SymbolVendorInstances g_instances;
1090f034231aSEd Maste   return g_instances;
1091f034231aSEd Maste }
1092f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,SymbolVendorCreateInstance create_callback)1093c0981da4SDimitry Andric bool PluginManager::RegisterPlugin(llvm::StringRef name,
1094c0981da4SDimitry Andric                                    llvm::StringRef description,
109514f1b3e8SDimitry Andric                                    SymbolVendorCreateInstance create_callback) {
1096cfca06d7SDimitry Andric   return GetSymbolVendorInstances().RegisterPlugin(name, description,
1097cfca06d7SDimitry Andric                                                    create_callback);
1098f034231aSEd Maste }
1099f034231aSEd Maste 
UnregisterPlugin(SymbolVendorCreateInstance create_callback)110014f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
110114f1b3e8SDimitry Andric     SymbolVendorCreateInstance create_callback) {
1102cfca06d7SDimitry Andric   return GetSymbolVendorInstances().UnregisterPlugin(create_callback);
1103f034231aSEd Maste }
1104f034231aSEd Maste 
1105f034231aSEd Maste SymbolVendorCreateInstance
GetSymbolVendorCreateCallbackAtIndex(uint32_t idx)110614f1b3e8SDimitry Andric PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
1107cfca06d7SDimitry Andric   return GetSymbolVendorInstances().GetCallbackAtIndex(idx);
1108f034231aSEd Maste }
1109f034231aSEd Maste 
1110b1c73532SDimitry Andric #pragma mark SymbolLocator
1111b1c73532SDimitry Andric 
1112b1c73532SDimitry Andric struct SymbolLocatorInstance
1113b1c73532SDimitry Andric     : public PluginInstance<SymbolLocatorCreateInstance> {
SymbolLocatorInstanceSymbolLocatorInstance1114b1c73532SDimitry Andric   SymbolLocatorInstance(
1115b1c73532SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
1116b1c73532SDimitry Andric       CallbackType create_callback,
1117b1c73532SDimitry Andric       SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
1118b1c73532SDimitry Andric       SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1119b1c73532SDimitry Andric       SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
1120b1c73532SDimitry Andric       SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1121b1c73532SDimitry Andric       DebuggerInitializeCallback debugger_init_callback)
1122b1c73532SDimitry Andric       : PluginInstance<SymbolLocatorCreateInstance>(
1123b1c73532SDimitry Andric             name, description, create_callback, debugger_init_callback),
1124b1c73532SDimitry Andric         locate_executable_object_file(locate_executable_object_file),
1125b1c73532SDimitry Andric         locate_executable_symbol_file(locate_executable_symbol_file),
1126b1c73532SDimitry Andric         download_object_symbol_file(download_object_symbol_file),
1127b1c73532SDimitry Andric         find_symbol_file_in_bundle(find_symbol_file_in_bundle) {}
1128b1c73532SDimitry Andric 
1129b1c73532SDimitry Andric   SymbolLocatorLocateExecutableObjectFile locate_executable_object_file;
1130b1c73532SDimitry Andric   SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file;
1131b1c73532SDimitry Andric   SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file;
1132b1c73532SDimitry Andric   SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle;
1133b1c73532SDimitry Andric };
1134b1c73532SDimitry Andric typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances;
1135b1c73532SDimitry Andric 
GetSymbolLocatorInstances()1136b1c73532SDimitry Andric static SymbolLocatorInstances &GetSymbolLocatorInstances() {
1137b1c73532SDimitry Andric   static SymbolLocatorInstances g_instances;
1138b1c73532SDimitry Andric   return g_instances;
1139b1c73532SDimitry Andric }
1140b1c73532SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,SymbolLocatorCreateInstance create_callback,SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,DebuggerInitializeCallback debugger_init_callback)1141b1c73532SDimitry Andric bool PluginManager::RegisterPlugin(
1142b1c73532SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1143b1c73532SDimitry Andric     SymbolLocatorCreateInstance create_callback,
1144b1c73532SDimitry Andric     SymbolLocatorLocateExecutableObjectFile locate_executable_object_file,
1145b1c73532SDimitry Andric     SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file,
1146b1c73532SDimitry Andric     SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file,
1147b1c73532SDimitry Andric     SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle,
1148b1c73532SDimitry Andric     DebuggerInitializeCallback debugger_init_callback) {
1149b1c73532SDimitry Andric   return GetSymbolLocatorInstances().RegisterPlugin(
1150b1c73532SDimitry Andric       name, description, create_callback, locate_executable_object_file,
1151b1c73532SDimitry Andric       locate_executable_symbol_file, download_object_symbol_file,
1152b1c73532SDimitry Andric       find_symbol_file_in_bundle, debugger_init_callback);
1153b1c73532SDimitry Andric }
1154b1c73532SDimitry Andric 
UnregisterPlugin(SymbolLocatorCreateInstance create_callback)1155b1c73532SDimitry Andric bool PluginManager::UnregisterPlugin(
1156b1c73532SDimitry Andric     SymbolLocatorCreateInstance create_callback) {
1157b1c73532SDimitry Andric   return GetSymbolLocatorInstances().UnregisterPlugin(create_callback);
1158b1c73532SDimitry Andric }
1159b1c73532SDimitry Andric 
1160b1c73532SDimitry Andric SymbolLocatorCreateInstance
GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx)1161b1c73532SDimitry Andric PluginManager::GetSymbolLocatorCreateCallbackAtIndex(uint32_t idx) {
1162b1c73532SDimitry Andric   return GetSymbolLocatorInstances().GetCallbackAtIndex(idx);
1163b1c73532SDimitry Andric }
1164b1c73532SDimitry Andric 
1165b1c73532SDimitry Andric ModuleSpec
LocateExecutableObjectFile(const ModuleSpec & module_spec)1166b1c73532SDimitry Andric PluginManager::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
1167b1c73532SDimitry Andric   auto &instances = GetSymbolLocatorInstances().GetInstances();
1168b1c73532SDimitry Andric   for (auto &instance : instances) {
1169b1c73532SDimitry Andric     if (instance.locate_executable_object_file) {
1170b1c73532SDimitry Andric       std::optional<ModuleSpec> result =
1171b1c73532SDimitry Andric           instance.locate_executable_object_file(module_spec);
1172b1c73532SDimitry Andric       if (result)
1173b1c73532SDimitry Andric         return *result;
1174b1c73532SDimitry Andric     }
1175b1c73532SDimitry Andric   }
1176b1c73532SDimitry Andric   return {};
1177b1c73532SDimitry Andric }
1178b1c73532SDimitry Andric 
LocateExecutableSymbolFile(const ModuleSpec & module_spec,const FileSpecList & default_search_paths)1179b1c73532SDimitry Andric FileSpec PluginManager::LocateExecutableSymbolFile(
1180b1c73532SDimitry Andric     const ModuleSpec &module_spec, const FileSpecList &default_search_paths) {
1181b1c73532SDimitry Andric   auto &instances = GetSymbolLocatorInstances().GetInstances();
1182b1c73532SDimitry Andric   for (auto &instance : instances) {
1183b1c73532SDimitry Andric     if (instance.locate_executable_symbol_file) {
1184b1c73532SDimitry Andric       std::optional<FileSpec> result = instance.locate_executable_symbol_file(
1185b1c73532SDimitry Andric           module_spec, default_search_paths);
1186b1c73532SDimitry Andric       if (result)
1187b1c73532SDimitry Andric         return *result;
1188b1c73532SDimitry Andric     }
1189b1c73532SDimitry Andric   }
1190b1c73532SDimitry Andric   return {};
1191b1c73532SDimitry Andric }
1192b1c73532SDimitry Andric 
DownloadObjectAndSymbolFile(ModuleSpec & module_spec,Status & error,bool force_lookup,bool copy_executable)1193b1c73532SDimitry Andric bool PluginManager::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
1194b1c73532SDimitry Andric                                                 Status &error,
1195b1c73532SDimitry Andric                                                 bool force_lookup,
1196b1c73532SDimitry Andric                                                 bool copy_executable) {
1197b1c73532SDimitry Andric   auto &instances = GetSymbolLocatorInstances().GetInstances();
1198b1c73532SDimitry Andric   for (auto &instance : instances) {
1199b1c73532SDimitry Andric     if (instance.download_object_symbol_file) {
1200b1c73532SDimitry Andric       if (instance.download_object_symbol_file(module_spec, error, force_lookup,
1201b1c73532SDimitry Andric                                                copy_executable))
1202b1c73532SDimitry Andric         return true;
1203b1c73532SDimitry Andric     }
1204b1c73532SDimitry Andric   }
1205b1c73532SDimitry Andric   return false;
1206b1c73532SDimitry Andric }
1207b1c73532SDimitry Andric 
FindSymbolFileInBundle(const FileSpec & symfile_bundle,const UUID * uuid,const ArchSpec * arch)1208b1c73532SDimitry Andric FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
1209b1c73532SDimitry Andric                                                const UUID *uuid,
1210b1c73532SDimitry Andric                                                const ArchSpec *arch) {
1211b1c73532SDimitry Andric   auto &instances = GetSymbolLocatorInstances().GetInstances();
1212b1c73532SDimitry Andric   for (auto &instance : instances) {
1213b1c73532SDimitry Andric     if (instance.find_symbol_file_in_bundle) {
1214b1c73532SDimitry Andric       std::optional<FileSpec> result =
1215b1c73532SDimitry Andric           instance.find_symbol_file_in_bundle(symfile_bundle, uuid, arch);
1216b1c73532SDimitry Andric       if (result)
1217b1c73532SDimitry Andric         return *result;
1218b1c73532SDimitry Andric     }
1219b1c73532SDimitry Andric   }
1220b1c73532SDimitry Andric   return {};
1221b1c73532SDimitry Andric }
1222b1c73532SDimitry Andric 
1223b60736ecSDimitry Andric #pragma mark Trace
1224b60736ecSDimitry Andric 
1225344a3780SDimitry Andric struct TraceInstance
1226145449b1SDimitry Andric     : public PluginInstance<TraceCreateInstanceFromBundle> {
TraceInstanceTraceInstance1227344a3780SDimitry Andric   TraceInstance(
1228c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
1229145449b1SDimitry Andric       CallbackType create_callback_from_bundle,
1230344a3780SDimitry Andric       TraceCreateInstanceForLiveProcess create_callback_for_live_process,
1231e3b55780SDimitry Andric       llvm::StringRef schema, DebuggerInitializeCallback debugger_init_callback)
1232145449b1SDimitry Andric       : PluginInstance<TraceCreateInstanceFromBundle>(
1233e3b55780SDimitry Andric             name, description, create_callback_from_bundle,
1234e3b55780SDimitry Andric             debugger_init_callback),
1235344a3780SDimitry Andric         schema(schema),
1236344a3780SDimitry Andric         create_callback_for_live_process(create_callback_for_live_process) {}
1237b60736ecSDimitry Andric 
1238b60736ecSDimitry Andric   llvm::StringRef schema;
1239344a3780SDimitry Andric   TraceCreateInstanceForLiveProcess create_callback_for_live_process;
1240b60736ecSDimitry Andric };
1241b60736ecSDimitry Andric 
1242b60736ecSDimitry Andric typedef PluginInstances<TraceInstance> TraceInstances;
1243b60736ecSDimitry Andric 
GetTracePluginInstances()1244b60736ecSDimitry Andric static TraceInstances &GetTracePluginInstances() {
1245b60736ecSDimitry Andric   static TraceInstances g_instances;
1246b60736ecSDimitry Andric   return g_instances;
1247b60736ecSDimitry Andric }
1248b60736ecSDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,TraceCreateInstanceFromBundle create_callback_from_bundle,TraceCreateInstanceForLiveProcess create_callback_for_live_process,llvm::StringRef schema,DebuggerInitializeCallback debugger_init_callback)1249344a3780SDimitry Andric bool PluginManager::RegisterPlugin(
1250c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1251145449b1SDimitry Andric     TraceCreateInstanceFromBundle create_callback_from_bundle,
1252344a3780SDimitry Andric     TraceCreateInstanceForLiveProcess create_callback_for_live_process,
1253e3b55780SDimitry Andric     llvm::StringRef schema, DebuggerInitializeCallback debugger_init_callback) {
1254b60736ecSDimitry Andric   return GetTracePluginInstances().RegisterPlugin(
1255145449b1SDimitry Andric       name, description, create_callback_from_bundle,
1256e3b55780SDimitry Andric       create_callback_for_live_process, schema, debugger_init_callback);
1257b60736ecSDimitry Andric }
1258b60736ecSDimitry Andric 
UnregisterPlugin(TraceCreateInstanceFromBundle create_callback_from_bundle)1259344a3780SDimitry Andric bool PluginManager::UnregisterPlugin(
1260145449b1SDimitry Andric     TraceCreateInstanceFromBundle create_callback_from_bundle) {
1261344a3780SDimitry Andric   return GetTracePluginInstances().UnregisterPlugin(
1262145449b1SDimitry Andric       create_callback_from_bundle);
1263b60736ecSDimitry Andric }
1264b60736ecSDimitry Andric 
1265145449b1SDimitry Andric TraceCreateInstanceFromBundle
GetTraceCreateCallback(llvm::StringRef plugin_name)1266c0981da4SDimitry Andric PluginManager::GetTraceCreateCallback(llvm::StringRef plugin_name) {
1267b60736ecSDimitry Andric   return GetTracePluginInstances().GetCallbackForName(plugin_name);
1268b60736ecSDimitry Andric }
1269b60736ecSDimitry Andric 
1270344a3780SDimitry Andric TraceCreateInstanceForLiveProcess
GetTraceCreateCallbackForLiveProcess(llvm::StringRef plugin_name)1271c0981da4SDimitry Andric PluginManager::GetTraceCreateCallbackForLiveProcess(llvm::StringRef plugin_name) {
1272344a3780SDimitry Andric   for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1273344a3780SDimitry Andric     if (instance.name == plugin_name)
1274344a3780SDimitry Andric       return instance.create_callback_for_live_process;
1275344a3780SDimitry Andric   return nullptr;
1276344a3780SDimitry Andric }
1277344a3780SDimitry Andric 
GetTraceSchema(llvm::StringRef plugin_name)1278c0981da4SDimitry Andric llvm::StringRef PluginManager::GetTraceSchema(llvm::StringRef plugin_name) {
1279b60736ecSDimitry Andric   for (const TraceInstance &instance : GetTracePluginInstances().GetInstances())
1280b60736ecSDimitry Andric     if (instance.name == plugin_name)
1281b60736ecSDimitry Andric       return instance.schema;
1282b60736ecSDimitry Andric   return llvm::StringRef();
1283b60736ecSDimitry Andric }
1284b60736ecSDimitry Andric 
GetTraceSchema(size_t index)1285b60736ecSDimitry Andric llvm::StringRef PluginManager::GetTraceSchema(size_t index) {
1286b60736ecSDimitry Andric   if (TraceInstance *instance =
1287b60736ecSDimitry Andric           GetTracePluginInstances().GetInstanceAtIndex(index))
1288b60736ecSDimitry Andric     return instance->schema;
1289b60736ecSDimitry Andric   return llvm::StringRef();
1290b60736ecSDimitry Andric }
1291b60736ecSDimitry Andric 
1292344a3780SDimitry Andric #pragma mark TraceExporter
1293344a3780SDimitry Andric 
1294344a3780SDimitry Andric struct TraceExporterInstance
1295344a3780SDimitry Andric     : public PluginInstance<TraceExporterCreateInstance> {
TraceExporterInstanceTraceExporterInstance1296344a3780SDimitry Andric   TraceExporterInstance(
1297c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
1298344a3780SDimitry Andric       TraceExporterCreateInstance create_instance,
1299344a3780SDimitry Andric       ThreadTraceExportCommandCreator create_thread_trace_export_command)
1300c0981da4SDimitry Andric       : PluginInstance<TraceExporterCreateInstance>(name, description,
1301c0981da4SDimitry Andric                                                     create_instance),
1302344a3780SDimitry Andric         create_thread_trace_export_command(create_thread_trace_export_command) {
1303344a3780SDimitry Andric   }
1304344a3780SDimitry Andric 
1305344a3780SDimitry Andric   ThreadTraceExportCommandCreator create_thread_trace_export_command;
1306344a3780SDimitry Andric };
1307344a3780SDimitry Andric 
1308344a3780SDimitry Andric typedef PluginInstances<TraceExporterInstance> TraceExporterInstances;
1309344a3780SDimitry Andric 
GetTraceExporterInstances()1310344a3780SDimitry Andric static TraceExporterInstances &GetTraceExporterInstances() {
1311344a3780SDimitry Andric   static TraceExporterInstances g_instances;
1312344a3780SDimitry Andric   return g_instances;
1313344a3780SDimitry Andric }
1314344a3780SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,TraceExporterCreateInstance create_callback,ThreadTraceExportCommandCreator create_thread_trace_export_command)1315344a3780SDimitry Andric bool PluginManager::RegisterPlugin(
1316c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1317344a3780SDimitry Andric     TraceExporterCreateInstance create_callback,
1318344a3780SDimitry Andric     ThreadTraceExportCommandCreator create_thread_trace_export_command) {
1319344a3780SDimitry Andric   return GetTraceExporterInstances().RegisterPlugin(
1320344a3780SDimitry Andric       name, description, create_callback, create_thread_trace_export_command);
1321344a3780SDimitry Andric }
1322344a3780SDimitry Andric 
1323344a3780SDimitry Andric TraceExporterCreateInstance
GetTraceExporterCreateCallback(llvm::StringRef plugin_name)1324c0981da4SDimitry Andric PluginManager::GetTraceExporterCreateCallback(llvm::StringRef plugin_name) {
1325344a3780SDimitry Andric   return GetTraceExporterInstances().GetCallbackForName(plugin_name);
1326344a3780SDimitry Andric }
1327344a3780SDimitry Andric 
UnregisterPlugin(TraceExporterCreateInstance create_callback)1328344a3780SDimitry Andric bool PluginManager::UnregisterPlugin(
1329344a3780SDimitry Andric     TraceExporterCreateInstance create_callback) {
1330344a3780SDimitry Andric   return GetTraceExporterInstances().UnregisterPlugin(create_callback);
1331344a3780SDimitry Andric }
1332344a3780SDimitry Andric 
1333344a3780SDimitry Andric ThreadTraceExportCommandCreator
GetThreadTraceExportCommandCreatorAtIndex(uint32_t index)1334344a3780SDimitry Andric PluginManager::GetThreadTraceExportCommandCreatorAtIndex(uint32_t index) {
1335344a3780SDimitry Andric   if (TraceExporterInstance *instance =
1336344a3780SDimitry Andric           GetTraceExporterInstances().GetInstanceAtIndex(index))
1337344a3780SDimitry Andric     return instance->create_thread_trace_export_command;
1338344a3780SDimitry Andric   return nullptr;
1339344a3780SDimitry Andric }
1340344a3780SDimitry Andric 
1341c0981da4SDimitry Andric llvm::StringRef
GetTraceExporterPluginNameAtIndex(uint32_t index)1342c0981da4SDimitry Andric PluginManager::GetTraceExporterPluginNameAtIndex(uint32_t index) {
1343344a3780SDimitry Andric   return GetTraceExporterInstances().GetNameAtIndex(index);
1344344a3780SDimitry Andric }
1345344a3780SDimitry Andric 
1346f034231aSEd Maste #pragma mark UnwindAssembly
1347f034231aSEd Maste 
1348cfca06d7SDimitry Andric typedef PluginInstance<UnwindAssemblyCreateInstance> UnwindAssemblyInstance;
1349cfca06d7SDimitry Andric typedef PluginInstances<UnwindAssemblyInstance> UnwindAssemblyInstances;
1350f034231aSEd Maste 
GetUnwindAssemblyInstances()135114f1b3e8SDimitry Andric static UnwindAssemblyInstances &GetUnwindAssemblyInstances() {
1352f034231aSEd Maste   static UnwindAssemblyInstances g_instances;
1353f034231aSEd Maste   return g_instances;
1354f034231aSEd Maste }
1355f034231aSEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,UnwindAssemblyCreateInstance create_callback)135614f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
1357c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
135814f1b3e8SDimitry Andric     UnwindAssemblyCreateInstance create_callback) {
1359cfca06d7SDimitry Andric   return GetUnwindAssemblyInstances().RegisterPlugin(name, description,
1360cfca06d7SDimitry Andric                                                      create_callback);
1361f034231aSEd Maste }
1362f034231aSEd Maste 
UnregisterPlugin(UnwindAssemblyCreateInstance create_callback)136314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
136414f1b3e8SDimitry Andric     UnwindAssemblyCreateInstance create_callback) {
1365cfca06d7SDimitry Andric   return GetUnwindAssemblyInstances().UnregisterPlugin(create_callback);
1366f034231aSEd Maste }
1367f034231aSEd Maste 
1368f034231aSEd Maste UnwindAssemblyCreateInstance
GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx)136914f1b3e8SDimitry Andric PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) {
1370cfca06d7SDimitry Andric   return GetUnwindAssemblyInstances().GetCallbackAtIndex(idx);
1371f034231aSEd Maste }
1372f034231aSEd Maste 
1373205afe67SEd Maste #pragma mark MemoryHistory
1374205afe67SEd Maste 
1375cfca06d7SDimitry Andric typedef PluginInstance<MemoryHistoryCreateInstance> MemoryHistoryInstance;
1376cfca06d7SDimitry Andric typedef PluginInstances<MemoryHistoryInstance> MemoryHistoryInstances;
1377205afe67SEd Maste 
GetMemoryHistoryInstances()137814f1b3e8SDimitry Andric static MemoryHistoryInstances &GetMemoryHistoryInstances() {
1379205afe67SEd Maste   static MemoryHistoryInstances g_instances;
1380205afe67SEd Maste   return g_instances;
1381205afe67SEd Maste }
1382205afe67SEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,MemoryHistoryCreateInstance create_callback)138314f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
1384c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
138514f1b3e8SDimitry Andric     MemoryHistoryCreateInstance create_callback) {
1386cfca06d7SDimitry Andric   return GetMemoryHistoryInstances().RegisterPlugin(name, description,
1387cfca06d7SDimitry Andric                                                     create_callback);
1388205afe67SEd Maste }
1389205afe67SEd Maste 
UnregisterPlugin(MemoryHistoryCreateInstance create_callback)139014f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
139114f1b3e8SDimitry Andric     MemoryHistoryCreateInstance create_callback) {
1392cfca06d7SDimitry Andric   return GetMemoryHistoryInstances().UnregisterPlugin(create_callback);
1393205afe67SEd Maste }
1394205afe67SEd Maste 
1395205afe67SEd Maste MemoryHistoryCreateInstance
GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx)139614f1b3e8SDimitry Andric PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) {
1397cfca06d7SDimitry Andric   return GetMemoryHistoryInstances().GetCallbackAtIndex(idx);
1398205afe67SEd Maste }
1399205afe67SEd Maste 
1400205afe67SEd Maste #pragma mark InstrumentationRuntime
1401205afe67SEd Maste 
1402cfca06d7SDimitry Andric struct InstrumentationRuntimeInstance
1403cfca06d7SDimitry Andric     : public PluginInstance<InstrumentationRuntimeCreateInstance> {
InstrumentationRuntimeInstanceInstrumentationRuntimeInstance1404cfca06d7SDimitry Andric   InstrumentationRuntimeInstance(
1405c0981da4SDimitry Andric       llvm::StringRef name, llvm::StringRef description,
1406c0981da4SDimitry Andric       CallbackType create_callback,
1407cfca06d7SDimitry Andric       InstrumentationRuntimeGetType get_type_callback)
1408c0981da4SDimitry Andric       : PluginInstance<InstrumentationRuntimeCreateInstance>(name, description,
1409c0981da4SDimitry Andric                                                              create_callback),
1410cfca06d7SDimitry Andric         get_type_callback(get_type_callback) {}
1411205afe67SEd Maste 
1412cfca06d7SDimitry Andric   InstrumentationRuntimeGetType get_type_callback = nullptr;
1413205afe67SEd Maste };
1414205afe67SEd Maste 
1415cfca06d7SDimitry Andric typedef PluginInstances<InstrumentationRuntimeInstance>
141614f1b3e8SDimitry Andric     InstrumentationRuntimeInstances;
1417205afe67SEd Maste 
GetInstrumentationRuntimeInstances()141814f1b3e8SDimitry Andric static InstrumentationRuntimeInstances &GetInstrumentationRuntimeInstances() {
1419205afe67SEd Maste   static InstrumentationRuntimeInstances g_instances;
1420205afe67SEd Maste   return g_instances;
1421205afe67SEd Maste }
1422205afe67SEd Maste 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,InstrumentationRuntimeCreateInstance create_callback,InstrumentationRuntimeGetType get_type_callback)142314f1b3e8SDimitry Andric bool PluginManager::RegisterPlugin(
1424c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1425205afe67SEd Maste     InstrumentationRuntimeCreateInstance create_callback,
142614f1b3e8SDimitry Andric     InstrumentationRuntimeGetType get_type_callback) {
1427cfca06d7SDimitry Andric   return GetInstrumentationRuntimeInstances().RegisterPlugin(
1428cfca06d7SDimitry Andric       name, description, create_callback, get_type_callback);
1429205afe67SEd Maste }
1430205afe67SEd Maste 
UnregisterPlugin(InstrumentationRuntimeCreateInstance create_callback)143114f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(
143214f1b3e8SDimitry Andric     InstrumentationRuntimeCreateInstance create_callback) {
1433cfca06d7SDimitry Andric   return GetInstrumentationRuntimeInstances().UnregisterPlugin(create_callback);
1434205afe67SEd Maste }
1435205afe67SEd Maste 
1436205afe67SEd Maste InstrumentationRuntimeGetType
GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx)143714f1b3e8SDimitry Andric PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
1438cfca06d7SDimitry Andric   const auto &instances = GetInstrumentationRuntimeInstances().GetInstances();
1439205afe67SEd Maste   if (idx < instances.size())
1440205afe67SEd Maste     return instances[idx].get_type_callback;
1441f3fbd1c0SDimitry Andric   return nullptr;
1442205afe67SEd Maste }
1443205afe67SEd Maste 
1444205afe67SEd Maste InstrumentationRuntimeCreateInstance
GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx)144514f1b3e8SDimitry Andric PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) {
1446cfca06d7SDimitry Andric   return GetInstrumentationRuntimeInstances().GetCallbackAtIndex(idx);
1447205afe67SEd Maste }
1448205afe67SEd Maste 
1449e81d9d49SDimitry Andric #pragma mark TypeSystem
1450e81d9d49SDimitry Andric 
1451cfca06d7SDimitry Andric struct TypeSystemInstance : public PluginInstance<TypeSystemCreateInstance> {
TypeSystemInstanceTypeSystemInstance1452c0981da4SDimitry Andric   TypeSystemInstance(llvm::StringRef name, llvm::StringRef description,
1453cfca06d7SDimitry Andric                      CallbackType create_callback,
1454cfca06d7SDimitry Andric                      LanguageSet supported_languages_for_types,
1455cfca06d7SDimitry Andric                      LanguageSet supported_languages_for_expressions)
1456c0981da4SDimitry Andric       : PluginInstance<TypeSystemCreateInstance>(name, description,
1457cfca06d7SDimitry Andric                                                  create_callback),
1458cfca06d7SDimitry Andric         supported_languages_for_types(supported_languages_for_types),
1459cfca06d7SDimitry Andric         supported_languages_for_expressions(
1460cfca06d7SDimitry Andric             supported_languages_for_expressions) {}
1461cfca06d7SDimitry Andric 
1462ead24645SDimitry Andric   LanguageSet supported_languages_for_types;
1463ead24645SDimitry Andric   LanguageSet supported_languages_for_expressions;
1464e81d9d49SDimitry Andric };
1465e81d9d49SDimitry Andric 
1466cfca06d7SDimitry Andric typedef PluginInstances<TypeSystemInstance> TypeSystemInstances;
1467e81d9d49SDimitry Andric 
GetTypeSystemInstances()146814f1b3e8SDimitry Andric static TypeSystemInstances &GetTypeSystemInstances() {
1469e81d9d49SDimitry Andric   static TypeSystemInstances g_instances;
1470e81d9d49SDimitry Andric   return g_instances;
1471e81d9d49SDimitry Andric }
1472e81d9d49SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,TypeSystemCreateInstance create_callback,LanguageSet supported_languages_for_types,LanguageSet supported_languages_for_expressions)1473ead24645SDimitry Andric bool PluginManager::RegisterPlugin(
1474c0981da4SDimitry Andric     llvm::StringRef name, llvm::StringRef description,
1475e81d9d49SDimitry Andric     TypeSystemCreateInstance create_callback,
1476ead24645SDimitry Andric     LanguageSet supported_languages_for_types,
1477ead24645SDimitry Andric     LanguageSet supported_languages_for_expressions) {
1478cfca06d7SDimitry Andric   return GetTypeSystemInstances().RegisterPlugin(
1479cfca06d7SDimitry Andric       name, description, create_callback, supported_languages_for_types,
1480cfca06d7SDimitry Andric       supported_languages_for_expressions);
1481e81d9d49SDimitry Andric }
1482e81d9d49SDimitry Andric 
UnregisterPlugin(TypeSystemCreateInstance create_callback)148314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
1484cfca06d7SDimitry Andric   return GetTypeSystemInstances().UnregisterPlugin(create_callback);
1485e81d9d49SDimitry Andric }
1486e81d9d49SDimitry Andric 
1487e81d9d49SDimitry Andric TypeSystemCreateInstance
GetTypeSystemCreateCallbackAtIndex(uint32_t idx)148814f1b3e8SDimitry Andric PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
1489cfca06d7SDimitry Andric   return GetTypeSystemInstances().GetCallbackAtIndex(idx);
1490e81d9d49SDimitry Andric }
1491e81d9d49SDimitry Andric 
GetAllTypeSystemSupportedLanguagesForTypes()1492ead24645SDimitry Andric LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
1493cfca06d7SDimitry Andric   const auto &instances = GetTypeSystemInstances().GetInstances();
1494ead24645SDimitry Andric   LanguageSet all;
1495ead24645SDimitry Andric   for (unsigned i = 0; i < instances.size(); ++i)
1496ead24645SDimitry Andric     all.bitvector |= instances[i].supported_languages_for_types.bitvector;
1497ead24645SDimitry Andric   return all;
1498e81d9d49SDimitry Andric }
1499e81d9d49SDimitry Andric 
GetAllTypeSystemSupportedLanguagesForExpressions()1500ead24645SDimitry Andric LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
1501cfca06d7SDimitry Andric   const auto &instances = GetTypeSystemInstances().GetInstances();
1502ead24645SDimitry Andric   LanguageSet all;
1503ead24645SDimitry Andric   for (unsigned i = 0; i < instances.size(); ++i)
1504ead24645SDimitry Andric     all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
1505ead24645SDimitry Andric   return all;
1506e81d9d49SDimitry Andric }
1507e81d9d49SDimitry Andric 
1508e81d9d49SDimitry Andric #pragma mark REPL
1509e81d9d49SDimitry Andric 
1510cfca06d7SDimitry Andric struct REPLInstance : public PluginInstance<REPLCreateInstance> {
REPLInstanceREPLInstance1511c0981da4SDimitry Andric   REPLInstance(llvm::StringRef name, llvm::StringRef description,
1512cfca06d7SDimitry Andric                CallbackType create_callback, LanguageSet supported_languages)
1513c0981da4SDimitry Andric       : PluginInstance<REPLCreateInstance>(name, description, create_callback),
1514cfca06d7SDimitry Andric         supported_languages(supported_languages) {}
1515e81d9d49SDimitry Andric 
1516ead24645SDimitry Andric   LanguageSet supported_languages;
1517e81d9d49SDimitry Andric };
1518e81d9d49SDimitry Andric 
1519cfca06d7SDimitry Andric typedef PluginInstances<REPLInstance> REPLInstances;
1520e81d9d49SDimitry Andric 
GetREPLInstances()152114f1b3e8SDimitry Andric static REPLInstances &GetREPLInstances() {
1522e81d9d49SDimitry Andric   static REPLInstances g_instances;
1523e81d9d49SDimitry Andric   return g_instances;
1524e81d9d49SDimitry Andric }
1525e81d9d49SDimitry Andric 
RegisterPlugin(llvm::StringRef name,llvm::StringRef description,REPLCreateInstance create_callback,LanguageSet supported_languages)1526c0981da4SDimitry Andric bool PluginManager::RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
1527e81d9d49SDimitry Andric                                    REPLCreateInstance create_callback,
1528ead24645SDimitry Andric                                    LanguageSet supported_languages) {
1529cfca06d7SDimitry Andric   return GetREPLInstances().RegisterPlugin(name, description, create_callback,
1530cfca06d7SDimitry Andric                                            supported_languages);
1531e81d9d49SDimitry Andric }
1532e81d9d49SDimitry Andric 
UnregisterPlugin(REPLCreateInstance create_callback)153314f1b3e8SDimitry Andric bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) {
1534cfca06d7SDimitry Andric   return GetREPLInstances().UnregisterPlugin(create_callback);
1535e81d9d49SDimitry Andric }
1536e81d9d49SDimitry Andric 
GetREPLCreateCallbackAtIndex(uint32_t idx)153714f1b3e8SDimitry Andric REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
1538cfca06d7SDimitry Andric   return GetREPLInstances().GetCallbackAtIndex(idx);
1539e81d9d49SDimitry Andric }
1540e81d9d49SDimitry Andric 
GetREPLSupportedLanguagesAtIndex(uint32_t idx)154177fc4c14SDimitry Andric LanguageSet PluginManager::GetREPLSupportedLanguagesAtIndex(uint32_t idx) {
154277fc4c14SDimitry Andric   const auto &instances = GetREPLInstances().GetInstances();
154377fc4c14SDimitry Andric   return idx < instances.size() ? instances[idx].supported_languages
154477fc4c14SDimitry Andric                                 : LanguageSet();
154577fc4c14SDimitry Andric }
154677fc4c14SDimitry Andric 
GetREPLAllTypeSystemSupportedLanguages()1547ead24645SDimitry Andric LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
1548cfca06d7SDimitry Andric   const auto &instances = GetREPLInstances().GetInstances();
1549ead24645SDimitry Andric   LanguageSet all;
1550ead24645SDimitry Andric   for (unsigned i = 0; i < instances.size(); ++i)
1551ead24645SDimitry Andric     all.bitvector |= instances[i].supported_languages.bitvector;
1552ead24645SDimitry Andric   return all;
1553e81d9d49SDimitry Andric }
1554e81d9d49SDimitry Andric 
1555205afe67SEd Maste #pragma mark PluginManager
1556205afe67SEd Maste 
DebuggerInitialize(Debugger & debugger)155714f1b3e8SDimitry Andric void PluginManager::DebuggerInitialize(Debugger &debugger) {
1558cfca06d7SDimitry Andric   GetDynamicLoaderInstances().PerformDebuggerCallback(debugger);
1559cfca06d7SDimitry Andric   GetJITLoaderInstances().PerformDebuggerCallback(debugger);
1560145449b1SDimitry Andric   GetObjectFileInstances().PerformDebuggerCallback(debugger);
1561cfca06d7SDimitry Andric   GetPlatformInstances().PerformDebuggerCallback(debugger);
1562cfca06d7SDimitry Andric   GetProcessInstances().PerformDebuggerCallback(debugger);
1563cfca06d7SDimitry Andric   GetSymbolFileInstances().PerformDebuggerCallback(debugger);
1564b1c73532SDimitry Andric   GetSymbolLocatorInstances().PerformDebuggerCallback(debugger);
1565cfca06d7SDimitry Andric   GetOperatingSystemInstances().PerformDebuggerCallback(debugger);
1566cfca06d7SDimitry Andric   GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
1567b60736ecSDimitry Andric   GetTracePluginInstances().PerformDebuggerCallback(debugger);
1568f034231aSEd Maste }
1569f034231aSEd Maste 
1570f034231aSEd Maste // This is the preferred new way to register plugin specific settings.  e.g.
157114f1b3e8SDimitry Andric // This will put a plugin's settings under e.g.
157214f1b3e8SDimitry Andric // "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
1573cfca06d7SDimitry Andric static lldb::OptionValuePropertiesSP
GetDebuggerPropertyForPlugins(Debugger & debugger,llvm::StringRef plugin_type_name,llvm::StringRef plugin_type_desc,bool can_create)15747fa27ce4SDimitry Andric GetDebuggerPropertyForPlugins(Debugger &debugger, llvm::StringRef plugin_type_name,
15757fa27ce4SDimitry Andric                               llvm::StringRef plugin_type_desc,
15767fa27ce4SDimitry Andric                               bool can_create) {
157714f1b3e8SDimitry Andric   lldb::OptionValuePropertiesSP parent_properties_sp(
157814f1b3e8SDimitry Andric       debugger.GetValueProperties());
157914f1b3e8SDimitry Andric   if (parent_properties_sp) {
15807fa27ce4SDimitry Andric     static constexpr llvm::StringLiteral g_property_name("plugin");
1581f034231aSEd Maste 
158214f1b3e8SDimitry Andric     OptionValuePropertiesSP plugin_properties_sp =
158314f1b3e8SDimitry Andric         parent_properties_sp->GetSubProperty(nullptr, g_property_name);
158414f1b3e8SDimitry Andric     if (!plugin_properties_sp && can_create) {
158574a628f7SDimitry Andric       plugin_properties_sp =
158674a628f7SDimitry Andric           std::make_shared<OptionValueProperties>(g_property_name);
15877fa27ce4SDimitry Andric       parent_properties_sp->AppendProperty(g_property_name,
15887fa27ce4SDimitry Andric                                            "Settings specify to plugins.", true,
1589f034231aSEd Maste                                            plugin_properties_sp);
1590f034231aSEd Maste     }
1591f034231aSEd Maste 
159214f1b3e8SDimitry Andric     if (plugin_properties_sp) {
159314f1b3e8SDimitry Andric       lldb::OptionValuePropertiesSP plugin_type_properties_sp =
159414f1b3e8SDimitry Andric           plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
159514f1b3e8SDimitry Andric       if (!plugin_type_properties_sp && can_create) {
159674a628f7SDimitry Andric         plugin_type_properties_sp =
159774a628f7SDimitry Andric             std::make_shared<OptionValueProperties>(plugin_type_name);
159814f1b3e8SDimitry Andric         plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
159914f1b3e8SDimitry Andric                                              true, plugin_type_properties_sp);
1600f034231aSEd Maste       }
1601f034231aSEd Maste       return plugin_type_properties_sp;
1602f034231aSEd Maste     }
1603f034231aSEd Maste   }
1604f034231aSEd Maste   return lldb::OptionValuePropertiesSP();
1605f034231aSEd Maste }
1606f034231aSEd Maste 
1607f034231aSEd Maste // This is deprecated way to register plugin specific settings.  e.g.
1608f73363f1SDimitry Andric // "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform
1609f73363f1SDimitry Andric // generic settings would be under "platform.SETTINGNAME".
GetDebuggerPropertyForPluginsOldStyle(Debugger & debugger,llvm::StringRef plugin_type_name,llvm::StringRef plugin_type_desc,bool can_create)161014f1b3e8SDimitry Andric static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(
16117fa27ce4SDimitry Andric     Debugger &debugger, llvm::StringRef plugin_type_name,
16127fa27ce4SDimitry Andric     llvm::StringRef plugin_type_desc, bool can_create) {
16137fa27ce4SDimitry Andric   static constexpr llvm::StringLiteral g_property_name("plugin");
161414f1b3e8SDimitry Andric   lldb::OptionValuePropertiesSP parent_properties_sp(
161514f1b3e8SDimitry Andric       debugger.GetValueProperties());
161614f1b3e8SDimitry Andric   if (parent_properties_sp) {
161714f1b3e8SDimitry Andric     OptionValuePropertiesSP plugin_properties_sp =
161814f1b3e8SDimitry Andric         parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
161914f1b3e8SDimitry Andric     if (!plugin_properties_sp && can_create) {
162074a628f7SDimitry Andric       plugin_properties_sp =
162174a628f7SDimitry Andric           std::make_shared<OptionValueProperties>(plugin_type_name);
162214f1b3e8SDimitry Andric       parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
162314f1b3e8SDimitry Andric                                            true, plugin_properties_sp);
1624f034231aSEd Maste     }
1625f034231aSEd Maste 
162614f1b3e8SDimitry Andric     if (plugin_properties_sp) {
162714f1b3e8SDimitry Andric       lldb::OptionValuePropertiesSP plugin_type_properties_sp =
162814f1b3e8SDimitry Andric           plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
162914f1b3e8SDimitry Andric       if (!plugin_type_properties_sp && can_create) {
163074a628f7SDimitry Andric         plugin_type_properties_sp =
163174a628f7SDimitry Andric             std::make_shared<OptionValueProperties>(g_property_name);
16327fa27ce4SDimitry Andric         plugin_properties_sp->AppendProperty(g_property_name,
16337fa27ce4SDimitry Andric                                              "Settings specific to plugins",
16347fa27ce4SDimitry Andric                                              true, plugin_type_properties_sp);
1635f034231aSEd Maste       }
1636f034231aSEd Maste       return plugin_type_properties_sp;
1637f034231aSEd Maste     }
1638f034231aSEd Maste   }
1639f034231aSEd Maste   return lldb::OptionValuePropertiesSP();
1640f034231aSEd Maste }
1641f034231aSEd Maste 
1642e81d9d49SDimitry Andric namespace {
1643e81d9d49SDimitry Andric 
1644e81d9d49SDimitry Andric typedef lldb::OptionValuePropertiesSP
16457fa27ce4SDimitry Andric GetDebuggerPropertyForPluginsPtr(Debugger &, llvm::StringRef, llvm::StringRef,
1646cfca06d7SDimitry Andric                                  bool can_create);
1647c0981da4SDimitry Andric }
1648f034231aSEd Maste 
1649c0981da4SDimitry Andric static lldb::OptionValuePropertiesSP
GetSettingForPlugin(Debugger & debugger,llvm::StringRef setting_name,llvm::StringRef plugin_type_name,GetDebuggerPropertyForPluginsPtr get_debugger_property=GetDebuggerPropertyForPlugins)16507fa27ce4SDimitry Andric GetSettingForPlugin(Debugger &debugger, llvm::StringRef setting_name,
16517fa27ce4SDimitry Andric                     llvm::StringRef plugin_type_name,
165214f1b3e8SDimitry Andric                     GetDebuggerPropertyForPluginsPtr get_debugger_property =
165314f1b3e8SDimitry Andric                         GetDebuggerPropertyForPlugins) {
1654f034231aSEd Maste   lldb::OptionValuePropertiesSP properties_sp;
165514f1b3e8SDimitry Andric   lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property(
165614f1b3e8SDimitry Andric       debugger, plugin_type_name,
16577fa27ce4SDimitry Andric       "", // not creating to so we don't need the description
1658f034231aSEd Maste       false));
1659f034231aSEd Maste   if (plugin_type_properties_sp)
166014f1b3e8SDimitry Andric     properties_sp =
166114f1b3e8SDimitry Andric         plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1662f034231aSEd Maste   return properties_sp;
1663f034231aSEd Maste }
1664f034231aSEd Maste 
1665c0981da4SDimitry Andric static bool
CreateSettingForPlugin(Debugger & debugger,llvm::StringRef plugin_type_name,llvm::StringRef plugin_type_desc,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property,GetDebuggerPropertyForPluginsPtr get_debugger_property=GetDebuggerPropertyForPlugins)16667fa27ce4SDimitry Andric CreateSettingForPlugin(Debugger &debugger, llvm::StringRef plugin_type_name,
16677fa27ce4SDimitry Andric                        llvm::StringRef plugin_type_desc,
1668c0981da4SDimitry Andric                        const lldb::OptionValuePropertiesSP &properties_sp,
16697fa27ce4SDimitry Andric                        llvm::StringRef description, bool is_global_property,
167014f1b3e8SDimitry Andric                        GetDebuggerPropertyForPluginsPtr get_debugger_property =
167114f1b3e8SDimitry Andric                            GetDebuggerPropertyForPlugins) {
167214f1b3e8SDimitry Andric   if (properties_sp) {
167314f1b3e8SDimitry Andric     lldb::OptionValuePropertiesSP plugin_type_properties_sp(
167414f1b3e8SDimitry Andric         get_debugger_property(debugger, plugin_type_name, plugin_type_desc,
167514f1b3e8SDimitry Andric                               true));
167614f1b3e8SDimitry Andric     if (plugin_type_properties_sp) {
1677e81d9d49SDimitry Andric       plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
167814f1b3e8SDimitry Andric                                                 description, is_global_property,
1679e81d9d49SDimitry Andric                                                 properties_sp);
1680e81d9d49SDimitry Andric       return true;
1681e81d9d49SDimitry Andric     }
1682e81d9d49SDimitry Andric   }
1683e81d9d49SDimitry Andric   return false;
1684e81d9d49SDimitry Andric }
1685e81d9d49SDimitry Andric 
16867fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kDynamicLoaderPluginName("dynamic-loader");
16877fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kPlatformPluginName("platform");
16887fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kProcessPluginName("process");
16897fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kTracePluginName("trace");
16907fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kObjectFilePluginName("object-file");
16917fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kSymbolFilePluginName("symbol-file");
1692b1c73532SDimitry Andric static constexpr llvm::StringLiteral kSymbolLocatorPluginName("symbol-locator");
16937fa27ce4SDimitry Andric static constexpr llvm::StringLiteral kJITLoaderPluginName("jit-loader");
16947fa27ce4SDimitry Andric static constexpr llvm::StringLiteral
16957fa27ce4SDimitry Andric     kStructuredDataPluginName("structured-data");
1696e81d9d49SDimitry Andric 
1697cfca06d7SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForDynamicLoaderPlugin(Debugger & debugger,llvm::StringRef setting_name)1698cfca06d7SDimitry Andric PluginManager::GetSettingForDynamicLoaderPlugin(Debugger &debugger,
16997fa27ce4SDimitry Andric                                                 llvm::StringRef setting_name) {
17007fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kDynamicLoaderPluginName);
1701e81d9d49SDimitry Andric }
1702e81d9d49SDimitry Andric 
CreateSettingForDynamicLoaderPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)170314f1b3e8SDimitry Andric bool PluginManager::CreateSettingForDynamicLoaderPlugin(
170414f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17057fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17067fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kDynamicLoaderPluginName,
17077fa27ce4SDimitry Andric                                 "Settings for dynamic loader plug-ins",
17087fa27ce4SDimitry Andric                                 properties_sp, description, is_global_property);
1709f034231aSEd Maste }
1710f034231aSEd Maste 
1711f034231aSEd Maste lldb::OptionValuePropertiesSP
GetSettingForPlatformPlugin(Debugger & debugger,llvm::StringRef setting_name)171214f1b3e8SDimitry Andric PluginManager::GetSettingForPlatformPlugin(Debugger &debugger,
17137fa27ce4SDimitry Andric                                            llvm::StringRef setting_name) {
17147fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kPlatformPluginName,
1715e81d9d49SDimitry Andric                              GetDebuggerPropertyForPluginsOldStyle);
1716f034231aSEd Maste }
1717f034231aSEd Maste 
CreateSettingForPlatformPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)171814f1b3e8SDimitry Andric bool PluginManager::CreateSettingForPlatformPlugin(
171914f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17207fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17217fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kPlatformPluginName,
17227fa27ce4SDimitry Andric                                 "Settings for platform plug-ins", properties_sp,
17237fa27ce4SDimitry Andric                                 description, is_global_property,
1724e81d9d49SDimitry Andric                                 GetDebuggerPropertyForPluginsOldStyle);
1725f034231aSEd Maste }
1726f034231aSEd Maste 
1727f034231aSEd Maste lldb::OptionValuePropertiesSP
GetSettingForProcessPlugin(Debugger & debugger,llvm::StringRef setting_name)172814f1b3e8SDimitry Andric PluginManager::GetSettingForProcessPlugin(Debugger &debugger,
17297fa27ce4SDimitry Andric                                           llvm::StringRef setting_name) {
17307fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kProcessPluginName);
1731f034231aSEd Maste }
1732f034231aSEd Maste 
CreateSettingForProcessPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)173314f1b3e8SDimitry Andric bool PluginManager::CreateSettingForProcessPlugin(
173414f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17357fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17367fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kProcessPluginName,
17377fa27ce4SDimitry Andric                                 "Settings for process plug-ins", properties_sp,
17387fa27ce4SDimitry Andric                                 description, is_global_property);
1739e81d9d49SDimitry Andric }
1740e81d9d49SDimitry Andric 
1741b1c73532SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForSymbolLocatorPlugin(Debugger & debugger,llvm::StringRef setting_name)1742b1c73532SDimitry Andric PluginManager::GetSettingForSymbolLocatorPlugin(Debugger &debugger,
1743b1c73532SDimitry Andric                                                 llvm::StringRef setting_name) {
1744b1c73532SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kSymbolLocatorPluginName);
1745b1c73532SDimitry Andric }
1746b1c73532SDimitry Andric 
CreateSettingForSymbolLocatorPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)1747b1c73532SDimitry Andric bool PluginManager::CreateSettingForSymbolLocatorPlugin(
1748b1c73532SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
1749b1c73532SDimitry Andric     llvm::StringRef description, bool is_global_property) {
1750b1c73532SDimitry Andric   return CreateSettingForPlugin(debugger, kSymbolLocatorPluginName,
1751b1c73532SDimitry Andric                                 "Settings for symbol locator plug-ins",
1752b1c73532SDimitry Andric                                 properties_sp, description, is_global_property);
1753b1c73532SDimitry Andric }
1754b1c73532SDimitry Andric 
CreateSettingForTracePlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)1755e3b55780SDimitry Andric bool PluginManager::CreateSettingForTracePlugin(
1756e3b55780SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17577fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17587fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kTracePluginName,
17597fa27ce4SDimitry Andric                                 "Settings for trace plug-ins", properties_sp,
17607fa27ce4SDimitry Andric                                 description, is_global_property);
1761e3b55780SDimitry Andric }
1762e3b55780SDimitry Andric 
1763e81d9d49SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForObjectFilePlugin(Debugger & debugger,llvm::StringRef setting_name)1764145449b1SDimitry Andric PluginManager::GetSettingForObjectFilePlugin(Debugger &debugger,
17657fa27ce4SDimitry Andric                                              llvm::StringRef setting_name) {
17667fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kObjectFilePluginName);
1767145449b1SDimitry Andric }
1768145449b1SDimitry Andric 
CreateSettingForObjectFilePlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)1769145449b1SDimitry Andric bool PluginManager::CreateSettingForObjectFilePlugin(
1770145449b1SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17717fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17727fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kObjectFilePluginName,
17737fa27ce4SDimitry Andric                                 "Settings for object file plug-ins",
17747fa27ce4SDimitry Andric                                 properties_sp, description, is_global_property);
1775145449b1SDimitry Andric }
1776145449b1SDimitry Andric 
1777145449b1SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForSymbolFilePlugin(Debugger & debugger,llvm::StringRef setting_name)1778e81d9d49SDimitry Andric PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger,
17797fa27ce4SDimitry Andric                                              llvm::StringRef setting_name) {
17807fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kSymbolFilePluginName);
1781e81d9d49SDimitry Andric }
1782e81d9d49SDimitry Andric 
CreateSettingForSymbolFilePlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)178314f1b3e8SDimitry Andric bool PluginManager::CreateSettingForSymbolFilePlugin(
178414f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17857fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
17867fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kSymbolFilePluginName,
17877fa27ce4SDimitry Andric                                 "Settings for symbol file plug-ins",
17887fa27ce4SDimitry Andric                                 properties_sp, description, is_global_property);
1789e81d9d49SDimitry Andric }
1790e81d9d49SDimitry Andric 
1791e81d9d49SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForJITLoaderPlugin(Debugger & debugger,llvm::StringRef setting_name)1792e81d9d49SDimitry Andric PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger,
17937fa27ce4SDimitry Andric                                             llvm::StringRef setting_name) {
17947fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kJITLoaderPluginName);
1795e81d9d49SDimitry Andric }
1796e81d9d49SDimitry Andric 
CreateSettingForJITLoaderPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)179714f1b3e8SDimitry Andric bool PluginManager::CreateSettingForJITLoaderPlugin(
179814f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
17997fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
18007fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kJITLoaderPluginName,
18017fa27ce4SDimitry Andric                                 "Settings for JIT loader plug-ins",
180214f1b3e8SDimitry Andric                                 properties_sp, description, is_global_property);
1803e81d9d49SDimitry Andric }
1804e81d9d49SDimitry Andric 
1805e81d9d49SDimitry Andric static const char *kOperatingSystemPluginName("os");
1806e81d9d49SDimitry Andric 
1807cfca06d7SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForOperatingSystemPlugin(Debugger & debugger,llvm::StringRef setting_name)1808cfca06d7SDimitry Andric PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger,
18097fa27ce4SDimitry Andric                                                   llvm::StringRef setting_name) {
1810e81d9d49SDimitry Andric   lldb::OptionValuePropertiesSP properties_sp;
1811e81d9d49SDimitry Andric   lldb::OptionValuePropertiesSP plugin_type_properties_sp(
181214f1b3e8SDimitry Andric       GetDebuggerPropertyForPlugins(
18137fa27ce4SDimitry Andric           debugger, kOperatingSystemPluginName,
18147fa27ce4SDimitry Andric           "", // not creating to so we don't need the description
1815e81d9d49SDimitry Andric           false));
1816e81d9d49SDimitry Andric   if (plugin_type_properties_sp)
181714f1b3e8SDimitry Andric     properties_sp =
181814f1b3e8SDimitry Andric         plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
1819e81d9d49SDimitry Andric   return properties_sp;
1820e81d9d49SDimitry Andric }
1821e81d9d49SDimitry Andric 
CreateSettingForOperatingSystemPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)182214f1b3e8SDimitry Andric bool PluginManager::CreateSettingForOperatingSystemPlugin(
182314f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
18247fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
182514f1b3e8SDimitry Andric   if (properties_sp) {
1826e81d9d49SDimitry Andric     lldb::OptionValuePropertiesSP plugin_type_properties_sp(
18277fa27ce4SDimitry Andric         GetDebuggerPropertyForPlugins(debugger, kOperatingSystemPluginName,
18287fa27ce4SDimitry Andric                                       "Settings for operating system plug-ins",
18297fa27ce4SDimitry Andric                                       true));
183014f1b3e8SDimitry Andric     if (plugin_type_properties_sp) {
183114f1b3e8SDimitry Andric       plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
183214f1b3e8SDimitry Andric                                                 description, is_global_property,
1833f034231aSEd Maste                                                 properties_sp);
1834f034231aSEd Maste       return true;
1835f034231aSEd Maste     }
1836f034231aSEd Maste   }
1837f034231aSEd Maste   return false;
1838f034231aSEd Maste }
183914f1b3e8SDimitry Andric 
1840cfca06d7SDimitry Andric lldb::OptionValuePropertiesSP
GetSettingForStructuredDataPlugin(Debugger & debugger,llvm::StringRef setting_name)1841cfca06d7SDimitry Andric PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger,
18427fa27ce4SDimitry Andric                                                  llvm::StringRef setting_name) {
18437fa27ce4SDimitry Andric   return GetSettingForPlugin(debugger, setting_name, kStructuredDataPluginName);
184414f1b3e8SDimitry Andric }
184514f1b3e8SDimitry Andric 
CreateSettingForStructuredDataPlugin(Debugger & debugger,const lldb::OptionValuePropertiesSP & properties_sp,llvm::StringRef description,bool is_global_property)184614f1b3e8SDimitry Andric bool PluginManager::CreateSettingForStructuredDataPlugin(
184714f1b3e8SDimitry Andric     Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
18487fa27ce4SDimitry Andric     llvm::StringRef description, bool is_global_property) {
18497fa27ce4SDimitry Andric   return CreateSettingForPlugin(debugger, kStructuredDataPluginName,
18507fa27ce4SDimitry Andric                                 "Settings for structured data plug-ins",
18517fa27ce4SDimitry Andric                                 properties_sp, description, is_global_property);
185214f1b3e8SDimitry Andric }
1853