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