Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- PluginManager.cpp ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Core/PluginManager.h" |
| 11 | |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 13 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 14 | #include "lldb/Interpreter/OptionValueProperties.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 15 | #include "lldb/Utility/ConstString.h" // for ConstString |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/FileSpec.h" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/Status.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/StringList.h" // for StringList |
| 19 | |
Nico Weber | b1cb0b79 | 2018-04-10 13:33:45 +0000 | [diff] [blame] | 20 | #if defined(_WIN32) |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 21 | #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX |
| 22 | #endif |
| 23 | |
| 24 | #include "llvm/ADT/StringRef.h" |
| 25 | #include "llvm/Support/DynamicLibrary.h" |
| 26 | #include "llvm/Support/FileSystem.h" // for file_type, file_... |
| 27 | #include "llvm/Support/raw_ostream.h" // for fs |
| 28 | |
| 29 | #include <map> // for map<>::const_ite... |
| 30 | #include <memory> // for shared_ptr |
| 31 | #include <mutex> |
| 32 | #include <string> |
| 33 | #include <utility> // for pair |
| 34 | #include <vector> |
| 35 | |
| 36 | #include <assert.h> // for assert |
| 37 | |
| 38 | namespace lldb_private { |
| 39 | class CommandInterpreter; |
| 40 | } |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 41 | |
| 42 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | using namespace lldb_private; |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | enum PluginAction { |
| 46 | ePluginRegisterInstance, |
| 47 | ePluginUnregisterInstance, |
| 48 | ePluginGetInstanceAtIndex |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Eugene Zelenko | 8918372 | 2016-03-11 21:55:47 +0000 | [diff] [blame] | 51 | typedef bool (*PluginInitCallback)(); |
| 52 | typedef void (*PluginTermCallback)(); |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | struct PluginInfo { |
| 55 | PluginInfo() : plugin_init_callback(nullptr), plugin_term_callback(nullptr) {} |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | llvm::sys::DynamicLibrary library; |
| 58 | PluginInitCallback plugin_init_callback; |
| 59 | PluginTermCallback plugin_term_callback; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | typedef std::map<FileSpec, PluginInfo> PluginTerminateMap; |
| 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | static std::recursive_mutex &GetPluginMapMutex() { |
| 65 | static std::recursive_mutex g_plugin_map_mutex; |
| 66 | return g_plugin_map_mutex; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | static PluginTerminateMap &GetPluginMap() { |
| 70 | static PluginTerminateMap g_plugin_map; |
| 71 | return g_plugin_map; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | static bool PluginIsLoaded(const FileSpec &plugin_file_spec) { |
| 75 | std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); |
| 76 | PluginTerminateMap &plugin_map = GetPluginMap(); |
| 77 | return plugin_map.find(plugin_file_spec) != plugin_map.end(); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | static void SetPluginInfo(const FileSpec &plugin_file_spec, |
| 81 | const PluginInfo &plugin_info) { |
| 82 | std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); |
| 83 | PluginTerminateMap &plugin_map = GetPluginMap(); |
| 84 | assert(plugin_map.find(plugin_file_spec) == plugin_map.end()); |
| 85 | plugin_map[plugin_file_spec] = plugin_info; |
David Majnemer | 5ff0278 | 2014-07-22 21:59:22 +0000 | [diff] [blame] | 86 | } |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) { |
| 89 | return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr)); |
| 90 | } |
Greg Clayton | 4531946 | 2011-02-08 00:35:34 +0000 | [diff] [blame] | 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | static FileSpec::EnumerateDirectoryResult |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 93 | LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | const FileSpec &file_spec) { |
| 95 | // PluginManager *plugin_manager = (PluginManager *)baton; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 96 | Status error; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 97 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 98 | namespace fs = llvm::sys::fs; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 99 | // If we have a regular file, a symbolic link or unknown file type, try and |
| 100 | // process the file. We must handle unknown as sometimes the directory |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | // enumeration might be enumerating a file system that doesn't have correct |
| 102 | // file type information. |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 103 | if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || |
| 104 | ft == fs::file_type::type_unknown) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | FileSpec plugin_file_spec(file_spec); |
| 106 | plugin_file_spec.ResolvePath(); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | if (PluginIsLoaded(plugin_file_spec)) |
| 109 | return FileSpec::eEnumerateDirectoryResultNext; |
| 110 | else { |
| 111 | PluginInfo plugin_info; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 112 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | std::string pluginLoadError; |
| 114 | plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary( |
| 115 | plugin_file_spec.GetPath().c_str(), &pluginLoadError); |
| 116 | if (plugin_info.library.isValid()) { |
| 117 | bool success = false; |
| 118 | plugin_info.plugin_init_callback = CastToFPtr<PluginInitCallback>( |
| 119 | plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize")); |
| 120 | if (plugin_info.plugin_init_callback) { |
| 121 | // Call the plug-in "bool LLDBPluginInitialize(void)" function |
| 122 | success = plugin_info.plugin_init_callback(); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 123 | } |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | if (success) { |
| 126 | // It is ok for the "LLDBPluginTerminate" symbol to be nullptr |
| 127 | plugin_info.plugin_term_callback = CastToFPtr<PluginTermCallback>( |
| 128 | plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate")); |
| 129 | } else { |
| 130 | // The initialize function returned FALSE which means the plug-in |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 131 | // might not be compatible, or might be too new or too old, or might |
| 132 | // not want to run on this machine. Set it to a default-constructed |
| 133 | // instance to invalidate it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | plugin_info = PluginInfo(); |
| 135 | } |
| 136 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 137 | // Regardless of success or failure, cache the plug-in load in our |
| 138 | // plug-in info so we don't try to load it again and again. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | SetPluginInfo(plugin_file_spec, plugin_info); |
| 140 | |
| 141 | return FileSpec::eEnumerateDirectoryResultNext; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 146 | if (ft == fs::file_type::directory_file || |
| 147 | ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 148 | // Try and recurse into anything that a directory or symbolic link. We must |
| 149 | // also do this for unknown as sometimes the directory enumeration might be |
| 150 | // enumerating a file system that doesn't have correct file type |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 151 | // information. |
| 152 | return FileSpec::eEnumerateDirectoryResultEnter; |
| 153 | } |
| 154 | |
| 155 | return FileSpec::eEnumerateDirectoryResultNext; |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | void PluginManager::Initialize() { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 159 | #if 1 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | const bool find_directories = true; |
| 161 | const bool find_files = true; |
| 162 | const bool find_other = true; |
| 163 | char dir_path[PATH_MAX]; |
Pavel Labath | 60f028f | 2018-06-19 15:09:07 +0000 | [diff] [blame] | 164 | if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { |
| 166 | FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, |
| 167 | find_other, LoadPluginCallback, nullptr); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 168 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | } |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 170 | |
Pavel Labath | 60f028f | 2018-06-19 15:09:07 +0000 | [diff] [blame] | 171 | if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { |
| 173 | FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, |
| 174 | find_other, LoadPluginCallback, nullptr); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 175 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 177 | #endif |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | void PluginManager::Terminate() { |
| 181 | std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); |
| 182 | PluginTerminateMap &plugin_map = GetPluginMap(); |
| 183 | |
| 184 | PluginTerminateMap::const_iterator pos, end = plugin_map.end(); |
| 185 | for (pos = plugin_map.begin(); pos != end; ++pos) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 186 | // Call the plug-in "void LLDBPluginTerminate (void)" function if there is |
| 187 | // one (if the symbol was not nullptr). |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 188 | if (pos->second.library.isValid()) { |
| 189 | if (pos->second.plugin_term_callback) |
| 190 | pos->second.plugin_term_callback(); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 191 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | } |
| 193 | plugin_map.clear(); |
Greg Clayton | 4272cc7 | 2011-02-02 02:24:04 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | #pragma mark ABI |
| 197 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | struct ABIInstance { |
| 199 | ABIInstance() : name(), description(), create_callback(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | ConstString name; |
| 202 | std::string description; |
| 203 | ABICreateInstance create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | typedef std::vector<ABIInstance> ABIInstances; |
| 207 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 208 | static std::recursive_mutex &GetABIInstancesMutex() { |
| 209 | static std::recursive_mutex g_instances_mutex; |
| 210 | return g_instances_mutex; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | static ABIInstances &GetABIInstances() { |
| 214 | static ABIInstances g_instances; |
| 215 | return g_instances; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 216 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 217 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 218 | bool PluginManager::RegisterPlugin(const ConstString &name, |
| 219 | const char *description, |
| 220 | ABICreateInstance create_callback) { |
| 221 | if (create_callback) { |
| 222 | ABIInstance instance; |
| 223 | assert((bool)name); |
| 224 | instance.name = name; |
| 225 | if (description && description[0]) |
| 226 | instance.description = description; |
| 227 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 228 | std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | GetABIInstances().push_back(instance); |
| 230 | return true; |
| 231 | } |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) { |
| 236 | if (create_callback) { |
| 237 | std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); |
| 238 | ABIInstances &instances = GetABIInstances(); |
| 239 | |
| 240 | ABIInstances::iterator pos, end = instances.end(); |
| 241 | for (pos = instances.begin(); pos != end; ++pos) { |
| 242 | if (pos->create_callback == create_callback) { |
| 243 | instances.erase(pos); |
| 244 | return true; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) { |
| 252 | std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); |
| 253 | ABIInstances &instances = GetABIInstances(); |
| 254 | if (idx < instances.size()) |
| 255 | return instances[idx].create_callback; |
| 256 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | ABICreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | PluginManager::GetABICreateCallbackForPluginName(const ConstString &name) { |
| 261 | if (name) { |
| 262 | std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); |
| 263 | ABIInstances &instances = GetABIInstances(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 264 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | ABIInstances::iterator pos, end = instances.end(); |
| 266 | for (pos = instances.begin(); pos != end; ++pos) { |
| 267 | if (name == pos->name) |
| 268 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | } |
| 271 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 274 | #pragma mark Architecture |
| 275 | |
| 276 | struct ArchitectureInstance { |
| 277 | ConstString name; |
| 278 | std::string description; |
| 279 | PluginManager::ArchitectureCreateInstance create_callback; |
| 280 | }; |
| 281 | |
| 282 | typedef std::vector<ArchitectureInstance> ArchitectureInstances; |
| 283 | |
| 284 | static std::mutex g_architecture_mutex; |
| 285 | |
| 286 | static ArchitectureInstances &GetArchitectureInstances() { |
| 287 | static ArchitectureInstances g_instances; |
| 288 | return g_instances; |
| 289 | } |
| 290 | |
| 291 | void PluginManager::RegisterPlugin(const ConstString &name, |
| 292 | llvm::StringRef description, |
| 293 | ArchitectureCreateInstance create_callback) { |
| 294 | std::lock_guard<std::mutex> guard(g_architecture_mutex); |
| 295 | GetArchitectureInstances().push_back({name, description, create_callback}); |
| 296 | } |
| 297 | |
| 298 | void PluginManager::UnregisterPlugin( |
| 299 | ArchitectureCreateInstance create_callback) { |
| 300 | std::lock_guard<std::mutex> guard(g_architecture_mutex); |
| 301 | auto &instances = GetArchitectureInstances(); |
| 302 | |
| 303 | for (auto pos = instances.begin(), end = instances.end(); pos != end; ++pos) { |
| 304 | if (pos->create_callback == create_callback) { |
| 305 | instances.erase(pos); |
| 306 | return; |
| 307 | } |
| 308 | } |
| 309 | llvm_unreachable("Plugin not found"); |
| 310 | } |
| 311 | |
| 312 | std::unique_ptr<Architecture> |
| 313 | PluginManager::CreateArchitectureInstance(const ArchSpec &arch) { |
| 314 | std::lock_guard<std::mutex> guard(g_architecture_mutex); |
| 315 | for (const auto &instances : GetArchitectureInstances()) { |
| 316 | if (auto plugin_up = instances.create_callback(arch)) |
| 317 | return plugin_up; |
| 318 | } |
| 319 | return nullptr; |
| 320 | } |
| 321 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | #pragma mark Disassembler |
| 323 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 324 | struct DisassemblerInstance { |
| 325 | DisassemblerInstance() : name(), description(), create_callback(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 327 | ConstString name; |
| 328 | std::string description; |
| 329 | DisassemblerCreateInstance create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | typedef std::vector<DisassemblerInstance> DisassemblerInstances; |
| 333 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 334 | static std::recursive_mutex &GetDisassemblerMutex() { |
| 335 | static std::recursive_mutex g_instances_mutex; |
| 336 | return g_instances_mutex; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 339 | static DisassemblerInstances &GetDisassemblerInstances() { |
| 340 | static DisassemblerInstances g_instances; |
| 341 | return g_instances; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 342 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | bool PluginManager::RegisterPlugin(const ConstString &name, |
| 345 | const char *description, |
| 346 | DisassemblerCreateInstance create_callback) { |
| 347 | if (create_callback) { |
| 348 | DisassemblerInstance instance; |
| 349 | assert((bool)name); |
| 350 | instance.name = name; |
| 351 | if (description && description[0]) |
| 352 | instance.description = description; |
| 353 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 354 | std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 355 | GetDisassemblerInstances().push_back(instance); |
| 356 | return true; |
| 357 | } |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | bool PluginManager::UnregisterPlugin( |
| 362 | DisassemblerCreateInstance create_callback) { |
| 363 | if (create_callback) { |
| 364 | std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); |
| 365 | DisassemblerInstances &instances = GetDisassemblerInstances(); |
| 366 | |
| 367 | DisassemblerInstances::iterator pos, end = instances.end(); |
| 368 | for (pos = instances.begin(); pos != end; ++pos) { |
| 369 | if (pos->create_callback == create_callback) { |
| 370 | instances.erase(pos); |
| 371 | return true; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | DisassemblerCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 379 | PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) { |
| 380 | std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); |
| 381 | DisassemblerInstances &instances = GetDisassemblerInstances(); |
| 382 | if (idx < instances.size()) |
| 383 | return instances[idx].create_callback; |
| 384 | return nullptr; |
| 385 | } |
| 386 | |
| 387 | DisassemblerCreateInstance |
| 388 | PluginManager::GetDisassemblerCreateCallbackForPluginName( |
| 389 | const ConstString &name) { |
| 390 | if (name) { |
| 391 | std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); |
| 392 | DisassemblerInstances &instances = GetDisassemblerInstances(); |
| 393 | |
| 394 | DisassemblerInstances::iterator pos, end = instances.end(); |
| 395 | for (pos = instances.begin(); pos != end; ++pos) { |
| 396 | if (name == pos->name) |
| 397 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 399 | } |
| 400 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | #pragma mark DynamicLoader |
| 404 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | struct DynamicLoaderInstance { |
| 406 | DynamicLoaderInstance() |
| 407 | : name(), description(), create_callback(nullptr), |
| 408 | debugger_init_callback(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 410 | ConstString name; |
| 411 | std::string description; |
| 412 | DynamicLoaderCreateInstance create_callback; |
| 413 | DebuggerInitializeCallback debugger_init_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances; |
| 417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | static std::recursive_mutex &GetDynamicLoaderMutex() { |
| 419 | static std::recursive_mutex g_instances_mutex; |
| 420 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 421 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 423 | static DynamicLoaderInstances &GetDynamicLoaderInstances() { |
| 424 | static DynamicLoaderInstances g_instances; |
| 425 | return g_instances; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | bool PluginManager::RegisterPlugin( |
| 429 | const ConstString &name, const char *description, |
| 430 | DynamicLoaderCreateInstance create_callback, |
| 431 | DebuggerInitializeCallback debugger_init_callback) { |
| 432 | if (create_callback) { |
| 433 | DynamicLoaderInstance instance; |
| 434 | assert((bool)name); |
| 435 | instance.name = name; |
| 436 | if (description && description[0]) |
| 437 | instance.description = description; |
| 438 | instance.create_callback = create_callback; |
| 439 | instance.debugger_init_callback = debugger_init_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 440 | std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 441 | GetDynamicLoaderInstances().push_back(instance); |
| 442 | } |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | bool PluginManager::UnregisterPlugin( |
| 447 | DynamicLoaderCreateInstance create_callback) { |
| 448 | if (create_callback) { |
| 449 | std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); |
| 450 | DynamicLoaderInstances &instances = GetDynamicLoaderInstances(); |
| 451 | |
| 452 | DynamicLoaderInstances::iterator pos, end = instances.end(); |
| 453 | for (pos = instances.begin(); pos != end; ++pos) { |
| 454 | if (pos->create_callback == create_callback) { |
| 455 | instances.erase(pos); |
| 456 | return true; |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | DynamicLoaderCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 464 | PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) { |
| 465 | std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); |
| 466 | DynamicLoaderInstances &instances = GetDynamicLoaderInstances(); |
| 467 | if (idx < instances.size()) |
| 468 | return instances[idx].create_callback; |
| 469 | return nullptr; |
| 470 | } |
| 471 | |
| 472 | DynamicLoaderCreateInstance |
| 473 | PluginManager::GetDynamicLoaderCreateCallbackForPluginName( |
| 474 | const ConstString &name) { |
| 475 | if (name) { |
| 476 | std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); |
| 477 | DynamicLoaderInstances &instances = GetDynamicLoaderInstances(); |
| 478 | |
| 479 | DynamicLoaderInstances::iterator pos, end = instances.end(); |
| 480 | for (pos = instances.begin(); pos != end; ++pos) { |
| 481 | if (name == pos->name) |
| 482 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 484 | } |
| 485 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 488 | #pragma mark JITLoader |
| 489 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | struct JITLoaderInstance { |
| 491 | JITLoaderInstance() |
| 492 | : name(), description(), create_callback(nullptr), |
| 493 | debugger_init_callback(nullptr) {} |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 494 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | ConstString name; |
| 496 | std::string description; |
| 497 | JITLoaderCreateInstance create_callback; |
| 498 | DebuggerInitializeCallback debugger_init_callback; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 499 | }; |
| 500 | |
| 501 | typedef std::vector<JITLoaderInstance> JITLoaderInstances; |
| 502 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | static std::recursive_mutex &GetJITLoaderMutex() { |
| 504 | static std::recursive_mutex g_instances_mutex; |
| 505 | return g_instances_mutex; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 508 | static JITLoaderInstances &GetJITLoaderInstances() { |
| 509 | static JITLoaderInstances g_instances; |
| 510 | return g_instances; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | bool PluginManager::RegisterPlugin( |
| 514 | const ConstString &name, const char *description, |
| 515 | JITLoaderCreateInstance create_callback, |
| 516 | DebuggerInitializeCallback debugger_init_callback) { |
| 517 | if (create_callback) { |
| 518 | JITLoaderInstance instance; |
| 519 | assert((bool)name); |
| 520 | instance.name = name; |
| 521 | if (description && description[0]) |
| 522 | instance.description = description; |
| 523 | instance.create_callback = create_callback; |
| 524 | instance.debugger_init_callback = debugger_init_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 525 | std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 526 | GetJITLoaderInstances().push_back(instance); |
| 527 | } |
| 528 | return false; |
| 529 | } |
| 530 | |
| 531 | bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) { |
| 532 | if (create_callback) { |
| 533 | std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); |
| 534 | JITLoaderInstances &instances = GetJITLoaderInstances(); |
| 535 | |
| 536 | JITLoaderInstances::iterator pos, end = instances.end(); |
| 537 | for (pos = instances.begin(); pos != end; ++pos) { |
| 538 | if (pos->create_callback == create_callback) { |
| 539 | instances.erase(pos); |
| 540 | return true; |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | return false; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | JITLoaderCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 548 | PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) { |
| 549 | std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); |
| 550 | JITLoaderInstances &instances = GetJITLoaderInstances(); |
| 551 | if (idx < instances.size()) |
| 552 | return instances[idx].create_callback; |
| 553 | return nullptr; |
| 554 | } |
| 555 | |
| 556 | JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackForPluginName( |
| 557 | const ConstString &name) { |
| 558 | if (name) { |
| 559 | std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); |
| 560 | JITLoaderInstances &instances = GetJITLoaderInstances(); |
| 561 | |
| 562 | JITLoaderInstances::iterator pos, end = instances.end(); |
| 563 | for (pos = instances.begin(); pos != end; ++pos) { |
| 564 | if (name == pos->name) |
| 565 | return pos->create_callback; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 566 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | } |
| 568 | return nullptr; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 571 | #pragma mark EmulateInstruction |
| 572 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | struct EmulateInstructionInstance { |
| 574 | EmulateInstructionInstance() |
| 575 | : name(), description(), create_callback(nullptr) {} |
| 576 | |
| 577 | ConstString name; |
| 578 | std::string description; |
| 579 | EmulateInstructionCreateInstance create_callback; |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances; |
| 583 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | static std::recursive_mutex &GetEmulateInstructionMutex() { |
| 585 | static std::recursive_mutex g_instances_mutex; |
| 586 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | static EmulateInstructionInstances &GetEmulateInstructionInstances() { |
| 590 | static EmulateInstructionInstances g_instances; |
| 591 | return g_instances; |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 594 | bool PluginManager::RegisterPlugin( |
| 595 | const ConstString &name, const char *description, |
| 596 | EmulateInstructionCreateInstance create_callback) { |
| 597 | if (create_callback) { |
| 598 | EmulateInstructionInstance instance; |
| 599 | assert((bool)name); |
| 600 | instance.name = name; |
| 601 | if (description && description[0]) |
| 602 | instance.description = description; |
| 603 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 604 | std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | GetEmulateInstructionInstances().push_back(instance); |
| 606 | } |
| 607 | return false; |
| 608 | } |
| 609 | |
| 610 | bool PluginManager::UnregisterPlugin( |
| 611 | EmulateInstructionCreateInstance create_callback) { |
| 612 | if (create_callback) { |
| 613 | std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); |
| 614 | EmulateInstructionInstances &instances = GetEmulateInstructionInstances(); |
| 615 | |
| 616 | EmulateInstructionInstances::iterator pos, end = instances.end(); |
| 617 | for (pos = instances.begin(); pos != end; ++pos) { |
| 618 | if (pos->create_callback == create_callback) { |
| 619 | instances.erase(pos); |
| 620 | return true; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | return false; |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | EmulateInstructionCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 628 | PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) { |
| 629 | std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); |
| 630 | EmulateInstructionInstances &instances = GetEmulateInstructionInstances(); |
| 631 | if (idx < instances.size()) |
| 632 | return instances[idx].create_callback; |
| 633 | return nullptr; |
| 634 | } |
| 635 | |
| 636 | EmulateInstructionCreateInstance |
| 637 | PluginManager::GetEmulateInstructionCreateCallbackForPluginName( |
| 638 | const ConstString &name) { |
| 639 | if (name) { |
| 640 | std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); |
| 641 | EmulateInstructionInstances &instances = GetEmulateInstructionInstances(); |
| 642 | |
| 643 | EmulateInstructionInstances::iterator pos, end = instances.end(); |
| 644 | for (pos = instances.begin(); pos != end; ++pos) { |
| 645 | if (name == pos->name) |
| 646 | return pos->create_callback; |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 647 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | } |
| 649 | return nullptr; |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 650 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 651 | |
Eugene Zelenko | 8918372 | 2016-03-11 21:55:47 +0000 | [diff] [blame] | 652 | #pragma mark OperatingSystem |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 653 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 654 | struct OperatingSystemInstance { |
| 655 | OperatingSystemInstance() |
| 656 | : name(), description(), create_callback(nullptr), |
| 657 | debugger_init_callback(nullptr) {} |
| 658 | |
| 659 | ConstString name; |
| 660 | std::string description; |
| 661 | OperatingSystemCreateInstance create_callback; |
| 662 | DebuggerInitializeCallback debugger_init_callback; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | typedef std::vector<OperatingSystemInstance> OperatingSystemInstances; |
| 666 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 667 | static std::recursive_mutex &GetOperatingSystemMutex() { |
| 668 | static std::recursive_mutex g_instances_mutex; |
| 669 | return g_instances_mutex; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 672 | static OperatingSystemInstances &GetOperatingSystemInstances() { |
| 673 | static OperatingSystemInstances g_instances; |
| 674 | return g_instances; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 677 | bool PluginManager::RegisterPlugin( |
| 678 | const ConstString &name, const char *description, |
| 679 | OperatingSystemCreateInstance create_callback, |
| 680 | DebuggerInitializeCallback debugger_init_callback) { |
| 681 | if (create_callback) { |
| 682 | OperatingSystemInstance instance; |
| 683 | assert((bool)name); |
| 684 | instance.name = name; |
| 685 | if (description && description[0]) |
| 686 | instance.description = description; |
| 687 | instance.create_callback = create_callback; |
| 688 | instance.debugger_init_callback = debugger_init_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 689 | std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 690 | GetOperatingSystemInstances().push_back(instance); |
| 691 | } |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | bool PluginManager::UnregisterPlugin( |
| 696 | OperatingSystemCreateInstance create_callback) { |
| 697 | if (create_callback) { |
| 698 | std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); |
| 699 | OperatingSystemInstances &instances = GetOperatingSystemInstances(); |
| 700 | |
| 701 | OperatingSystemInstances::iterator pos, end = instances.end(); |
| 702 | for (pos = instances.begin(); pos != end; ++pos) { |
| 703 | if (pos->create_callback == create_callback) { |
| 704 | instances.erase(pos); |
| 705 | return true; |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | return false; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | OperatingSystemCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 713 | PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) { |
| 714 | std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); |
| 715 | OperatingSystemInstances &instances = GetOperatingSystemInstances(); |
| 716 | if (idx < instances.size()) |
| 717 | return instances[idx].create_callback; |
| 718 | return nullptr; |
| 719 | } |
| 720 | |
| 721 | OperatingSystemCreateInstance |
| 722 | PluginManager::GetOperatingSystemCreateCallbackForPluginName( |
| 723 | const ConstString &name) { |
| 724 | if (name) { |
| 725 | std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); |
| 726 | OperatingSystemInstances &instances = GetOperatingSystemInstances(); |
| 727 | |
| 728 | OperatingSystemInstances::iterator pos, end = instances.end(); |
| 729 | for (pos = instances.begin(); pos != end; ++pos) { |
| 730 | if (name == pos->name) |
| 731 | return pos->create_callback; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 732 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 733 | } |
| 734 | return nullptr; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 735 | } |
Greg Clayton | f03bbe2 | 2011-02-01 01:37:45 +0000 | [diff] [blame] | 736 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 737 | #pragma mark Language |
| 738 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 739 | struct LanguageInstance { |
| 740 | LanguageInstance() : name(), description(), create_callback(nullptr) {} |
| 741 | |
| 742 | ConstString name; |
| 743 | std::string description; |
| 744 | LanguageCreateInstance create_callback; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 745 | }; |
| 746 | |
| 747 | typedef std::vector<LanguageInstance> LanguageInstances; |
| 748 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 749 | static std::recursive_mutex &GetLanguageMutex() { |
| 750 | static std::recursive_mutex g_instances_mutex; |
| 751 | return g_instances_mutex; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 754 | static LanguageInstances &GetLanguageInstances() { |
| 755 | static LanguageInstances g_instances; |
| 756 | return g_instances; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 759 | bool PluginManager::RegisterPlugin(const ConstString &name, |
| 760 | const char *description, |
| 761 | LanguageCreateInstance create_callback) { |
| 762 | if (create_callback) { |
| 763 | LanguageInstance instance; |
| 764 | assert((bool)name); |
| 765 | instance.name = name; |
| 766 | if (description && description[0]) |
| 767 | instance.description = description; |
| 768 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 769 | std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 770 | GetLanguageInstances().push_back(instance); |
| 771 | } |
| 772 | return false; |
| 773 | } |
| 774 | |
| 775 | bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) { |
| 776 | if (create_callback) { |
| 777 | std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); |
| 778 | LanguageInstances &instances = GetLanguageInstances(); |
| 779 | |
| 780 | LanguageInstances::iterator pos, end = instances.end(); |
| 781 | for (pos = instances.begin(); pos != end; ++pos) { |
| 782 | if (pos->create_callback == create_callback) { |
| 783 | instances.erase(pos); |
| 784 | return true; |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | return false; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | LanguageCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 792 | PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) { |
| 793 | std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); |
| 794 | LanguageInstances &instances = GetLanguageInstances(); |
| 795 | if (idx < instances.size()) |
| 796 | return instances[idx].create_callback; |
| 797 | return nullptr; |
| 798 | } |
| 799 | |
| 800 | LanguageCreateInstance |
| 801 | PluginManager::GetLanguageCreateCallbackForPluginName(const ConstString &name) { |
| 802 | if (name) { |
| 803 | std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); |
| 804 | LanguageInstances &instances = GetLanguageInstances(); |
| 805 | |
| 806 | LanguageInstances::iterator pos, end = instances.end(); |
| 807 | for (pos = instances.begin(); pos != end; ++pos) { |
| 808 | if (name == pos->name) |
| 809 | return pos->create_callback; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 810 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 811 | } |
| 812 | return nullptr; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 815 | #pragma mark LanguageRuntime |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 816 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | struct LanguageRuntimeInstance { |
| 818 | LanguageRuntimeInstance() : name(), description(), create_callback(nullptr) {} |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 819 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 820 | ConstString name; |
| 821 | std::string description; |
| 822 | LanguageRuntimeCreateInstance create_callback; |
| 823 | LanguageRuntimeGetCommandObject command_callback; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 824 | }; |
| 825 | |
| 826 | typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances; |
| 827 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | static std::recursive_mutex &GetLanguageRuntimeMutex() { |
| 829 | static std::recursive_mutex g_instances_mutex; |
| 830 | return g_instances_mutex; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 833 | static LanguageRuntimeInstances &GetLanguageRuntimeInstances() { |
| 834 | static LanguageRuntimeInstances g_instances; |
| 835 | return g_instances; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 836 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 837 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 838 | bool PluginManager::RegisterPlugin( |
| 839 | const ConstString &name, const char *description, |
| 840 | LanguageRuntimeCreateInstance create_callback, |
| 841 | LanguageRuntimeGetCommandObject command_callback) { |
| 842 | if (create_callback) { |
| 843 | LanguageRuntimeInstance instance; |
| 844 | assert((bool)name); |
| 845 | instance.name = name; |
| 846 | if (description && description[0]) |
| 847 | instance.description = description; |
| 848 | instance.create_callback = create_callback; |
| 849 | instance.command_callback = command_callback; |
| 850 | std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); |
| 851 | GetLanguageRuntimeInstances().push_back(instance); |
| 852 | } |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | bool PluginManager::UnregisterPlugin( |
| 857 | LanguageRuntimeCreateInstance create_callback) { |
| 858 | if (create_callback) { |
| 859 | std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); |
| 860 | LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances(); |
| 861 | |
| 862 | LanguageRuntimeInstances::iterator pos, end = instances.end(); |
| 863 | for (pos = instances.begin(); pos != end; ++pos) { |
| 864 | if (pos->create_callback == create_callback) { |
| 865 | instances.erase(pos); |
| 866 | return true; |
| 867 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 868 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 869 | } |
| 870 | return false; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | LanguageRuntimeCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 874 | PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) { |
| 875 | std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); |
| 876 | LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances(); |
| 877 | if (idx < instances.size()) |
| 878 | return instances[idx].create_callback; |
| 879 | return nullptr; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Colin Riley | c9c55a2 | 2015-05-04 18:39:38 +0000 | [diff] [blame] | 882 | LanguageRuntimeGetCommandObject |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 883 | PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) { |
| 884 | std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); |
| 885 | LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances(); |
| 886 | if (idx < instances.size()) |
| 887 | return instances[idx].command_callback; |
| 888 | return nullptr; |
Colin Riley | c9c55a2 | 2015-05-04 18:39:38 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 891 | LanguageRuntimeCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 892 | PluginManager::GetLanguageRuntimeCreateCallbackForPluginName( |
| 893 | const ConstString &name) { |
| 894 | if (name) { |
| 895 | std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); |
| 896 | LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances(); |
| 897 | |
| 898 | LanguageRuntimeInstances::iterator pos, end = instances.end(); |
| 899 | for (pos = instances.begin(); pos != end; ++pos) { |
| 900 | if (name == pos->name) |
| 901 | return pos->create_callback; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 902 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 903 | } |
| 904 | return nullptr; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 907 | #pragma mark SystemRuntime |
| 908 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 909 | struct SystemRuntimeInstance { |
| 910 | SystemRuntimeInstance() : name(), description(), create_callback(nullptr) {} |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 911 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | ConstString name; |
| 913 | std::string description; |
| 914 | SystemRuntimeCreateInstance create_callback; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 915 | }; |
| 916 | |
| 917 | typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances; |
| 918 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 919 | static std::recursive_mutex &GetSystemRuntimeMutex() { |
| 920 | static std::recursive_mutex g_instances_mutex; |
| 921 | return g_instances_mutex; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 924 | static SystemRuntimeInstances &GetSystemRuntimeInstances() { |
| 925 | static SystemRuntimeInstances g_instances; |
| 926 | return g_instances; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 929 | bool PluginManager::RegisterPlugin( |
| 930 | const ConstString &name, const char *description, |
| 931 | SystemRuntimeCreateInstance create_callback) { |
| 932 | if (create_callback) { |
| 933 | SystemRuntimeInstance instance; |
| 934 | assert((bool)name); |
| 935 | instance.name = name; |
| 936 | if (description && description[0]) |
| 937 | instance.description = description; |
| 938 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 939 | std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 940 | GetSystemRuntimeInstances().push_back(instance); |
| 941 | } |
| 942 | return false; |
| 943 | } |
| 944 | |
| 945 | bool PluginManager::UnregisterPlugin( |
| 946 | SystemRuntimeCreateInstance create_callback) { |
| 947 | if (create_callback) { |
| 948 | std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); |
| 949 | SystemRuntimeInstances &instances = GetSystemRuntimeInstances(); |
| 950 | |
| 951 | SystemRuntimeInstances::iterator pos, end = instances.end(); |
| 952 | for (pos = instances.begin(); pos != end; ++pos) { |
| 953 | if (pos->create_callback == create_callback) { |
| 954 | instances.erase(pos); |
| 955 | return true; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | return false; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | SystemRuntimeCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 963 | PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) { |
| 964 | std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); |
| 965 | SystemRuntimeInstances &instances = GetSystemRuntimeInstances(); |
| 966 | if (idx < instances.size()) |
| 967 | return instances[idx].create_callback; |
| 968 | return nullptr; |
| 969 | } |
| 970 | |
| 971 | SystemRuntimeCreateInstance |
| 972 | PluginManager::GetSystemRuntimeCreateCallbackForPluginName( |
| 973 | const ConstString &name) { |
| 974 | if (name) { |
| 975 | std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); |
| 976 | SystemRuntimeInstances &instances = GetSystemRuntimeInstances(); |
| 977 | |
| 978 | SystemRuntimeInstances::iterator pos, end = instances.end(); |
| 979 | for (pos = instances.begin(); pos != end; ++pos) { |
| 980 | if (name == pos->name) |
| 981 | return pos->create_callback; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 982 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 983 | } |
| 984 | return nullptr; |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 987 | #pragma mark ObjectFile |
| 988 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 989 | struct ObjectFileInstance { |
| 990 | ObjectFileInstance() |
| 991 | : name(), description(), create_callback(nullptr), |
| 992 | create_memory_callback(nullptr), get_module_specifications(nullptr), |
| 993 | save_core(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 994 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | ConstString name; |
| 996 | std::string description; |
| 997 | ObjectFileCreateInstance create_callback; |
| 998 | ObjectFileCreateMemoryInstance create_memory_callback; |
| 999 | ObjectFileGetModuleSpecifications get_module_specifications; |
| 1000 | ObjectFileSaveCore save_core; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | typedef std::vector<ObjectFileInstance> ObjectFileInstances; |
| 1004 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1005 | static std::recursive_mutex &GetObjectFileMutex() { |
| 1006 | static std::recursive_mutex g_instances_mutex; |
| 1007 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1008 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1009 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1010 | static ObjectFileInstances &GetObjectFileInstances() { |
| 1011 | static ObjectFileInstances g_instances; |
| 1012 | return g_instances; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1015 | bool PluginManager::RegisterPlugin( |
| 1016 | const ConstString &name, const char *description, |
| 1017 | ObjectFileCreateInstance create_callback, |
| 1018 | ObjectFileCreateMemoryInstance create_memory_callback, |
| 1019 | ObjectFileGetModuleSpecifications get_module_specifications, |
| 1020 | ObjectFileSaveCore save_core) { |
| 1021 | if (create_callback) { |
| 1022 | ObjectFileInstance instance; |
| 1023 | assert((bool)name); |
| 1024 | instance.name = name; |
| 1025 | if (description && description[0]) |
| 1026 | instance.description = description; |
| 1027 | instance.create_callback = create_callback; |
| 1028 | instance.create_memory_callback = create_memory_callback; |
| 1029 | instance.save_core = save_core; |
| 1030 | instance.get_module_specifications = get_module_specifications; |
| 1031 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1032 | GetObjectFileInstances().push_back(instance); |
| 1033 | } |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) { |
| 1038 | if (create_callback) { |
| 1039 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1040 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1041 | |
| 1042 | ObjectFileInstances::iterator pos, end = instances.end(); |
| 1043 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1044 | if (pos->create_callback == create_callback) { |
| 1045 | instances.erase(pos); |
| 1046 | return true; |
| 1047 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1048 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1049 | } |
| 1050 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | ObjectFileCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1054 | PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) { |
| 1055 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1056 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1057 | if (idx < instances.size()) |
| 1058 | return instances[idx].create_callback; |
| 1059 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1060 | } |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1061 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1062 | ObjectFileCreateMemoryInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1063 | PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) { |
| 1064 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1065 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1066 | if (idx < instances.size()) |
| 1067 | return instances[idx].create_memory_callback; |
| 1068 | return nullptr; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 1071 | ObjectFileGetModuleSpecifications |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex( |
| 1073 | uint32_t idx) { |
| 1074 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1075 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1076 | if (idx < instances.size()) |
| 1077 | return instances[idx].get_module_specifications; |
| 1078 | return nullptr; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | ObjectFileCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1082 | PluginManager::GetObjectFileCreateCallbackForPluginName( |
| 1083 | const ConstString &name) { |
| 1084 | if (name) { |
| 1085 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1086 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1087 | |
| 1088 | ObjectFileInstances::iterator pos, end = instances.end(); |
| 1089 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1090 | if (name == pos->name) |
| 1091 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1097 | ObjectFileCreateMemoryInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1098 | PluginManager::GetObjectFileCreateMemoryCallbackForPluginName( |
| 1099 | const ConstString &name) { |
| 1100 | if (name) { |
| 1101 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1102 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1103 | |
| 1104 | ObjectFileInstances::iterator pos, end = instances.end(); |
| 1105 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1106 | if (name == pos->name) |
| 1107 | return pos->create_memory_callback; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1108 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1109 | } |
| 1110 | return nullptr; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1113 | Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp, |
| 1114 | const FileSpec &outfile) { |
| 1115 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1116 | std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); |
| 1117 | ObjectFileInstances &instances = GetObjectFileInstances(); |
| 1118 | |
| 1119 | ObjectFileInstances::iterator pos, end = instances.end(); |
| 1120 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1121 | if (pos->save_core && pos->save_core(process_sp, outfile, error)) |
| 1122 | return error; |
| 1123 | } |
| 1124 | error.SetErrorString( |
| 1125 | "no ObjectFile plugins were able to save a core for this process"); |
| 1126 | return error; |
Greg Clayton | a2715cf | 2014-06-13 00:54:12 +0000 | [diff] [blame] | 1127 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1128 | |
| 1129 | #pragma mark ObjectContainer |
| 1130 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1131 | struct ObjectContainerInstance { |
| 1132 | ObjectContainerInstance() |
| 1133 | : name(), description(), create_callback(nullptr), |
| 1134 | get_module_specifications(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1135 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1136 | ConstString name; |
| 1137 | std::string description; |
| 1138 | ObjectContainerCreateInstance create_callback; |
| 1139 | ObjectFileGetModuleSpecifications get_module_specifications; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1140 | }; |
| 1141 | |
| 1142 | typedef std::vector<ObjectContainerInstance> ObjectContainerInstances; |
| 1143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1144 | static std::recursive_mutex &GetObjectContainerMutex() { |
| 1145 | static std::recursive_mutex g_instances_mutex; |
| 1146 | return g_instances_mutex; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1149 | static ObjectContainerInstances &GetObjectContainerInstances() { |
| 1150 | static ObjectContainerInstances g_instances; |
| 1151 | return g_instances; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1152 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1154 | bool PluginManager::RegisterPlugin( |
| 1155 | const ConstString &name, const char *description, |
| 1156 | ObjectContainerCreateInstance create_callback, |
| 1157 | ObjectFileGetModuleSpecifications get_module_specifications) { |
| 1158 | if (create_callback) { |
| 1159 | ObjectContainerInstance instance; |
| 1160 | assert((bool)name); |
| 1161 | instance.name = name; |
| 1162 | if (description && description[0]) |
| 1163 | instance.description = description; |
| 1164 | instance.create_callback = create_callback; |
| 1165 | instance.get_module_specifications = get_module_specifications; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1166 | std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1167 | GetObjectContainerInstances().push_back(instance); |
| 1168 | } |
| 1169 | return false; |
| 1170 | } |
| 1171 | |
| 1172 | bool PluginManager::UnregisterPlugin( |
| 1173 | ObjectContainerCreateInstance create_callback) { |
| 1174 | if (create_callback) { |
| 1175 | std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); |
| 1176 | ObjectContainerInstances &instances = GetObjectContainerInstances(); |
| 1177 | |
| 1178 | ObjectContainerInstances::iterator pos, end = instances.end(); |
| 1179 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1180 | if (pos->create_callback == create_callback) { |
| 1181 | instances.erase(pos); |
| 1182 | return true; |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | } |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1188 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1189 | ObjectContainerCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1190 | PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) { |
| 1191 | std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); |
| 1192 | ObjectContainerInstances &instances = GetObjectContainerInstances(); |
| 1193 | if (idx < instances.size()) |
| 1194 | return instances[idx].create_callback; |
| 1195 | return nullptr; |
| 1196 | } |
| 1197 | |
| 1198 | ObjectContainerCreateInstance |
| 1199 | PluginManager::GetObjectContainerCreateCallbackForPluginName( |
| 1200 | const ConstString &name) { |
| 1201 | if (name) { |
| 1202 | std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); |
| 1203 | ObjectContainerInstances &instances = GetObjectContainerInstances(); |
| 1204 | |
| 1205 | ObjectContainerInstances::iterator pos, end = instances.end(); |
| 1206 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1207 | if (name == pos->name) |
| 1208 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1210 | } |
| 1211 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 1214 | ObjectFileGetModuleSpecifications |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1215 | PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex( |
| 1216 | uint32_t idx) { |
| 1217 | std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); |
| 1218 | ObjectContainerInstances &instances = GetObjectContainerInstances(); |
| 1219 | if (idx < instances.size()) |
| 1220 | return instances[idx].get_module_specifications; |
| 1221 | return nullptr; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1224 | #pragma mark Platform |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1225 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1226 | struct PlatformInstance { |
| 1227 | PlatformInstance() |
| 1228 | : name(), description(), create_callback(nullptr), |
| 1229 | debugger_init_callback(nullptr) {} |
| 1230 | |
| 1231 | ConstString name; |
| 1232 | std::string description; |
| 1233 | PlatformCreateInstance create_callback; |
| 1234 | DebuggerInitializeCallback debugger_init_callback; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1235 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1236 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1237 | typedef std::vector<PlatformInstance> PlatformInstances; |
| 1238 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1239 | static std::recursive_mutex &GetPlatformInstancesMutex() { |
| 1240 | static std::recursive_mutex g_platform_instances_mutex; |
| 1241 | return g_platform_instances_mutex; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1244 | static PlatformInstances &GetPlatformInstances() { |
| 1245 | static PlatformInstances g_platform_instances; |
| 1246 | return g_platform_instances; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1247 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1248 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1249 | bool PluginManager::RegisterPlugin( |
| 1250 | const ConstString &name, const char *description, |
| 1251 | PlatformCreateInstance create_callback, |
| 1252 | DebuggerInitializeCallback debugger_init_callback) { |
| 1253 | if (create_callback) { |
| 1254 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1255 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1256 | PlatformInstance instance; |
| 1257 | assert((bool)name); |
| 1258 | instance.name = name; |
| 1259 | if (description && description[0]) |
| 1260 | instance.description = description; |
| 1261 | instance.create_callback = create_callback; |
| 1262 | instance.debugger_init_callback = debugger_init_callback; |
| 1263 | GetPlatformInstances().push_back(instance); |
| 1264 | return true; |
| 1265 | } |
| 1266 | return false; |
| 1267 | } |
| 1268 | |
| 1269 | const char *PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) { |
| 1270 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1271 | PlatformInstances &instances = GetPlatformInstances(); |
| 1272 | if (idx < instances.size()) |
| 1273 | return instances[idx].name.GetCString(); |
| 1274 | return nullptr; |
| 1275 | } |
| 1276 | |
| 1277 | const char *PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) { |
| 1278 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1279 | PlatformInstances &instances = GetPlatformInstances(); |
| 1280 | if (idx < instances.size()) |
| 1281 | return instances[idx].description.c_str(); |
| 1282 | return nullptr; |
| 1283 | } |
| 1284 | |
| 1285 | bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) { |
| 1286 | if (create_callback) { |
| 1287 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1288 | PlatformInstances &instances = GetPlatformInstances(); |
| 1289 | |
| 1290 | PlatformInstances::iterator pos, end = instances.end(); |
| 1291 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1292 | if (pos->create_callback == create_callback) { |
| 1293 | instances.erase(pos); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1294 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1295 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1296 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1297 | } |
| 1298 | return false; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | PlatformCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1302 | PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) { |
| 1303 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1304 | PlatformInstances &instances = GetPlatformInstances(); |
| 1305 | if (idx < instances.size()) |
| 1306 | return instances[idx].create_callback; |
| 1307 | return nullptr; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | PlatformCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1311 | PluginManager::GetPlatformCreateCallbackForPluginName(const ConstString &name) { |
| 1312 | if (name) { |
| 1313 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1314 | PlatformInstances &instances = GetPlatformInstances(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1315 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1316 | PlatformInstances::iterator pos, end = instances.end(); |
| 1317 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1318 | if (name == pos->name) |
| 1319 | return pos->create_callback; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1320 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1321 | } |
| 1322 | return nullptr; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Zachary Turner | 4aa8753 | 2016-11-17 01:37:42 +0000 | [diff] [blame] | 1325 | size_t PluginManager::AutoCompletePlatformName(llvm::StringRef name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1326 | StringList &matches) { |
Zachary Turner | 4aa8753 | 2016-11-17 01:37:42 +0000 | [diff] [blame] | 1327 | if (name.empty()) |
| 1328 | return matches.GetSize(); |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1329 | |
Zachary Turner | 4aa8753 | 2016-11-17 01:37:42 +0000 | [diff] [blame] | 1330 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 1331 | PlatformInstances &instances = GetPlatformInstances(); |
| 1332 | llvm::StringRef name_sref(name); |
| 1333 | |
| 1334 | PlatformInstances::iterator pos, end = instances.end(); |
| 1335 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1336 | llvm::StringRef plugin_name(pos->name.GetCString()); |
| 1337 | if (plugin_name.startswith(name_sref)) |
| 1338 | matches.AppendString(plugin_name.data()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1339 | } |
| 1340 | return matches.GetSize(); |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1341 | } |
Eugene Zelenko | 8918372 | 2016-03-11 21:55:47 +0000 | [diff] [blame] | 1342 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1343 | #pragma mark Process |
| 1344 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1345 | struct ProcessInstance { |
| 1346 | ProcessInstance() |
| 1347 | : name(), description(), create_callback(nullptr), |
| 1348 | debugger_init_callback(nullptr) {} |
| 1349 | |
| 1350 | ConstString name; |
| 1351 | std::string description; |
| 1352 | ProcessCreateInstance create_callback; |
| 1353 | DebuggerInitializeCallback debugger_init_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | }; |
| 1355 | |
| 1356 | typedef std::vector<ProcessInstance> ProcessInstances; |
| 1357 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1358 | static std::recursive_mutex &GetProcessMutex() { |
| 1359 | static std::recursive_mutex g_instances_mutex; |
| 1360 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1363 | static ProcessInstances &GetProcessInstances() { |
| 1364 | static ProcessInstances g_instances; |
| 1365 | return g_instances; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1368 | bool PluginManager::RegisterPlugin( |
| 1369 | const ConstString &name, const char *description, |
| 1370 | ProcessCreateInstance create_callback, |
| 1371 | DebuggerInitializeCallback debugger_init_callback) { |
| 1372 | if (create_callback) { |
| 1373 | ProcessInstance instance; |
| 1374 | assert((bool)name); |
| 1375 | instance.name = name; |
| 1376 | if (description && description[0]) |
| 1377 | instance.description = description; |
| 1378 | instance.create_callback = create_callback; |
| 1379 | instance.debugger_init_callback = debugger_init_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1380 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1381 | GetProcessInstances().push_back(instance); |
| 1382 | } |
| 1383 | return false; |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1386 | const char *PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) { |
| 1387 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
| 1388 | ProcessInstances &instances = GetProcessInstances(); |
| 1389 | if (idx < instances.size()) |
| 1390 | return instances[idx].name.GetCString(); |
| 1391 | return nullptr; |
| 1392 | } |
| 1393 | |
| 1394 | const char *PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) { |
| 1395 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
| 1396 | ProcessInstances &instances = GetProcessInstances(); |
| 1397 | if (idx < instances.size()) |
| 1398 | return instances[idx].description.c_str(); |
| 1399 | return nullptr; |
| 1400 | } |
| 1401 | |
| 1402 | bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) { |
| 1403 | if (create_callback) { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1404 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1405 | ProcessInstances &instances = GetProcessInstances(); |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 1406 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1407 | ProcessInstances::iterator pos, end = instances.end(); |
| 1408 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1409 | if (pos->create_callback == create_callback) { |
| 1410 | instances.erase(pos); |
| 1411 | return true; |
| 1412 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1413 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1414 | } |
| 1415 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | ProcessCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1419 | PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) { |
| 1420 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
| 1421 | ProcessInstances &instances = GetProcessInstances(); |
| 1422 | if (idx < instances.size()) |
| 1423 | return instances[idx].create_callback; |
| 1424 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | ProcessCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1428 | PluginManager::GetProcessCreateCallbackForPluginName(const ConstString &name) { |
| 1429 | if (name) { |
| 1430 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
| 1431 | ProcessInstances &instances = GetProcessInstances(); |
| 1432 | |
| 1433 | ProcessInstances::iterator pos, end = instances.end(); |
| 1434 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1435 | if (name == pos->name) |
| 1436 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1437 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1438 | } |
| 1439 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1442 | #pragma mark ScriptInterpreter |
| 1443 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1444 | struct ScriptInterpreterInstance { |
| 1445 | ScriptInterpreterInstance() |
| 1446 | : name(), language(lldb::eScriptLanguageNone), description(), |
| 1447 | create_callback(nullptr) {} |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1448 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1449 | ConstString name; |
| 1450 | lldb::ScriptLanguage language; |
| 1451 | std::string description; |
| 1452 | ScriptInterpreterCreateInstance create_callback; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1453 | }; |
| 1454 | |
| 1455 | typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances; |
| 1456 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1457 | static std::recursive_mutex &GetScriptInterpreterMutex() { |
| 1458 | static std::recursive_mutex g_instances_mutex; |
| 1459 | return g_instances_mutex; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1462 | static ScriptInterpreterInstances &GetScriptInterpreterInstances() { |
| 1463 | static ScriptInterpreterInstances g_instances; |
| 1464 | return g_instances; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1467 | bool PluginManager::RegisterPlugin( |
| 1468 | const ConstString &name, const char *description, |
| 1469 | lldb::ScriptLanguage script_language, |
| 1470 | ScriptInterpreterCreateInstance create_callback) { |
| 1471 | if (!create_callback) |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1472 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1473 | ScriptInterpreterInstance instance; |
| 1474 | assert((bool)name); |
| 1475 | instance.name = name; |
| 1476 | if (description && description[0]) |
| 1477 | instance.description = description; |
| 1478 | instance.create_callback = create_callback; |
| 1479 | instance.language = script_language; |
| 1480 | std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); |
| 1481 | GetScriptInterpreterInstances().push_back(instance); |
| 1482 | return false; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1485 | bool PluginManager::UnregisterPlugin( |
| 1486 | ScriptInterpreterCreateInstance create_callback) { |
| 1487 | if (!create_callback) |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1488 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1489 | std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); |
| 1490 | ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); |
| 1491 | |
| 1492 | ScriptInterpreterInstances::iterator pos, end = instances.end(); |
| 1493 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1494 | if (pos->create_callback != create_callback) |
| 1495 | continue; |
| 1496 | |
| 1497 | instances.erase(pos); |
| 1498 | return true; |
| 1499 | } |
| 1500 | return false; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | ScriptInterpreterCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1504 | PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) { |
| 1505 | std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); |
| 1506 | ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); |
| 1507 | if (idx < instances.size()) |
| 1508 | return instances[idx].create_callback; |
| 1509 | return nullptr; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1512 | lldb::ScriptInterpreterSP PluginManager::GetScriptInterpreterForLanguage( |
| 1513 | lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) { |
| 1514 | std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); |
| 1515 | ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1516 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1517 | ScriptInterpreterInstances::iterator pos, end = instances.end(); |
| 1518 | ScriptInterpreterCreateInstance none_instance = nullptr; |
| 1519 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1520 | if (pos->language == lldb::eScriptLanguageNone) |
| 1521 | none_instance = pos->create_callback; |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1522 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1523 | if (script_lang == pos->language) |
| 1524 | return pos->create_callback(interpreter); |
| 1525 | } |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1526 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1527 | // If we didn't find one, return the ScriptInterpreter for the null language. |
| 1528 | assert(none_instance != nullptr); |
| 1529 | return none_instance(interpreter); |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1532 | #pragma mark - |
| 1533 | #pragma mark StructuredDataPlugin |
| 1534 | |
| 1535 | // ----------------------------------------------------------------------------- |
| 1536 | // StructuredDataPlugin |
| 1537 | // ----------------------------------------------------------------------------- |
| 1538 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1539 | struct StructuredDataPluginInstance { |
| 1540 | StructuredDataPluginInstance() |
| 1541 | : name(), description(), create_callback(nullptr), |
| 1542 | debugger_init_callback(nullptr), filter_callback(nullptr) {} |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1544 | ConstString name; |
| 1545 | std::string description; |
| 1546 | StructuredDataPluginCreateInstance create_callback; |
| 1547 | DebuggerInitializeCallback debugger_init_callback; |
| 1548 | StructuredDataFilterLaunchInfo filter_callback; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1549 | }; |
| 1550 | |
| 1551 | typedef std::vector<StructuredDataPluginInstance> StructuredDataPluginInstances; |
| 1552 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1553 | static std::recursive_mutex &GetStructuredDataPluginMutex() { |
| 1554 | static std::recursive_mutex g_instances_mutex; |
| 1555 | return g_instances_mutex; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1558 | static StructuredDataPluginInstances &GetStructuredDataPluginInstances() { |
| 1559 | static StructuredDataPluginInstances g_instances; |
| 1560 | return g_instances; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1563 | bool PluginManager::RegisterPlugin( |
| 1564 | const ConstString &name, const char *description, |
| 1565 | StructuredDataPluginCreateInstance create_callback, |
| 1566 | DebuggerInitializeCallback debugger_init_callback, |
| 1567 | StructuredDataFilterLaunchInfo filter_callback) { |
| 1568 | if (create_callback) { |
| 1569 | StructuredDataPluginInstance instance; |
| 1570 | assert((bool)name); |
| 1571 | instance.name = name; |
| 1572 | if (description && description[0]) |
| 1573 | instance.description = description; |
| 1574 | instance.create_callback = create_callback; |
| 1575 | instance.debugger_init_callback = debugger_init_callback; |
| 1576 | instance.filter_callback = filter_callback; |
| 1577 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 1578 | GetStructuredDataPluginInstances().push_back(instance); |
| 1579 | } |
| 1580 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1583 | bool PluginManager::UnregisterPlugin( |
| 1584 | StructuredDataPluginCreateInstance create_callback) { |
| 1585 | if (create_callback) { |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1586 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 1587 | StructuredDataPluginInstances &instances = |
| 1588 | GetStructuredDataPluginInstances(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1589 | |
| 1590 | StructuredDataPluginInstances::iterator pos, end = instances.end(); |
| 1591 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1592 | if (pos->create_callback == create_callback) { |
| 1593 | instances.erase(pos); |
| 1594 | return true; |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | return false; |
| 1599 | } |
| 1600 | |
| 1601 | StructuredDataPluginCreateInstance |
| 1602 | PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) { |
| 1603 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 1604 | StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances(); |
| 1605 | if (idx < instances.size()) |
| 1606 | return instances[idx].create_callback; |
| 1607 | return nullptr; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | StructuredDataPluginCreateInstance |
| 1611 | PluginManager::GetStructuredDataPluginCreateCallbackForPluginName( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1612 | const ConstString &name) { |
| 1613 | if (name) { |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1614 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 1615 | StructuredDataPluginInstances &instances = |
| 1616 | GetStructuredDataPluginInstances(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1617 | |
| 1618 | StructuredDataPluginInstances::iterator pos, end = instances.end(); |
| 1619 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1620 | if (name == pos->name) |
| 1621 | return pos->create_callback; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1622 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1623 | } |
| 1624 | return nullptr; |
| 1625 | } |
| 1626 | |
| 1627 | StructuredDataFilterLaunchInfo |
| 1628 | PluginManager::GetStructuredDataFilterCallbackAtIndex( |
| 1629 | uint32_t idx, bool &iteration_complete) { |
| 1630 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 1631 | StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances(); |
| 1632 | if (idx < instances.size()) { |
| 1633 | iteration_complete = false; |
| 1634 | return instances[idx].filter_callback; |
| 1635 | } else { |
| 1636 | iteration_complete = true; |
| 1637 | } |
| 1638 | return nullptr; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1641 | #pragma mark SymbolFile |
| 1642 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1643 | struct SymbolFileInstance { |
| 1644 | SymbolFileInstance() |
| 1645 | : name(), description(), create_callback(nullptr), |
| 1646 | debugger_init_callback(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1647 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1648 | ConstString name; |
| 1649 | std::string description; |
| 1650 | SymbolFileCreateInstance create_callback; |
| 1651 | DebuggerInitializeCallback debugger_init_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1652 | }; |
| 1653 | |
| 1654 | typedef std::vector<SymbolFileInstance> SymbolFileInstances; |
| 1655 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1656 | static std::recursive_mutex &GetSymbolFileMutex() { |
| 1657 | static std::recursive_mutex g_instances_mutex; |
| 1658 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1659 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1660 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1661 | static SymbolFileInstances &GetSymbolFileInstances() { |
| 1662 | static SymbolFileInstances g_instances; |
| 1663 | return g_instances; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1666 | bool PluginManager::RegisterPlugin( |
| 1667 | const ConstString &name, const char *description, |
| 1668 | SymbolFileCreateInstance create_callback, |
| 1669 | DebuggerInitializeCallback debugger_init_callback) { |
| 1670 | if (create_callback) { |
| 1671 | SymbolFileInstance instance; |
| 1672 | assert((bool)name); |
| 1673 | instance.name = name; |
| 1674 | if (description && description[0]) |
| 1675 | instance.description = description; |
| 1676 | instance.create_callback = create_callback; |
| 1677 | instance.debugger_init_callback = debugger_init_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1678 | std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1679 | GetSymbolFileInstances().push_back(instance); |
| 1680 | } |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) { |
| 1685 | if (create_callback) { |
| 1686 | std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); |
| 1687 | SymbolFileInstances &instances = GetSymbolFileInstances(); |
| 1688 | |
| 1689 | SymbolFileInstances::iterator pos, end = instances.end(); |
| 1690 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1691 | if (pos->create_callback == create_callback) { |
| 1692 | instances.erase(pos); |
| 1693 | return true; |
| 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1698 | } |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1699 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1700 | SymbolFileCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1701 | PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) { |
| 1702 | std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); |
| 1703 | SymbolFileInstances &instances = GetSymbolFileInstances(); |
| 1704 | if (idx < instances.size()) |
| 1705 | return instances[idx].create_callback; |
| 1706 | return nullptr; |
| 1707 | } |
| 1708 | |
| 1709 | SymbolFileCreateInstance |
| 1710 | PluginManager::GetSymbolFileCreateCallbackForPluginName( |
| 1711 | const ConstString &name) { |
| 1712 | if (name) { |
| 1713 | std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); |
| 1714 | SymbolFileInstances &instances = GetSymbolFileInstances(); |
| 1715 | |
| 1716 | SymbolFileInstances::iterator pos, end = instances.end(); |
| 1717 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1718 | if (name == pos->name) |
| 1719 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1720 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1721 | } |
| 1722 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1725 | #pragma mark SymbolVendor |
| 1726 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1727 | struct SymbolVendorInstance { |
| 1728 | SymbolVendorInstance() : name(), description(), create_callback(nullptr) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1729 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1730 | ConstString name; |
| 1731 | std::string description; |
| 1732 | SymbolVendorCreateInstance create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1733 | }; |
| 1734 | |
| 1735 | typedef std::vector<SymbolVendorInstance> SymbolVendorInstances; |
| 1736 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1737 | static std::recursive_mutex &GetSymbolVendorMutex() { |
| 1738 | static std::recursive_mutex g_instances_mutex; |
| 1739 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1740 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1741 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1742 | static SymbolVendorInstances &GetSymbolVendorInstances() { |
| 1743 | static SymbolVendorInstances g_instances; |
| 1744 | return g_instances; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1747 | bool PluginManager::RegisterPlugin(const ConstString &name, |
| 1748 | const char *description, |
| 1749 | SymbolVendorCreateInstance create_callback) { |
| 1750 | if (create_callback) { |
| 1751 | SymbolVendorInstance instance; |
| 1752 | assert((bool)name); |
| 1753 | instance.name = name; |
| 1754 | if (description && description[0]) |
| 1755 | instance.description = description; |
| 1756 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1757 | std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1758 | GetSymbolVendorInstances().push_back(instance); |
| 1759 | } |
| 1760 | return false; |
| 1761 | } |
| 1762 | |
| 1763 | bool PluginManager::UnregisterPlugin( |
| 1764 | SymbolVendorCreateInstance create_callback) { |
| 1765 | if (create_callback) { |
| 1766 | std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); |
| 1767 | SymbolVendorInstances &instances = GetSymbolVendorInstances(); |
| 1768 | |
| 1769 | SymbolVendorInstances::iterator pos, end = instances.end(); |
| 1770 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1771 | if (pos->create_callback == create_callback) { |
| 1772 | instances.erase(pos); |
| 1773 | return true; |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | SymbolVendorCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1781 | PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) { |
| 1782 | std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); |
| 1783 | SymbolVendorInstances &instances = GetSymbolVendorInstances(); |
| 1784 | if (idx < instances.size()) |
| 1785 | return instances[idx].create_callback; |
| 1786 | return nullptr; |
| 1787 | } |
| 1788 | |
| 1789 | SymbolVendorCreateInstance |
| 1790 | PluginManager::GetSymbolVendorCreateCallbackForPluginName( |
| 1791 | const ConstString &name) { |
| 1792 | if (name) { |
| 1793 | std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); |
| 1794 | SymbolVendorInstances &instances = GetSymbolVendorInstances(); |
| 1795 | |
| 1796 | SymbolVendorInstances::iterator pos, end = instances.end(); |
| 1797 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1798 | if (name == pos->name) |
| 1799 | return pos->create_callback; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1800 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1801 | } |
| 1802 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 1805 | #pragma mark UnwindAssembly |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1806 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1807 | struct UnwindAssemblyInstance { |
| 1808 | UnwindAssemblyInstance() : name(), description(), create_callback(nullptr) {} |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1809 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1810 | ConstString name; |
| 1811 | std::string description; |
| 1812 | UnwindAssemblyCreateInstance create_callback; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1813 | }; |
| 1814 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 1815 | typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1816 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1817 | static std::recursive_mutex &GetUnwindAssemblyMutex() { |
| 1818 | static std::recursive_mutex g_instances_mutex; |
| 1819 | return g_instances_mutex; |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 1820 | } |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1821 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1822 | static UnwindAssemblyInstances &GetUnwindAssemblyInstances() { |
| 1823 | static UnwindAssemblyInstances g_instances; |
| 1824 | return g_instances; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1827 | bool PluginManager::RegisterPlugin( |
| 1828 | const ConstString &name, const char *description, |
| 1829 | UnwindAssemblyCreateInstance create_callback) { |
| 1830 | if (create_callback) { |
| 1831 | UnwindAssemblyInstance instance; |
| 1832 | assert((bool)name); |
| 1833 | instance.name = name; |
| 1834 | if (description && description[0]) |
| 1835 | instance.description = description; |
| 1836 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1837 | std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1838 | GetUnwindAssemblyInstances().push_back(instance); |
| 1839 | } |
| 1840 | return false; |
| 1841 | } |
| 1842 | |
| 1843 | bool PluginManager::UnregisterPlugin( |
| 1844 | UnwindAssemblyCreateInstance create_callback) { |
| 1845 | if (create_callback) { |
| 1846 | std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); |
| 1847 | UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances(); |
| 1848 | |
| 1849 | UnwindAssemblyInstances::iterator pos, end = instances.end(); |
| 1850 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1851 | if (pos->create_callback == create_callback) { |
| 1852 | instances.erase(pos); |
| 1853 | return true; |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | return false; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 1860 | UnwindAssemblyCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1861 | PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) { |
| 1862 | std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); |
| 1863 | UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances(); |
| 1864 | if (idx < instances.size()) |
| 1865 | return instances[idx].create_callback; |
| 1866 | return nullptr; |
| 1867 | } |
| 1868 | |
| 1869 | UnwindAssemblyCreateInstance |
| 1870 | PluginManager::GetUnwindAssemblyCreateCallbackForPluginName( |
| 1871 | const ConstString &name) { |
| 1872 | if (name) { |
| 1873 | std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); |
| 1874 | UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances(); |
| 1875 | |
| 1876 | UnwindAssemblyInstances::iterator pos, end = instances.end(); |
| 1877 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1878 | if (name == pos->name) |
| 1879 | return pos->create_callback; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1880 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1881 | } |
| 1882 | return nullptr; |
Jason Molenda | fbcb7f2 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1885 | #pragma mark MemoryHistory |
| 1886 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1887 | struct MemoryHistoryInstance { |
| 1888 | MemoryHistoryInstance() : name(), description(), create_callback(nullptr) {} |
| 1889 | |
| 1890 | ConstString name; |
| 1891 | std::string description; |
| 1892 | MemoryHistoryCreateInstance create_callback; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1893 | }; |
| 1894 | |
| 1895 | typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances; |
| 1896 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1897 | static std::recursive_mutex &GetMemoryHistoryMutex() { |
| 1898 | static std::recursive_mutex g_instances_mutex; |
| 1899 | return g_instances_mutex; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1902 | static MemoryHistoryInstances &GetMemoryHistoryInstances() { |
| 1903 | static MemoryHistoryInstances g_instances; |
| 1904 | return g_instances; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1907 | bool PluginManager::RegisterPlugin( |
| 1908 | const ConstString &name, const char *description, |
| 1909 | MemoryHistoryCreateInstance create_callback) { |
| 1910 | if (create_callback) { |
| 1911 | MemoryHistoryInstance instance; |
| 1912 | assert((bool)name); |
| 1913 | instance.name = name; |
| 1914 | if (description && description[0]) |
| 1915 | instance.description = description; |
| 1916 | instance.create_callback = create_callback; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1917 | std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1918 | GetMemoryHistoryInstances().push_back(instance); |
| 1919 | } |
| 1920 | return false; |
| 1921 | } |
| 1922 | |
| 1923 | bool PluginManager::UnregisterPlugin( |
| 1924 | MemoryHistoryCreateInstance create_callback) { |
| 1925 | if (create_callback) { |
| 1926 | std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); |
| 1927 | MemoryHistoryInstances &instances = GetMemoryHistoryInstances(); |
| 1928 | |
| 1929 | MemoryHistoryInstances::iterator pos, end = instances.end(); |
| 1930 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1931 | if (pos->create_callback == create_callback) { |
| 1932 | instances.erase(pos); |
| 1933 | return true; |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | return false; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1940 | MemoryHistoryCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1941 | PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) { |
| 1942 | std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); |
| 1943 | MemoryHistoryInstances &instances = GetMemoryHistoryInstances(); |
| 1944 | if (idx < instances.size()) |
| 1945 | return instances[idx].create_callback; |
| 1946 | return nullptr; |
| 1947 | } |
| 1948 | |
| 1949 | MemoryHistoryCreateInstance |
| 1950 | PluginManager::GetMemoryHistoryCreateCallbackForPluginName( |
| 1951 | const ConstString &name) { |
| 1952 | if (name) { |
| 1953 | std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); |
| 1954 | MemoryHistoryInstances &instances = GetMemoryHistoryInstances(); |
| 1955 | |
| 1956 | MemoryHistoryInstances::iterator pos, end = instances.end(); |
| 1957 | for (pos = instances.begin(); pos != end; ++pos) { |
| 1958 | if (name == pos->name) |
| 1959 | return pos->create_callback; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1960 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1961 | } |
| 1962 | return nullptr; |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 1965 | #pragma mark InstrumentationRuntime |
| 1966 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1967 | struct InstrumentationRuntimeInstance { |
| 1968 | InstrumentationRuntimeInstance() |
| 1969 | : name(), description(), create_callback(nullptr) {} |
| 1970 | |
| 1971 | ConstString name; |
| 1972 | std::string description; |
| 1973 | InstrumentationRuntimeCreateInstance create_callback; |
| 1974 | InstrumentationRuntimeGetType get_type_callback; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 1975 | }; |
| 1976 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1977 | typedef std::vector<InstrumentationRuntimeInstance> |
| 1978 | InstrumentationRuntimeInstances; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 1979 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1980 | static std::recursive_mutex &GetInstrumentationRuntimeMutex() { |
| 1981 | static std::recursive_mutex g_instances_mutex; |
| 1982 | return g_instances_mutex; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1985 | static InstrumentationRuntimeInstances &GetInstrumentationRuntimeInstances() { |
| 1986 | static InstrumentationRuntimeInstances g_instances; |
| 1987 | return g_instances; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1990 | bool PluginManager::RegisterPlugin( |
| 1991 | const ConstString &name, const char *description, |
| 1992 | InstrumentationRuntimeCreateInstance create_callback, |
| 1993 | InstrumentationRuntimeGetType get_type_callback) { |
| 1994 | if (create_callback) { |
| 1995 | InstrumentationRuntimeInstance instance; |
| 1996 | assert((bool)name); |
| 1997 | instance.name = name; |
| 1998 | if (description && description[0]) |
| 1999 | instance.description = description; |
| 2000 | instance.create_callback = create_callback; |
| 2001 | instance.get_type_callback = get_type_callback; |
| 2002 | std::lock_guard<std::recursive_mutex> guard( |
| 2003 | GetInstrumentationRuntimeMutex()); |
| 2004 | GetInstrumentationRuntimeInstances().push_back(instance); |
| 2005 | } |
| 2006 | return false; |
| 2007 | } |
| 2008 | |
| 2009 | bool PluginManager::UnregisterPlugin( |
| 2010 | InstrumentationRuntimeCreateInstance create_callback) { |
| 2011 | if (create_callback) { |
| 2012 | std::lock_guard<std::recursive_mutex> guard( |
| 2013 | GetInstrumentationRuntimeMutex()); |
| 2014 | InstrumentationRuntimeInstances &instances = |
| 2015 | GetInstrumentationRuntimeInstances(); |
| 2016 | |
| 2017 | InstrumentationRuntimeInstances::iterator pos, end = instances.end(); |
| 2018 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2019 | if (pos->create_callback == create_callback) { |
| 2020 | instances.erase(pos); |
| 2021 | return true; |
| 2022 | } |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2023 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2024 | } |
| 2025 | return false; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | InstrumentationRuntimeGetType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2029 | PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) { |
| 2030 | std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); |
| 2031 | InstrumentationRuntimeInstances &instances = |
| 2032 | GetInstrumentationRuntimeInstances(); |
| 2033 | if (idx < instances.size()) |
| 2034 | return instances[idx].get_type_callback; |
| 2035 | return nullptr; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | InstrumentationRuntimeCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2039 | PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) { |
| 2040 | std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); |
| 2041 | InstrumentationRuntimeInstances &instances = |
| 2042 | GetInstrumentationRuntimeInstances(); |
| 2043 | if (idx < instances.size()) |
| 2044 | return instances[idx].create_callback; |
| 2045 | return nullptr; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2048 | InstrumentationRuntimeCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2049 | PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName( |
| 2050 | const ConstString &name) { |
| 2051 | if (name) { |
| 2052 | std::lock_guard<std::recursive_mutex> guard( |
| 2053 | GetInstrumentationRuntimeMutex()); |
| 2054 | InstrumentationRuntimeInstances &instances = |
| 2055 | GetInstrumentationRuntimeInstances(); |
| 2056 | |
| 2057 | InstrumentationRuntimeInstances::iterator pos, end = instances.end(); |
| 2058 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2059 | if (name == pos->name) |
| 2060 | return pos->create_callback; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2061 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2062 | } |
| 2063 | return nullptr; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2066 | #pragma mark TypeSystem |
| 2067 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2068 | struct TypeSystemInstance { |
| 2069 | TypeSystemInstance() : name(), description(), create_callback(nullptr) {} |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2070 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2071 | ConstString name; |
| 2072 | std::string description; |
| 2073 | TypeSystemCreateInstance create_callback; |
| 2074 | TypeSystemEnumerateSupportedLanguages enumerate_callback; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2075 | }; |
| 2076 | |
| 2077 | typedef std::vector<TypeSystemInstance> TypeSystemInstances; |
| 2078 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2079 | static std::recursive_mutex &GetTypeSystemMutex() { |
| 2080 | static std::recursive_mutex g_instances_mutex; |
| 2081 | return g_instances_mutex; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2084 | static TypeSystemInstances &GetTypeSystemInstances() { |
| 2085 | static TypeSystemInstances g_instances; |
| 2086 | return g_instances; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2089 | bool PluginManager::RegisterPlugin(const ConstString &name, |
| 2090 | const char *description, |
| 2091 | TypeSystemCreateInstance create_callback, |
| 2092 | TypeSystemEnumerateSupportedLanguages |
| 2093 | enumerate_supported_languages_callback) { |
| 2094 | if (create_callback) { |
| 2095 | TypeSystemInstance instance; |
| 2096 | assert((bool)name); |
| 2097 | instance.name = name; |
| 2098 | if (description && description[0]) |
| 2099 | instance.description = description; |
| 2100 | instance.create_callback = create_callback; |
| 2101 | instance.enumerate_callback = enumerate_supported_languages_callback; |
| 2102 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
| 2103 | GetTypeSystemInstances().push_back(instance); |
| 2104 | } |
| 2105 | return false; |
| 2106 | } |
| 2107 | |
| 2108 | bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) { |
| 2109 | if (create_callback) { |
| 2110 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
| 2111 | TypeSystemInstances &instances = GetTypeSystemInstances(); |
| 2112 | |
| 2113 | TypeSystemInstances::iterator pos, end = instances.end(); |
| 2114 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2115 | if (pos->create_callback == create_callback) { |
| 2116 | instances.erase(pos); |
| 2117 | return true; |
| 2118 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2119 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2120 | } |
| 2121 | return false; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | TypeSystemCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2125 | PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) { |
| 2126 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
| 2127 | TypeSystemInstances &instances = GetTypeSystemInstances(); |
| 2128 | if (idx < instances.size()) |
| 2129 | return instances[idx].create_callback; |
| 2130 | return nullptr; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | TypeSystemCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2134 | PluginManager::GetTypeSystemCreateCallbackForPluginName( |
| 2135 | const ConstString &name) { |
| 2136 | if (name) { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 2137 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2138 | TypeSystemInstances &instances = GetTypeSystemInstances(); |
| 2139 | |
| 2140 | TypeSystemInstances::iterator pos, end = instances.end(); |
| 2141 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2142 | if (name == pos->name) |
| 2143 | return pos->create_callback; |
| 2144 | } |
| 2145 | } |
| 2146 | return nullptr; |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | TypeSystemEnumerateSupportedLanguages |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2150 | PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex( |
| 2151 | uint32_t idx) { |
| 2152 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
| 2153 | TypeSystemInstances &instances = GetTypeSystemInstances(); |
| 2154 | if (idx < instances.size()) |
| 2155 | return instances[idx].enumerate_callback; |
| 2156 | return nullptr; |
| 2157 | } |
| 2158 | |
| 2159 | TypeSystemEnumerateSupportedLanguages |
| 2160 | PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName( |
| 2161 | const ConstString &name) { |
| 2162 | if (name) { |
| 2163 | std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); |
| 2164 | TypeSystemInstances &instances = GetTypeSystemInstances(); |
| 2165 | |
| 2166 | TypeSystemInstances::iterator pos, end = instances.end(); |
| 2167 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2168 | if (name == pos->name) |
| 2169 | return pos->enumerate_callback; |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 2170 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2171 | } |
| 2172 | return nullptr; |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 2173 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 2174 | |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2175 | #pragma mark REPL |
| 2176 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2177 | struct REPLInstance { |
| 2178 | REPLInstance() : name(), description(), create_callback(nullptr) {} |
| 2179 | |
| 2180 | ConstString name; |
| 2181 | std::string description; |
| 2182 | REPLCreateInstance create_callback; |
| 2183 | REPLEnumerateSupportedLanguages enumerate_languages_callback; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2184 | }; |
| 2185 | |
| 2186 | typedef std::vector<REPLInstance> REPLInstances; |
| 2187 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2188 | static std::recursive_mutex &GetREPLMutex() { |
| 2189 | static std::recursive_mutex g_instances_mutex; |
| 2190 | return g_instances_mutex; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2193 | static REPLInstances &GetREPLInstances() { |
| 2194 | static REPLInstances g_instances; |
| 2195 | return g_instances; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2198 | bool PluginManager::RegisterPlugin( |
| 2199 | const ConstString &name, const char *description, |
| 2200 | REPLCreateInstance create_callback, |
| 2201 | REPLEnumerateSupportedLanguages enumerate_languages_callback) { |
| 2202 | if (create_callback) { |
| 2203 | REPLInstance instance; |
| 2204 | assert((bool)name); |
| 2205 | instance.name = name; |
| 2206 | if (description && description[0]) |
| 2207 | instance.description = description; |
| 2208 | instance.create_callback = create_callback; |
| 2209 | instance.enumerate_languages_callback = enumerate_languages_callback; |
| 2210 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
| 2211 | GetREPLInstances().push_back(instance); |
| 2212 | } |
| 2213 | return false; |
| 2214 | } |
| 2215 | |
| 2216 | bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) { |
| 2217 | if (create_callback) { |
| 2218 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
| 2219 | REPLInstances &instances = GetREPLInstances(); |
| 2220 | |
| 2221 | REPLInstances::iterator pos, end = instances.end(); |
| 2222 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2223 | if (pos->create_callback == create_callback) { |
| 2224 | instances.erase(pos); |
| 2225 | return true; |
| 2226 | } |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2227 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2228 | } |
| 2229 | return false; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2232 | REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) { |
| 2233 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
| 2234 | REPLInstances &instances = GetREPLInstances(); |
| 2235 | if (idx < instances.size()) |
| 2236 | return instances[idx].create_callback; |
| 2237 | return nullptr; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | REPLCreateInstance |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2241 | PluginManager::GetREPLCreateCallbackForPluginName(const ConstString &name) { |
| 2242 | if (name) { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 2243 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2244 | REPLInstances &instances = GetREPLInstances(); |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2245 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2246 | REPLInstances::iterator pos, end = instances.end(); |
| 2247 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2248 | if (name == pos->name) |
| 2249 | return pos->create_callback; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2250 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2251 | } |
| 2252 | return nullptr; |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Sean Callanan | 93c0b00 | 2015-10-21 19:14:33 +0000 | [diff] [blame] | 2255 | REPLEnumerateSupportedLanguages |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2256 | PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx) { |
| 2257 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
| 2258 | REPLInstances &instances = GetREPLInstances(); |
| 2259 | if (idx < instances.size()) |
| 2260 | return instances[idx].enumerate_languages_callback; |
| 2261 | return nullptr; |
Sean Callanan | 93c0b00 | 2015-10-21 19:14:33 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
Sean Callanan | 93c0b00 | 2015-10-21 19:14:33 +0000 | [diff] [blame] | 2264 | REPLEnumerateSupportedLanguages |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2265 | PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName( |
| 2266 | const ConstString &name) { |
| 2267 | if (name) { |
| 2268 | std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); |
| 2269 | REPLInstances &instances = GetREPLInstances(); |
| 2270 | |
| 2271 | REPLInstances::iterator pos, end = instances.end(); |
| 2272 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2273 | if (name == pos->name) |
| 2274 | return pos->enumerate_languages_callback; |
Sean Callanan | 93c0b00 | 2015-10-21 19:14:33 +0000 | [diff] [blame] | 2275 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2276 | } |
| 2277 | return nullptr; |
Sean Callanan | 93c0b00 | 2015-10-21 19:14:33 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2280 | #pragma mark PluginManager |
| 2281 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2282 | void PluginManager::DebuggerInitialize(Debugger &debugger) { |
| 2283 | // Initialize the DynamicLoader plugins |
| 2284 | { |
| 2285 | std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); |
| 2286 | DynamicLoaderInstances &instances = GetDynamicLoaderInstances(); |
Jason Molenda | 9b837a1 | 2013-04-05 05:06:39 +0000 | [diff] [blame] | 2287 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2288 | DynamicLoaderInstances::iterator pos, end = instances.end(); |
| 2289 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2290 | if (pos->debugger_init_callback) |
| 2291 | pos->debugger_init_callback(debugger); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2292 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2293 | } |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2294 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2295 | // Initialize the JITLoader plugins |
| 2296 | { |
| 2297 | std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); |
| 2298 | JITLoaderInstances &instances = GetJITLoaderInstances(); |
Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 2299 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2300 | JITLoaderInstances::iterator pos, end = instances.end(); |
| 2301 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2302 | if (pos->debugger_init_callback) |
| 2303 | pos->debugger_init_callback(debugger); |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2304 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2305 | } |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2306 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2307 | // Initialize the Platform plugins |
| 2308 | { |
| 2309 | std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); |
| 2310 | PlatformInstances &instances = GetPlatformInstances(); |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2311 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2312 | PlatformInstances::iterator pos, end = instances.end(); |
| 2313 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2314 | if (pos->debugger_init_callback) |
| 2315 | pos->debugger_init_callback(debugger); |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2316 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2317 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2319 | // Initialize the Process plugins |
| 2320 | { |
| 2321 | std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); |
| 2322 | ProcessInstances &instances = GetProcessInstances(); |
| 2323 | |
| 2324 | ProcessInstances::iterator pos, end = instances.end(); |
| 2325 | for (pos = instances.begin(); pos != end; ++pos) { |
| 2326 | if (pos->debugger_init_callback) |
| 2327 | pos->debugger_init_callback(debugger); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2328 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | // Initialize the SymbolFile plugins |
| 2332 | { |
| 2333 | std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); |
| 2334 | for (auto &sym_file : GetSymbolFileInstances()) { |
| 2335 | if (sym_file.debugger_init_callback) |
| 2336 | sym_file.debugger_init_callback(debugger); |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | // Initialize the OperatingSystem plugins |
| 2341 | { |
| 2342 | std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); |
| 2343 | for (auto &os : GetOperatingSystemInstances()) { |
| 2344 | if (os.debugger_init_callback) |
| 2345 | os.debugger_init_callback(debugger); |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | // Initialize the StructuredDataPlugin plugins |
| 2350 | { |
| 2351 | std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); |
| 2352 | for (auto &plugin : GetStructuredDataPluginInstances()) { |
| 2353 | if (plugin.debugger_init_callback) |
| 2354 | plugin.debugger_init_callback(debugger); |
| 2355 | } |
| 2356 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2359 | // This is the preferred new way to register plugin specific settings. e.g. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2360 | // This will put a plugin's settings under e.g. |
| 2361 | // "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME". |
| 2362 | static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins( |
| 2363 | Debugger &debugger, const ConstString &plugin_type_name, |
| 2364 | const ConstString &plugin_type_desc, bool can_create) { |
| 2365 | lldb::OptionValuePropertiesSP parent_properties_sp( |
| 2366 | debugger.GetValueProperties()); |
| 2367 | if (parent_properties_sp) { |
| 2368 | static ConstString g_property_name("plugin"); |
| 2369 | |
| 2370 | OptionValuePropertiesSP plugin_properties_sp = |
| 2371 | parent_properties_sp->GetSubProperty(nullptr, g_property_name); |
| 2372 | if (!plugin_properties_sp && can_create) { |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 2373 | plugin_properties_sp = |
| 2374 | std::make_shared<OptionValueProperties>(g_property_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2375 | parent_properties_sp->AppendProperty( |
| 2376 | g_property_name, ConstString("Settings specify to plugins."), true, |
| 2377 | plugin_properties_sp); |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2378 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2379 | |
| 2380 | if (plugin_properties_sp) { |
| 2381 | lldb::OptionValuePropertiesSP plugin_type_properties_sp = |
| 2382 | plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name); |
| 2383 | if (!plugin_type_properties_sp && can_create) { |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 2384 | plugin_type_properties_sp = |
| 2385 | std::make_shared<OptionValueProperties>(plugin_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2386 | plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc, |
| 2387 | true, plugin_type_properties_sp); |
| 2388 | } |
| 2389 | return plugin_type_properties_sp; |
| 2390 | } |
| 2391 | } |
| 2392 | return lldb::OptionValuePropertiesSP(); |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2395 | // This is deprecated way to register plugin specific settings. e.g. |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2396 | // "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform |
| 2397 | // generic settings would be under "platform.SETTINGNAME". |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2398 | static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle( |
| 2399 | Debugger &debugger, const ConstString &plugin_type_name, |
| 2400 | const ConstString &plugin_type_desc, bool can_create) { |
| 2401 | static ConstString g_property_name("plugin"); |
| 2402 | lldb::OptionValuePropertiesSP parent_properties_sp( |
| 2403 | debugger.GetValueProperties()); |
| 2404 | if (parent_properties_sp) { |
| 2405 | OptionValuePropertiesSP plugin_properties_sp = |
| 2406 | parent_properties_sp->GetSubProperty(nullptr, plugin_type_name); |
| 2407 | if (!plugin_properties_sp && can_create) { |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 2408 | plugin_properties_sp = |
| 2409 | std::make_shared<OptionValueProperties>(plugin_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2410 | parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc, |
| 2411 | true, plugin_properties_sp); |
Jason Molenda | 3b59f5c | 2013-04-05 22:40:42 +0000 | [diff] [blame] | 2412 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2413 | |
| 2414 | if (plugin_properties_sp) { |
| 2415 | lldb::OptionValuePropertiesSP plugin_type_properties_sp = |
| 2416 | plugin_properties_sp->GetSubProperty(nullptr, g_property_name); |
| 2417 | if (!plugin_type_properties_sp && can_create) { |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 2418 | plugin_type_properties_sp = |
| 2419 | std::make_shared<OptionValueProperties>(g_property_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2420 | plugin_properties_sp->AppendProperty( |
| 2421 | g_property_name, ConstString("Settings specific to plugins"), true, |
| 2422 | plugin_type_properties_sp); |
| 2423 | } |
| 2424 | return plugin_type_properties_sp; |
| 2425 | } |
| 2426 | } |
| 2427 | return lldb::OptionValuePropertiesSP(); |
Jason Molenda | 3b59f5c | 2013-04-05 22:40:42 +0000 | [diff] [blame] | 2428 | } |
| 2429 | |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2430 | namespace { |
| 2431 | |
| 2432 | typedef lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2433 | GetDebuggerPropertyForPluginsPtr(Debugger &, const ConstString &, |
| 2434 | const ConstString &, bool can_create); |
Jason Molenda | 3b59f5c | 2013-04-05 22:40:42 +0000 | [diff] [blame] | 2435 | |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2436 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2437 | GetSettingForPlugin(Debugger &debugger, const ConstString &setting_name, |
| 2438 | const ConstString &plugin_type_name, |
| 2439 | GetDebuggerPropertyForPluginsPtr get_debugger_property = |
| 2440 | GetDebuggerPropertyForPlugins) { |
| 2441 | lldb::OptionValuePropertiesSP properties_sp; |
| 2442 | lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property( |
| 2443 | debugger, plugin_type_name, |
| 2444 | ConstString(), // not creating to so we don't need the description |
| 2445 | false)); |
| 2446 | if (plugin_type_properties_sp) |
| 2447 | properties_sp = |
| 2448 | plugin_type_properties_sp->GetSubProperty(nullptr, setting_name); |
| 2449 | return properties_sp; |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2452 | bool CreateSettingForPlugin( |
| 2453 | Debugger &debugger, const ConstString &plugin_type_name, |
| 2454 | const ConstString &plugin_type_desc, |
| 2455 | const lldb::OptionValuePropertiesSP &properties_sp, |
| 2456 | const ConstString &description, bool is_global_property, |
| 2457 | GetDebuggerPropertyForPluginsPtr get_debugger_property = |
| 2458 | GetDebuggerPropertyForPlugins) { |
| 2459 | if (properties_sp) { |
| 2460 | lldb::OptionValuePropertiesSP plugin_type_properties_sp( |
| 2461 | get_debugger_property(debugger, plugin_type_name, plugin_type_desc, |
| 2462 | true)); |
| 2463 | if (plugin_type_properties_sp) { |
| 2464 | plugin_type_properties_sp->AppendProperty(properties_sp->GetName(), |
| 2465 | description, is_global_property, |
| 2466 | properties_sp); |
| 2467 | return true; |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2468 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2469 | } |
| 2470 | return false; |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2471 | } |
| 2472 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2473 | const char *kDynamicLoaderPluginName("dynamic-loader"); |
| 2474 | const char *kPlatformPluginName("platform"); |
| 2475 | const char *kProcessPluginName("process"); |
| 2476 | const char *kSymbolFilePluginName("symbol-file"); |
| 2477 | const char *kJITLoaderPluginName("jit-loader"); |
| 2478 | const char *kStructuredDataPluginName("structured-data"); |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2479 | |
Eugene Zelenko | 8918372 | 2016-03-11 21:55:47 +0000 | [diff] [blame] | 2480 | } // anonymous namespace |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2481 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2482 | lldb::OptionValuePropertiesSP PluginManager::GetSettingForDynamicLoaderPlugin( |
| 2483 | Debugger &debugger, const ConstString &setting_name) { |
| 2484 | return GetSettingForPlugin(debugger, setting_name, |
| 2485 | ConstString(kDynamicLoaderPluginName)); |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2488 | bool PluginManager::CreateSettingForDynamicLoaderPlugin( |
| 2489 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2490 | const ConstString &description, bool is_global_property) { |
| 2491 | return CreateSettingForPlugin( |
| 2492 | debugger, ConstString(kDynamicLoaderPluginName), |
| 2493 | ConstString("Settings for dynamic loader plug-ins"), properties_sp, |
| 2494 | description, is_global_property); |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
Jason Molenda | 9b837a1 | 2013-04-05 05:06:39 +0000 | [diff] [blame] | 2497 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2498 | PluginManager::GetSettingForPlatformPlugin(Debugger &debugger, |
| 2499 | const ConstString &setting_name) { |
| 2500 | return GetSettingForPlugin(debugger, setting_name, |
| 2501 | ConstString(kPlatformPluginName), |
| 2502 | GetDebuggerPropertyForPluginsOldStyle); |
Jason Molenda | 9b837a1 | 2013-04-05 05:06:39 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2505 | bool PluginManager::CreateSettingForPlatformPlugin( |
| 2506 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2507 | const ConstString &description, bool is_global_property) { |
| 2508 | return CreateSettingForPlugin(debugger, ConstString(kPlatformPluginName), |
| 2509 | ConstString("Settings for platform plug-ins"), |
| 2510 | properties_sp, description, is_global_property, |
| 2511 | GetDebuggerPropertyForPluginsOldStyle); |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2514 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2515 | PluginManager::GetSettingForProcessPlugin(Debugger &debugger, |
| 2516 | const ConstString &setting_name) { |
| 2517 | return GetSettingForPlugin(debugger, setting_name, |
| 2518 | ConstString(kProcessPluginName)); |
Greg Clayton | 7f98240 | 2013-07-15 22:54:20 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2521 | bool PluginManager::CreateSettingForProcessPlugin( |
| 2522 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2523 | const ConstString &description, bool is_global_property) { |
| 2524 | return CreateSettingForPlugin(debugger, ConstString(kProcessPluginName), |
| 2525 | ConstString("Settings for process plug-ins"), |
| 2526 | properties_sp, description, is_global_property); |
Jason Molenda | 9b837a1 | 2013-04-05 05:06:39 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 2529 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2530 | PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger, |
| 2531 | const ConstString &setting_name) { |
| 2532 | return GetSettingForPlugin(debugger, setting_name, |
| 2533 | ConstString(kSymbolFilePluginName)); |
Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2536 | bool PluginManager::CreateSettingForSymbolFilePlugin( |
| 2537 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2538 | const ConstString &description, bool is_global_property) { |
| 2539 | return CreateSettingForPlugin( |
| 2540 | debugger, ConstString(kSymbolFilePluginName), |
| 2541 | ConstString("Settings for symbol file plug-ins"), properties_sp, |
| 2542 | description, is_global_property); |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2546 | PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger, |
| 2547 | const ConstString &setting_name) { |
| 2548 | return GetSettingForPlugin(debugger, setting_name, |
| 2549 | ConstString(kJITLoaderPluginName)); |
Oleksiy Vyalov | eff9ad2 | 2015-09-16 17:38:36 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2552 | bool PluginManager::CreateSettingForJITLoaderPlugin( |
| 2553 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2554 | const ConstString &description, bool is_global_property) { |
| 2555 | return CreateSettingForPlugin(debugger, ConstString(kJITLoaderPluginName), |
| 2556 | ConstString("Settings for JIT loader plug-ins"), |
| 2557 | properties_sp, description, is_global_property); |
Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 2558 | } |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2559 | |
| 2560 | static const char *kOperatingSystemPluginName("os"); |
| 2561 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2562 | lldb::OptionValuePropertiesSP PluginManager::GetSettingForOperatingSystemPlugin( |
| 2563 | Debugger &debugger, const ConstString &setting_name) { |
| 2564 | lldb::OptionValuePropertiesSP properties_sp; |
| 2565 | lldb::OptionValuePropertiesSP plugin_type_properties_sp( |
| 2566 | GetDebuggerPropertyForPlugins( |
| 2567 | debugger, ConstString(kOperatingSystemPluginName), |
| 2568 | ConstString(), // not creating to so we don't need the description |
| 2569 | false)); |
| 2570 | if (plugin_type_properties_sp) |
| 2571 | properties_sp = |
| 2572 | plugin_type_properties_sp->GetSubProperty(nullptr, setting_name); |
| 2573 | return properties_sp; |
| 2574 | } |
| 2575 | |
| 2576 | bool PluginManager::CreateSettingForOperatingSystemPlugin( |
| 2577 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2578 | const ConstString &description, bool is_global_property) { |
| 2579 | if (properties_sp) { |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2580 | lldb::OptionValuePropertiesSP plugin_type_properties_sp( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2581 | GetDebuggerPropertyForPlugins( |
| 2582 | debugger, ConstString(kOperatingSystemPluginName), |
| 2583 | ConstString("Settings for operating system plug-ins"), true)); |
| 2584 | if (plugin_type_properties_sp) { |
| 2585 | plugin_type_properties_sp->AppendProperty(properties_sp->GetName(), |
| 2586 | description, is_global_property, |
| 2587 | properties_sp); |
| 2588 | return true; |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2589 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2590 | } |
| 2591 | return false; |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 2592 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2594 | lldb::OptionValuePropertiesSP PluginManager::GetSettingForStructuredDataPlugin( |
| 2595 | Debugger &debugger, const ConstString &setting_name) { |
| 2596 | return GetSettingForPlugin(debugger, setting_name, |
| 2597 | ConstString(kStructuredDataPluginName)); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2600 | bool PluginManager::CreateSettingForStructuredDataPlugin( |
| 2601 | Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, |
| 2602 | const ConstString &description, bool is_global_property) { |
| 2603 | return CreateSettingForPlugin( |
| 2604 | debugger, ConstString(kStructuredDataPluginName), |
| 2605 | ConstString("Settings for structured data plug-ins"), properties_sp, |
| 2606 | description, is_global_property); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2607 | } |