1 //===-- PluginManager.cpp ---------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Core/PluginManager.h" 11 12 // C Includes 13 // C++ Includes 14 #include <climits> 15 #include <mutex> 16 #include <string> 17 #include <vector> 18 19 // Other libraries and framework includes 20 #include "llvm/ADT/StringRef.h" 21 #include "llvm/Support/DynamicLibrary.h" 22 23 // Project includes 24 #include "lldb/Core/Debugger.h" 25 #include "lldb/Core/Error.h" 26 #include "lldb/Host/FileSpec.h" 27 #include "lldb/Host/Host.h" 28 #include "lldb/Host/HostInfo.h" 29 #include "lldb/Interpreter/OptionValueProperties.h" 30 31 using namespace lldb; 32 using namespace lldb_private; 33 34 enum PluginAction 35 { 36 ePluginRegisterInstance, 37 ePluginUnregisterInstance, 38 ePluginGetInstanceAtIndex 39 }; 40 41 typedef bool (*PluginInitCallback)(); 42 typedef void (*PluginTermCallback)(); 43 44 struct PluginInfo 45 { 46 PluginInfo() 47 : plugin_init_callback(nullptr), plugin_term_callback(nullptr) 48 { 49 } 50 51 llvm::sys::DynamicLibrary library; 52 PluginInitCallback plugin_init_callback; 53 PluginTermCallback plugin_term_callback; 54 }; 55 56 typedef std::map<FileSpec, PluginInfo> PluginTerminateMap; 57 58 static std::recursive_mutex & 59 GetPluginMapMutex() 60 { 61 static std::recursive_mutex g_plugin_map_mutex; 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 std::lock_guard<std::recursive_mutex> guard(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 std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); 84 PluginTerminateMap &plugin_map = GetPluginMap (); 85 assert (plugin_map.find (plugin_file_spec) == plugin_map.end()); 86 plugin_map[plugin_file_spec] = plugin_info; 87 } 88 89 template <typename FPtrTy> 90 static FPtrTy 91 CastToFPtr (void *VPtr) 92 { 93 return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr)); 94 } 95 96 static FileSpec::EnumerateDirectoryResult 97 LoadPluginCallback(void *baton, 98 FileSpec::FileType file_type, 99 const FileSpec &file_spec) 100 { 101 // PluginManager *plugin_manager = (PluginManager *)baton; 102 Error error; 103 104 // If we have a regular file, a symbolic link or unknown file type, try 105 // and process the file. We must handle unknown as sometimes the directory 106 // enumeration might be enumerating a file system that doesn't have correct 107 // file type information. 108 if (file_type == FileSpec::eFileTypeRegular || 109 file_type == FileSpec::eFileTypeSymbolicLink || 110 file_type == FileSpec::eFileTypeUnknown ) 111 { 112 FileSpec plugin_file_spec (file_spec); 113 plugin_file_spec.ResolvePath(); 114 115 if (PluginIsLoaded (plugin_file_spec)) 116 return FileSpec::eEnumerateDirectoryResultNext; 117 else 118 { 119 PluginInfo plugin_info; 120 121 std::string pluginLoadError; 122 plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary (plugin_file_spec.GetPath().c_str(), &pluginLoadError); 123 if (plugin_info.library.isValid()) 124 { 125 bool success = false; 126 plugin_info.plugin_init_callback = 127 CastToFPtr<PluginInitCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize")); 128 if (plugin_info.plugin_init_callback) 129 { 130 // Call the plug-in "bool LLDBPluginInitialize(void)" function 131 success = plugin_info.plugin_init_callback(); 132 } 133 134 if (success) 135 { 136 // It is ok for the "LLDBPluginTerminate" symbol to be nullptr 137 plugin_info.plugin_term_callback = 138 CastToFPtr<PluginTermCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate")); 139 } 140 else 141 { 142 // The initialize function returned FALSE which means the plug-in might not be 143 // compatible, or might be too new or too old, or might not want to run on this 144 // machine. Set it to a default-constructed instance to invalidate it. 145 plugin_info = PluginInfo(); 146 } 147 148 // Regardless of success or failure, cache the plug-in load 149 // in our plug-in info so we don't try to load it again and 150 // again. 151 SetPluginInfo (plugin_file_spec, plugin_info); 152 153 return FileSpec::eEnumerateDirectoryResultNext; 154 } 155 } 156 } 157 158 if (file_type == FileSpec::eFileTypeUnknown || 159 file_type == FileSpec::eFileTypeDirectory || 160 file_type == FileSpec::eFileTypeSymbolicLink ) 161 { 162 // Try and recurse into anything that a directory or symbolic link. 163 // We must also do this for unknown as sometimes the directory enumeration 164 // might be enumerating a file system that doesn't have correct file type 165 // information. 166 return FileSpec::eEnumerateDirectoryResultEnter; 167 } 168 169 return FileSpec::eEnumerateDirectoryResultNext; 170 } 171 172 void 173 PluginManager::Initialize () 174 { 175 #if 1 176 FileSpec dir_spec; 177 const bool find_directories = true; 178 const bool find_files = true; 179 const bool find_other = true; 180 char dir_path[PATH_MAX]; 181 if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) 182 { 183 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) 184 { 185 FileSpec::EnumerateDirectory(dir_path, 186 find_directories, 187 find_files, 188 find_other, 189 LoadPluginCallback, 190 nullptr); 191 } 192 } 193 194 if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) 195 { 196 if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) 197 { 198 FileSpec::EnumerateDirectory(dir_path, 199 find_directories, 200 find_files, 201 find_other, 202 LoadPluginCallback, 203 nullptr); 204 } 205 } 206 #endif 207 } 208 209 void 210 PluginManager::Terminate () 211 { 212 std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); 213 PluginTerminateMap &plugin_map = GetPluginMap (); 214 215 PluginTerminateMap::const_iterator pos, end = plugin_map.end(); 216 for (pos = plugin_map.begin(); pos != end; ++pos) 217 { 218 // Call the plug-in "void LLDBPluginTerminate (void)" function if there 219 // is one (if the symbol was not nullptr). 220 if (pos->second.library.isValid()) 221 { 222 if (pos->second.plugin_term_callback) 223 pos->second.plugin_term_callback(); 224 } 225 } 226 plugin_map.clear(); 227 } 228 229 #pragma mark ABI 230 231 struct ABIInstance 232 { 233 ABIInstance() : 234 name(), 235 description(), 236 create_callback(nullptr) 237 { 238 } 239 240 ConstString name; 241 std::string description; 242 ABICreateInstance create_callback; 243 }; 244 245 typedef std::vector<ABIInstance> ABIInstances; 246 247 static std::recursive_mutex & 248 GetABIInstancesMutex() 249 { 250 static std::recursive_mutex g_instances_mutex; 251 return g_instances_mutex; 252 } 253 254 static ABIInstances & 255 GetABIInstances () 256 { 257 static ABIInstances g_instances; 258 return g_instances; 259 } 260 261 bool 262 PluginManager::RegisterPlugin(const ConstString &name, 263 const char *description, 264 ABICreateInstance create_callback) 265 { 266 if (create_callback) 267 { 268 ABIInstance instance; 269 assert ((bool)name); 270 instance.name = name; 271 if (description && description[0]) 272 instance.description = description; 273 instance.create_callback = create_callback; 274 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); 275 GetABIInstances ().push_back (instance); 276 return true; 277 } 278 return false; 279 } 280 281 bool 282 PluginManager::UnregisterPlugin (ABICreateInstance create_callback) 283 { 284 if (create_callback) 285 { 286 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); 287 ABIInstances &instances = GetABIInstances (); 288 289 ABIInstances::iterator pos, end = instances.end(); 290 for (pos = instances.begin(); pos != end; ++ pos) 291 { 292 if (pos->create_callback == create_callback) 293 { 294 instances.erase(pos); 295 return true; 296 } 297 } 298 } 299 return false; 300 } 301 302 ABICreateInstance 303 PluginManager::GetABICreateCallbackAtIndex (uint32_t idx) 304 { 305 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); 306 ABIInstances &instances = GetABIInstances (); 307 if (idx < instances.size()) 308 return instances[idx].create_callback; 309 return nullptr; 310 } 311 312 ABICreateInstance 313 PluginManager::GetABICreateCallbackForPluginName (const ConstString &name) 314 { 315 if (name) 316 { 317 std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); 318 ABIInstances &instances = GetABIInstances (); 319 320 ABIInstances::iterator pos, end = instances.end(); 321 for (pos = instances.begin(); pos != end; ++ pos) 322 { 323 if (name == pos->name) 324 return pos->create_callback; 325 } 326 } 327 return nullptr; 328 } 329 330 #pragma mark Disassembler 331 332 struct DisassemblerInstance 333 { 334 DisassemblerInstance() : 335 name(), 336 description(), 337 create_callback(nullptr) 338 { 339 } 340 341 ConstString name; 342 std::string description; 343 DisassemblerCreateInstance create_callback; 344 }; 345 346 typedef std::vector<DisassemblerInstance> DisassemblerInstances; 347 348 static std::recursive_mutex & 349 GetDisassemblerMutex() 350 { 351 static std::recursive_mutex g_instances_mutex; 352 return g_instances_mutex; 353 } 354 355 static DisassemblerInstances & 356 GetDisassemblerInstances () 357 { 358 static DisassemblerInstances g_instances; 359 return g_instances; 360 } 361 362 bool 363 PluginManager::RegisterPlugin(const ConstString &name, 364 const char *description, 365 DisassemblerCreateInstance create_callback) 366 { 367 if (create_callback) 368 { 369 DisassemblerInstance instance; 370 assert ((bool)name); 371 instance.name = name; 372 if (description && description[0]) 373 instance.description = description; 374 instance.create_callback = create_callback; 375 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); 376 GetDisassemblerInstances ().push_back (instance); 377 return true; 378 } 379 return false; 380 } 381 382 bool 383 PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback) 384 { 385 if (create_callback) 386 { 387 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); 388 DisassemblerInstances &instances = GetDisassemblerInstances (); 389 390 DisassemblerInstances::iterator pos, end = instances.end(); 391 for (pos = instances.begin(); pos != end; ++ pos) 392 { 393 if (pos->create_callback == create_callback) 394 { 395 instances.erase(pos); 396 return true; 397 } 398 } 399 } 400 return false; 401 } 402 403 DisassemblerCreateInstance 404 PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx) 405 { 406 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); 407 DisassemblerInstances &instances = GetDisassemblerInstances (); 408 if (idx < instances.size()) 409 return instances[idx].create_callback; 410 return nullptr; 411 } 412 413 DisassemblerCreateInstance 414 PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &name) 415 { 416 if (name) 417 { 418 std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); 419 DisassemblerInstances &instances = GetDisassemblerInstances (); 420 421 DisassemblerInstances::iterator pos, end = instances.end(); 422 for (pos = instances.begin(); pos != end; ++ pos) 423 { 424 if (name == pos->name) 425 return pos->create_callback; 426 } 427 } 428 return nullptr; 429 } 430 431 #pragma mark DynamicLoader 432 433 struct DynamicLoaderInstance 434 { 435 DynamicLoaderInstance() : 436 name(), 437 description(), 438 create_callback(nullptr), 439 debugger_init_callback(nullptr) 440 { 441 } 442 443 ConstString name; 444 std::string description; 445 DynamicLoaderCreateInstance create_callback; 446 DebuggerInitializeCallback debugger_init_callback; 447 }; 448 449 typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances; 450 451 static std::recursive_mutex & 452 GetDynamicLoaderMutex() 453 { 454 static std::recursive_mutex g_instances_mutex; 455 return g_instances_mutex; 456 } 457 458 static DynamicLoaderInstances & 459 GetDynamicLoaderInstances () 460 { 461 static DynamicLoaderInstances g_instances; 462 return g_instances; 463 } 464 465 bool 466 PluginManager::RegisterPlugin(const ConstString &name, 467 const char *description, 468 DynamicLoaderCreateInstance create_callback, 469 DebuggerInitializeCallback debugger_init_callback) 470 { 471 if (create_callback) 472 { 473 DynamicLoaderInstance instance; 474 assert ((bool)name); 475 instance.name = name; 476 if (description && description[0]) 477 instance.description = description; 478 instance.create_callback = create_callback; 479 instance.debugger_init_callback = debugger_init_callback; 480 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); 481 GetDynamicLoaderInstances ().push_back (instance); 482 } 483 return false; 484 } 485 486 bool 487 PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback) 488 { 489 if (create_callback) 490 { 491 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); 492 DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); 493 494 DynamicLoaderInstances::iterator pos, end = instances.end(); 495 for (pos = instances.begin(); pos != end; ++ pos) 496 { 497 if (pos->create_callback == create_callback) 498 { 499 instances.erase(pos); 500 return true; 501 } 502 } 503 } 504 return false; 505 } 506 507 DynamicLoaderCreateInstance 508 PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx) 509 { 510 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); 511 DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); 512 if (idx < instances.size()) 513 return instances[idx].create_callback; 514 return nullptr; 515 } 516 517 DynamicLoaderCreateInstance 518 PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &name) 519 { 520 if (name) 521 { 522 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); 523 DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); 524 525 DynamicLoaderInstances::iterator pos, end = instances.end(); 526 for (pos = instances.begin(); pos != end; ++ pos) 527 { 528 if (name == pos->name) 529 return pos->create_callback; 530 } 531 } 532 return nullptr; 533 } 534 535 #pragma mark JITLoader 536 537 struct JITLoaderInstance 538 { 539 JITLoaderInstance() : 540 name(), 541 description(), 542 create_callback(nullptr), 543 debugger_init_callback(nullptr) 544 { 545 } 546 547 ConstString name; 548 std::string description; 549 JITLoaderCreateInstance create_callback; 550 DebuggerInitializeCallback debugger_init_callback; 551 }; 552 553 typedef std::vector<JITLoaderInstance> JITLoaderInstances; 554 555 static std::recursive_mutex & 556 GetJITLoaderMutex() 557 { 558 static std::recursive_mutex g_instances_mutex; 559 return g_instances_mutex; 560 } 561 562 static JITLoaderInstances & 563 GetJITLoaderInstances () 564 { 565 static JITLoaderInstances g_instances; 566 return g_instances; 567 } 568 569 bool 570 PluginManager::RegisterPlugin(const ConstString &name, 571 const char *description, 572 JITLoaderCreateInstance create_callback, 573 DebuggerInitializeCallback debugger_init_callback) 574 { 575 if (create_callback) 576 { 577 JITLoaderInstance instance; 578 assert ((bool)name); 579 instance.name = name; 580 if (description && description[0]) 581 instance.description = description; 582 instance.create_callback = create_callback; 583 instance.debugger_init_callback = debugger_init_callback; 584 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); 585 GetJITLoaderInstances ().push_back (instance); 586 } 587 return false; 588 } 589 590 bool 591 PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback) 592 { 593 if (create_callback) 594 { 595 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); 596 JITLoaderInstances &instances = GetJITLoaderInstances (); 597 598 JITLoaderInstances::iterator pos, end = instances.end(); 599 for (pos = instances.begin(); pos != end; ++ pos) 600 { 601 if (pos->create_callback == create_callback) 602 { 603 instances.erase(pos); 604 return true; 605 } 606 } 607 } 608 return false; 609 } 610 611 JITLoaderCreateInstance 612 PluginManager::GetJITLoaderCreateCallbackAtIndex (uint32_t idx) 613 { 614 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); 615 JITLoaderInstances &instances = GetJITLoaderInstances (); 616 if (idx < instances.size()) 617 return instances[idx].create_callback; 618 return nullptr; 619 } 620 621 JITLoaderCreateInstance 622 PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name) 623 { 624 if (name) 625 { 626 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); 627 JITLoaderInstances &instances = GetJITLoaderInstances (); 628 629 JITLoaderInstances::iterator pos, end = instances.end(); 630 for (pos = instances.begin(); pos != end; ++ pos) 631 { 632 if (name == pos->name) 633 return pos->create_callback; 634 } 635 } 636 return nullptr; 637 } 638 639 #pragma mark EmulateInstruction 640 641 struct EmulateInstructionInstance 642 { 643 EmulateInstructionInstance() : 644 name(), 645 description(), 646 create_callback(nullptr) 647 { 648 } 649 650 ConstString name; 651 std::string description; 652 EmulateInstructionCreateInstance create_callback; 653 }; 654 655 typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances; 656 657 static std::recursive_mutex & 658 GetEmulateInstructionMutex() 659 { 660 static std::recursive_mutex g_instances_mutex; 661 return g_instances_mutex; 662 } 663 664 static EmulateInstructionInstances & 665 GetEmulateInstructionInstances () 666 { 667 static EmulateInstructionInstances g_instances; 668 return g_instances; 669 } 670 671 bool 672 PluginManager::RegisterPlugin(const ConstString &name, 673 const char *description, 674 EmulateInstructionCreateInstance create_callback) 675 { 676 if (create_callback) 677 { 678 EmulateInstructionInstance instance; 679 assert ((bool)name); 680 instance.name = name; 681 if (description && description[0]) 682 instance.description = description; 683 instance.create_callback = create_callback; 684 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); 685 GetEmulateInstructionInstances ().push_back (instance); 686 } 687 return false; 688 } 689 690 bool 691 PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callback) 692 { 693 if (create_callback) 694 { 695 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); 696 EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); 697 698 EmulateInstructionInstances::iterator pos, end = instances.end(); 699 for (pos = instances.begin(); pos != end; ++ pos) 700 { 701 if (pos->create_callback == create_callback) 702 { 703 instances.erase(pos); 704 return true; 705 } 706 } 707 } 708 return false; 709 } 710 711 EmulateInstructionCreateInstance 712 PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx) 713 { 714 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); 715 EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); 716 if (idx < instances.size()) 717 return instances[idx].create_callback; 718 return nullptr; 719 } 720 721 EmulateInstructionCreateInstance 722 PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstString &name) 723 { 724 if (name) 725 { 726 std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); 727 EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); 728 729 EmulateInstructionInstances::iterator pos, end = instances.end(); 730 for (pos = instances.begin(); pos != end; ++ pos) 731 { 732 if (name == pos->name) 733 return pos->create_callback; 734 } 735 } 736 return nullptr; 737 } 738 739 #pragma mark OperatingSystem 740 741 struct OperatingSystemInstance 742 { 743 OperatingSystemInstance () : 744 name (), 745 description (), 746 create_callback (nullptr), 747 debugger_init_callback (nullptr) 748 { 749 } 750 751 ConstString name; 752 std::string description; 753 OperatingSystemCreateInstance create_callback; 754 DebuggerInitializeCallback debugger_init_callback; 755 }; 756 757 typedef std::vector<OperatingSystemInstance> OperatingSystemInstances; 758 759 static std::recursive_mutex & 760 GetOperatingSystemMutex() 761 { 762 static std::recursive_mutex g_instances_mutex; 763 return g_instances_mutex; 764 } 765 766 static OperatingSystemInstances & 767 GetOperatingSystemInstances () 768 { 769 static OperatingSystemInstances g_instances; 770 return g_instances; 771 } 772 773 bool 774 PluginManager::RegisterPlugin(const ConstString &name, const char *description, 775 OperatingSystemCreateInstance create_callback, 776 DebuggerInitializeCallback debugger_init_callback) 777 { 778 if (create_callback) 779 { 780 OperatingSystemInstance instance; 781 assert ((bool)name); 782 instance.name = name; 783 if (description && description[0]) 784 instance.description = description; 785 instance.create_callback = create_callback; 786 instance.debugger_init_callback = debugger_init_callback; 787 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); 788 GetOperatingSystemInstances ().push_back (instance); 789 } 790 return false; 791 } 792 793 bool 794 PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback) 795 { 796 if (create_callback) 797 { 798 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); 799 OperatingSystemInstances &instances = GetOperatingSystemInstances (); 800 801 OperatingSystemInstances::iterator pos, end = instances.end(); 802 for (pos = instances.begin(); pos != end; ++ pos) 803 { 804 if (pos->create_callback == create_callback) 805 { 806 instances.erase(pos); 807 return true; 808 } 809 } 810 } 811 return false; 812 } 813 814 OperatingSystemCreateInstance 815 PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx) 816 { 817 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); 818 OperatingSystemInstances &instances = GetOperatingSystemInstances (); 819 if (idx < instances.size()) 820 return instances[idx].create_callback; 821 return nullptr; 822 } 823 824 OperatingSystemCreateInstance 825 PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString &name) 826 { 827 if (name) 828 { 829 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); 830 OperatingSystemInstances &instances = GetOperatingSystemInstances (); 831 832 OperatingSystemInstances::iterator pos, end = instances.end(); 833 for (pos = instances.begin(); pos != end; ++ pos) 834 { 835 if (name == pos->name) 836 return pos->create_callback; 837 } 838 } 839 return nullptr; 840 } 841 842 #pragma mark Language 843 844 struct LanguageInstance 845 { 846 LanguageInstance() : 847 name(), 848 description(), 849 create_callback(nullptr) 850 { 851 } 852 853 ConstString name; 854 std::string description; 855 LanguageCreateInstance create_callback; 856 }; 857 858 typedef std::vector<LanguageInstance> LanguageInstances; 859 860 static std::recursive_mutex & 861 GetLanguageMutex() 862 { 863 static std::recursive_mutex g_instances_mutex; 864 return g_instances_mutex; 865 } 866 867 static LanguageInstances & 868 GetLanguageInstances () 869 { 870 static LanguageInstances g_instances; 871 return g_instances; 872 } 873 874 bool 875 PluginManager::RegisterPlugin(const ConstString &name, 876 const char *description, 877 LanguageCreateInstance create_callback) 878 { 879 if (create_callback) 880 { 881 LanguageInstance instance; 882 assert ((bool)name); 883 instance.name = name; 884 if (description && description[0]) 885 instance.description = description; 886 instance.create_callback = create_callback; 887 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); 888 GetLanguageInstances ().push_back (instance); 889 } 890 return false; 891 } 892 893 bool 894 PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback) 895 { 896 if (create_callback) 897 { 898 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); 899 LanguageInstances &instances = GetLanguageInstances (); 900 901 LanguageInstances::iterator pos, end = instances.end(); 902 for (pos = instances.begin(); pos != end; ++ pos) 903 { 904 if (pos->create_callback == create_callback) 905 { 906 instances.erase(pos); 907 return true; 908 } 909 } 910 } 911 return false; 912 } 913 914 LanguageCreateInstance 915 PluginManager::GetLanguageCreateCallbackAtIndex (uint32_t idx) 916 { 917 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); 918 LanguageInstances &instances = GetLanguageInstances (); 919 if (idx < instances.size()) 920 return instances[idx].create_callback; 921 return nullptr; 922 } 923 924 LanguageCreateInstance 925 PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name) 926 { 927 if (name) 928 { 929 std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); 930 LanguageInstances &instances = GetLanguageInstances (); 931 932 LanguageInstances::iterator pos, end = instances.end(); 933 for (pos = instances.begin(); pos != end; ++ pos) 934 { 935 if (name == pos->name) 936 return pos->create_callback; 937 } 938 } 939 return nullptr; 940 } 941 942 #pragma mark LanguageRuntime 943 944 struct LanguageRuntimeInstance 945 { 946 LanguageRuntimeInstance() : 947 name(), 948 description(), 949 create_callback(nullptr) 950 { 951 } 952 953 ConstString name; 954 std::string description; 955 LanguageRuntimeCreateInstance create_callback; 956 LanguageRuntimeGetCommandObject command_callback; 957 }; 958 959 typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances; 960 961 static std::recursive_mutex & 962 GetLanguageRuntimeMutex() 963 { 964 static std::recursive_mutex g_instances_mutex; 965 return g_instances_mutex; 966 } 967 968 static LanguageRuntimeInstances & 969 GetLanguageRuntimeInstances () 970 { 971 static LanguageRuntimeInstances g_instances; 972 return g_instances; 973 } 974 975 bool 976 PluginManager::RegisterPlugin(const ConstString &name, 977 const char *description, 978 LanguageRuntimeCreateInstance create_callback, 979 LanguageRuntimeGetCommandObject command_callback) 980 { 981 if (create_callback) 982 { 983 LanguageRuntimeInstance instance; 984 assert ((bool)name); 985 instance.name = name; 986 if (description && description[0]) 987 instance.description = description; 988 instance.create_callback = create_callback; 989 instance.command_callback = command_callback; 990 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); 991 GetLanguageRuntimeInstances ().push_back (instance); 992 } 993 return false; 994 } 995 996 bool 997 PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback) 998 { 999 if (create_callback) 1000 { 1001 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); 1002 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); 1003 1004 LanguageRuntimeInstances::iterator pos, end = instances.end(); 1005 for (pos = instances.begin(); pos != end; ++ pos) 1006 { 1007 if (pos->create_callback == create_callback) 1008 { 1009 instances.erase(pos); 1010 return true; 1011 } 1012 } 1013 } 1014 return false; 1015 } 1016 1017 LanguageRuntimeCreateInstance 1018 PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx) 1019 { 1020 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); 1021 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); 1022 if (idx < instances.size()) 1023 return instances[idx].create_callback; 1024 return nullptr; 1025 } 1026 1027 LanguageRuntimeGetCommandObject 1028 PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex (uint32_t idx) 1029 { 1030 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); 1031 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); 1032 if (idx < instances.size()) 1033 return instances[idx].command_callback; 1034 return nullptr; 1035 } 1036 1037 LanguageRuntimeCreateInstance 1038 PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString &name) 1039 { 1040 if (name) 1041 { 1042 std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); 1043 LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); 1044 1045 LanguageRuntimeInstances::iterator pos, end = instances.end(); 1046 for (pos = instances.begin(); pos != end; ++ pos) 1047 { 1048 if (name == pos->name) 1049 return pos->create_callback; 1050 } 1051 } 1052 return nullptr; 1053 } 1054 1055 #pragma mark SystemRuntime 1056 1057 struct SystemRuntimeInstance 1058 { 1059 SystemRuntimeInstance() : 1060 name(), 1061 description(), 1062 create_callback(nullptr) 1063 { 1064 } 1065 1066 ConstString name; 1067 std::string description; 1068 SystemRuntimeCreateInstance create_callback; 1069 }; 1070 1071 typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances; 1072 1073 static std::recursive_mutex & 1074 GetSystemRuntimeMutex() 1075 { 1076 static std::recursive_mutex g_instances_mutex; 1077 return g_instances_mutex; 1078 } 1079 1080 static SystemRuntimeInstances & 1081 GetSystemRuntimeInstances () 1082 { 1083 static SystemRuntimeInstances g_instances; 1084 return g_instances; 1085 } 1086 1087 bool 1088 PluginManager::RegisterPlugin(const ConstString &name, 1089 const char *description, 1090 SystemRuntimeCreateInstance create_callback) 1091 { 1092 if (create_callback) 1093 { 1094 SystemRuntimeInstance instance; 1095 assert ((bool)name); 1096 instance.name = name; 1097 if (description && description[0]) 1098 instance.description = description; 1099 instance.create_callback = create_callback; 1100 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); 1101 GetSystemRuntimeInstances ().push_back (instance); 1102 } 1103 return false; 1104 } 1105 1106 bool 1107 PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback) 1108 { 1109 if (create_callback) 1110 { 1111 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); 1112 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 1113 1114 SystemRuntimeInstances::iterator pos, end = instances.end(); 1115 for (pos = instances.begin(); pos != end; ++ pos) 1116 { 1117 if (pos->create_callback == create_callback) 1118 { 1119 instances.erase(pos); 1120 return true; 1121 } 1122 } 1123 } 1124 return false; 1125 } 1126 1127 SystemRuntimeCreateInstance 1128 PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx) 1129 { 1130 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); 1131 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 1132 if (idx < instances.size()) 1133 return instances[idx].create_callback; 1134 return nullptr; 1135 } 1136 1137 SystemRuntimeCreateInstance 1138 PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name) 1139 { 1140 if (name) 1141 { 1142 std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); 1143 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 1144 1145 SystemRuntimeInstances::iterator pos, end = instances.end(); 1146 for (pos = instances.begin(); pos != end; ++ pos) 1147 { 1148 if (name == pos->name) 1149 return pos->create_callback; 1150 } 1151 } 1152 return nullptr; 1153 } 1154 1155 #pragma mark ObjectFile 1156 1157 struct ObjectFileInstance 1158 { 1159 ObjectFileInstance() : 1160 name(), 1161 description(), 1162 create_callback(nullptr), 1163 create_memory_callback(nullptr), 1164 get_module_specifications(nullptr), 1165 save_core(nullptr) 1166 { 1167 } 1168 1169 ConstString name; 1170 std::string description; 1171 ObjectFileCreateInstance create_callback; 1172 ObjectFileCreateMemoryInstance create_memory_callback; 1173 ObjectFileGetModuleSpecifications get_module_specifications; 1174 ObjectFileSaveCore save_core; 1175 }; 1176 1177 typedef std::vector<ObjectFileInstance> ObjectFileInstances; 1178 1179 static std::recursive_mutex & 1180 GetObjectFileMutex() 1181 { 1182 static std::recursive_mutex g_instances_mutex; 1183 return g_instances_mutex; 1184 } 1185 1186 static ObjectFileInstances & 1187 GetObjectFileInstances () 1188 { 1189 static ObjectFileInstances g_instances; 1190 return g_instances; 1191 } 1192 1193 bool 1194 PluginManager::RegisterPlugin (const ConstString &name, 1195 const char *description, 1196 ObjectFileCreateInstance create_callback, 1197 ObjectFileCreateMemoryInstance create_memory_callback, 1198 ObjectFileGetModuleSpecifications get_module_specifications, 1199 ObjectFileSaveCore save_core) 1200 { 1201 if (create_callback) 1202 { 1203 ObjectFileInstance instance; 1204 assert ((bool)name); 1205 instance.name = name; 1206 if (description && description[0]) 1207 instance.description = description; 1208 instance.create_callback = create_callback; 1209 instance.create_memory_callback = create_memory_callback; 1210 instance.save_core = save_core; 1211 instance.get_module_specifications = get_module_specifications; 1212 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1213 GetObjectFileInstances ().push_back (instance); 1214 } 1215 return false; 1216 } 1217 1218 bool 1219 PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback) 1220 { 1221 if (create_callback) 1222 { 1223 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1224 ObjectFileInstances &instances = GetObjectFileInstances (); 1225 1226 ObjectFileInstances::iterator pos, end = instances.end(); 1227 for (pos = instances.begin(); pos != end; ++ pos) 1228 { 1229 if (pos->create_callback == create_callback) 1230 { 1231 instances.erase(pos); 1232 return true; 1233 } 1234 } 1235 } 1236 return false; 1237 } 1238 1239 ObjectFileCreateInstance 1240 PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx) 1241 { 1242 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1243 ObjectFileInstances &instances = GetObjectFileInstances (); 1244 if (idx < instances.size()) 1245 return instances[idx].create_callback; 1246 return nullptr; 1247 } 1248 1249 ObjectFileCreateMemoryInstance 1250 PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx) 1251 { 1252 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1253 ObjectFileInstances &instances = GetObjectFileInstances (); 1254 if (idx < instances.size()) 1255 return instances[idx].create_memory_callback; 1256 return nullptr; 1257 } 1258 1259 ObjectFileGetModuleSpecifications 1260 PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex (uint32_t idx) 1261 { 1262 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1263 ObjectFileInstances &instances = GetObjectFileInstances (); 1264 if (idx < instances.size()) 1265 return instances[idx].get_module_specifications; 1266 return nullptr; 1267 } 1268 1269 ObjectFileCreateInstance 1270 PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name) 1271 { 1272 if (name) 1273 { 1274 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1275 ObjectFileInstances &instances = GetObjectFileInstances (); 1276 1277 ObjectFileInstances::iterator pos, end = instances.end(); 1278 for (pos = instances.begin(); pos != end; ++ pos) 1279 { 1280 if (name == pos->name) 1281 return pos->create_callback; 1282 } 1283 } 1284 return nullptr; 1285 } 1286 1287 ObjectFileCreateMemoryInstance 1288 PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString &name) 1289 { 1290 if (name) 1291 { 1292 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1293 ObjectFileInstances &instances = GetObjectFileInstances (); 1294 1295 ObjectFileInstances::iterator pos, end = instances.end(); 1296 for (pos = instances.begin(); pos != end; ++ pos) 1297 { 1298 if (name == pos->name) 1299 return pos->create_memory_callback; 1300 } 1301 } 1302 return nullptr; 1303 } 1304 1305 Error 1306 PluginManager::SaveCore (const lldb::ProcessSP &process_sp, const FileSpec &outfile) 1307 { 1308 Error error; 1309 std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); 1310 ObjectFileInstances &instances = GetObjectFileInstances (); 1311 1312 ObjectFileInstances::iterator pos, end = instances.end(); 1313 for (pos = instances.begin(); pos != end; ++ pos) 1314 { 1315 if (pos->save_core && pos->save_core (process_sp, outfile, error)) 1316 return error; 1317 } 1318 error.SetErrorString("no ObjectFile plugins were able to save a core for this process"); 1319 return error; 1320 } 1321 1322 #pragma mark ObjectContainer 1323 1324 struct ObjectContainerInstance 1325 { 1326 ObjectContainerInstance() : 1327 name(), 1328 description(), 1329 create_callback(nullptr), 1330 get_module_specifications(nullptr) 1331 { 1332 } 1333 1334 ConstString name; 1335 std::string description; 1336 ObjectContainerCreateInstance create_callback; 1337 ObjectFileGetModuleSpecifications get_module_specifications; 1338 }; 1339 1340 typedef std::vector<ObjectContainerInstance> ObjectContainerInstances; 1341 1342 static std::recursive_mutex & 1343 GetObjectContainerMutex() 1344 { 1345 static std::recursive_mutex g_instances_mutex; 1346 return g_instances_mutex; 1347 } 1348 1349 static ObjectContainerInstances & 1350 GetObjectContainerInstances () 1351 { 1352 static ObjectContainerInstances g_instances; 1353 return g_instances; 1354 } 1355 1356 bool 1357 PluginManager::RegisterPlugin (const ConstString &name, 1358 const char *description, 1359 ObjectContainerCreateInstance create_callback, 1360 ObjectFileGetModuleSpecifications get_module_specifications) 1361 { 1362 if (create_callback) 1363 { 1364 ObjectContainerInstance instance; 1365 assert ((bool)name); 1366 instance.name = name; 1367 if (description && description[0]) 1368 instance.description = description; 1369 instance.create_callback = create_callback; 1370 instance.get_module_specifications = get_module_specifications; 1371 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); 1372 GetObjectContainerInstances ().push_back (instance); 1373 } 1374 return false; 1375 } 1376 1377 bool 1378 PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback) 1379 { 1380 if (create_callback) 1381 { 1382 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); 1383 ObjectContainerInstances &instances = GetObjectContainerInstances (); 1384 1385 ObjectContainerInstances::iterator pos, end = instances.end(); 1386 for (pos = instances.begin(); pos != end; ++ pos) 1387 { 1388 if (pos->create_callback == create_callback) 1389 { 1390 instances.erase(pos); 1391 return true; 1392 } 1393 } 1394 } 1395 return false; 1396 } 1397 1398 ObjectContainerCreateInstance 1399 PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx) 1400 { 1401 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); 1402 ObjectContainerInstances &instances = GetObjectContainerInstances (); 1403 if (idx < instances.size()) 1404 return instances[idx].create_callback; 1405 return nullptr; 1406 } 1407 1408 ObjectContainerCreateInstance 1409 PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString &name) 1410 { 1411 if (name) 1412 { 1413 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); 1414 ObjectContainerInstances &instances = GetObjectContainerInstances (); 1415 1416 ObjectContainerInstances::iterator pos, end = instances.end(); 1417 for (pos = instances.begin(); pos != end; ++ pos) 1418 { 1419 if (name == pos->name) 1420 return pos->create_callback; 1421 } 1422 } 1423 return nullptr; 1424 } 1425 1426 ObjectFileGetModuleSpecifications 1427 PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex (uint32_t idx) 1428 { 1429 std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); 1430 ObjectContainerInstances &instances = GetObjectContainerInstances (); 1431 if (idx < instances.size()) 1432 return instances[idx].get_module_specifications; 1433 return nullptr; 1434 } 1435 1436 #pragma mark LogChannel 1437 1438 struct LogInstance 1439 { 1440 LogInstance() : 1441 name(), 1442 description(), 1443 create_callback(nullptr) 1444 { 1445 } 1446 1447 ConstString name; 1448 std::string description; 1449 LogChannelCreateInstance create_callback; 1450 }; 1451 1452 typedef std::vector<LogInstance> LogInstances; 1453 1454 static std::recursive_mutex & 1455 GetLogMutex() 1456 { 1457 static std::recursive_mutex g_instances_mutex; 1458 return g_instances_mutex; 1459 } 1460 1461 static LogInstances & 1462 GetLogInstances () 1463 { 1464 static LogInstances g_instances; 1465 return g_instances; 1466 } 1467 1468 bool 1469 PluginManager::RegisterPlugin(const ConstString &name, 1470 const char *description, 1471 LogChannelCreateInstance create_callback) 1472 { 1473 if (create_callback) 1474 { 1475 LogInstance instance; 1476 assert ((bool)name); 1477 instance.name = name; 1478 if (description && description[0]) 1479 instance.description = description; 1480 instance.create_callback = create_callback; 1481 std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); 1482 GetLogInstances ().push_back (instance); 1483 } 1484 return false; 1485 } 1486 1487 bool 1488 PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback) 1489 { 1490 if (create_callback) 1491 { 1492 std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); 1493 LogInstances &instances = GetLogInstances (); 1494 1495 LogInstances::iterator pos, end = instances.end(); 1496 for (pos = instances.begin(); pos != end; ++ pos) 1497 { 1498 if (pos->create_callback == create_callback) 1499 { 1500 instances.erase(pos); 1501 return true; 1502 } 1503 } 1504 } 1505 return false; 1506 } 1507 1508 const char * 1509 PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx) 1510 { 1511 std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); 1512 LogInstances &instances = GetLogInstances (); 1513 if (idx < instances.size()) 1514 return instances[idx].name.GetCString(); 1515 return nullptr; 1516 } 1517 1518 LogChannelCreateInstance 1519 PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx) 1520 { 1521 std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); 1522 LogInstances &instances = GetLogInstances (); 1523 if (idx < instances.size()) 1524 return instances[idx].create_callback; 1525 return nullptr; 1526 } 1527 1528 LogChannelCreateInstance 1529 PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name) 1530 { 1531 if (name) 1532 { 1533 std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); 1534 LogInstances &instances = GetLogInstances (); 1535 1536 LogInstances::iterator pos, end = instances.end(); 1537 for (pos = instances.begin(); pos != end; ++ pos) 1538 { 1539 if (name == pos->name) 1540 return pos->create_callback; 1541 } 1542 } 1543 return nullptr; 1544 } 1545 1546 #pragma mark Platform 1547 1548 struct PlatformInstance 1549 { 1550 PlatformInstance() : 1551 name(), 1552 description(), 1553 create_callback(nullptr), 1554 debugger_init_callback(nullptr) 1555 { 1556 } 1557 1558 ConstString name; 1559 std::string description; 1560 PlatformCreateInstance create_callback; 1561 DebuggerInitializeCallback debugger_init_callback; 1562 }; 1563 1564 typedef std::vector<PlatformInstance> PlatformInstances; 1565 1566 static std::recursive_mutex & 1567 GetPlatformInstancesMutex() 1568 { 1569 static std::recursive_mutex g_platform_instances_mutex; 1570 return g_platform_instances_mutex; 1571 } 1572 1573 static PlatformInstances & 1574 GetPlatformInstances () 1575 { 1576 static PlatformInstances g_platform_instances; 1577 return g_platform_instances; 1578 } 1579 1580 bool 1581 PluginManager::RegisterPlugin (const ConstString &name, 1582 const char *description, 1583 PlatformCreateInstance create_callback, 1584 DebuggerInitializeCallback debugger_init_callback) 1585 { 1586 if (create_callback) 1587 { 1588 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1589 1590 PlatformInstance instance; 1591 assert ((bool)name); 1592 instance.name = name; 1593 if (description && description[0]) 1594 instance.description = description; 1595 instance.create_callback = create_callback; 1596 instance.debugger_init_callback = debugger_init_callback; 1597 GetPlatformInstances ().push_back (instance); 1598 return true; 1599 } 1600 return false; 1601 } 1602 1603 const char * 1604 PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx) 1605 { 1606 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1607 PlatformInstances &instances = GetPlatformInstances (); 1608 if (idx < instances.size()) 1609 return instances[idx].name.GetCString(); 1610 return nullptr; 1611 } 1612 1613 const char * 1614 PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx) 1615 { 1616 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1617 PlatformInstances &instances = GetPlatformInstances (); 1618 if (idx < instances.size()) 1619 return instances[idx].description.c_str(); 1620 return nullptr; 1621 } 1622 1623 bool 1624 PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback) 1625 { 1626 if (create_callback) 1627 { 1628 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1629 PlatformInstances &instances = GetPlatformInstances (); 1630 1631 PlatformInstances::iterator pos, end = instances.end(); 1632 for (pos = instances.begin(); pos != end; ++ pos) 1633 { 1634 if (pos->create_callback == create_callback) 1635 { 1636 instances.erase(pos); 1637 return true; 1638 } 1639 } 1640 } 1641 return false; 1642 } 1643 1644 PlatformCreateInstance 1645 PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx) 1646 { 1647 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1648 PlatformInstances &instances = GetPlatformInstances (); 1649 if (idx < instances.size()) 1650 return instances[idx].create_callback; 1651 return nullptr; 1652 } 1653 1654 PlatformCreateInstance 1655 PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name) 1656 { 1657 if (name) 1658 { 1659 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1660 PlatformInstances &instances = GetPlatformInstances (); 1661 1662 PlatformInstances::iterator pos, end = instances.end(); 1663 for (pos = instances.begin(); pos != end; ++ pos) 1664 { 1665 if (name == pos->name) 1666 return pos->create_callback; 1667 } 1668 } 1669 return nullptr; 1670 } 1671 1672 size_t 1673 PluginManager::AutoCompletePlatformName (const char *name, StringList &matches) 1674 { 1675 if (name) 1676 { 1677 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 1678 PlatformInstances &instances = GetPlatformInstances (); 1679 llvm::StringRef name_sref(name); 1680 1681 PlatformInstances::iterator pos, end = instances.end(); 1682 for (pos = instances.begin(); pos != end; ++ pos) 1683 { 1684 llvm::StringRef plugin_name (pos->name.GetCString()); 1685 if (plugin_name.startswith(name_sref)) 1686 matches.AppendString (plugin_name.data()); 1687 } 1688 } 1689 return matches.GetSize(); 1690 } 1691 1692 #pragma mark Process 1693 1694 struct ProcessInstance 1695 { 1696 ProcessInstance() : 1697 name(), 1698 description(), 1699 create_callback(nullptr), 1700 debugger_init_callback(nullptr) 1701 { 1702 } 1703 1704 ConstString name; 1705 std::string description; 1706 ProcessCreateInstance create_callback; 1707 DebuggerInitializeCallback debugger_init_callback; 1708 }; 1709 1710 typedef std::vector<ProcessInstance> ProcessInstances; 1711 1712 static std::recursive_mutex & 1713 GetProcessMutex() 1714 { 1715 static std::recursive_mutex g_instances_mutex; 1716 return g_instances_mutex; 1717 } 1718 1719 static ProcessInstances & 1720 GetProcessInstances () 1721 { 1722 static ProcessInstances g_instances; 1723 return g_instances; 1724 } 1725 1726 bool 1727 PluginManager::RegisterPlugin (const ConstString &name, 1728 const char *description, 1729 ProcessCreateInstance create_callback, 1730 DebuggerInitializeCallback debugger_init_callback) 1731 { 1732 if (create_callback) 1733 { 1734 ProcessInstance instance; 1735 assert ((bool)name); 1736 instance.name = name; 1737 if (description && description[0]) 1738 instance.description = description; 1739 instance.create_callback = create_callback; 1740 instance.debugger_init_callback = debugger_init_callback; 1741 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1742 GetProcessInstances ().push_back (instance); 1743 } 1744 return false; 1745 } 1746 1747 const char * 1748 PluginManager::GetProcessPluginNameAtIndex (uint32_t idx) 1749 { 1750 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1751 ProcessInstances &instances = GetProcessInstances (); 1752 if (idx < instances.size()) 1753 return instances[idx].name.GetCString(); 1754 return nullptr; 1755 } 1756 1757 const char * 1758 PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx) 1759 { 1760 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1761 ProcessInstances &instances = GetProcessInstances (); 1762 if (idx < instances.size()) 1763 return instances[idx].description.c_str(); 1764 return nullptr; 1765 } 1766 1767 bool 1768 PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback) 1769 { 1770 if (create_callback) 1771 { 1772 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1773 ProcessInstances &instances = GetProcessInstances (); 1774 1775 ProcessInstances::iterator pos, end = instances.end(); 1776 for (pos = instances.begin(); pos != end; ++ pos) 1777 { 1778 if (pos->create_callback == create_callback) 1779 { 1780 instances.erase(pos); 1781 return true; 1782 } 1783 } 1784 } 1785 return false; 1786 } 1787 1788 ProcessCreateInstance 1789 PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx) 1790 { 1791 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1792 ProcessInstances &instances = GetProcessInstances (); 1793 if (idx < instances.size()) 1794 return instances[idx].create_callback; 1795 return nullptr; 1796 } 1797 1798 ProcessCreateInstance 1799 PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name) 1800 { 1801 if (name) 1802 { 1803 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 1804 ProcessInstances &instances = GetProcessInstances (); 1805 1806 ProcessInstances::iterator pos, end = instances.end(); 1807 for (pos = instances.begin(); pos != end; ++ pos) 1808 { 1809 if (name == pos->name) 1810 return pos->create_callback; 1811 } 1812 } 1813 return nullptr; 1814 } 1815 1816 #pragma mark ScriptInterpreter 1817 1818 struct ScriptInterpreterInstance 1819 { 1820 ScriptInterpreterInstance() 1821 : name() 1822 , language(lldb::eScriptLanguageNone) 1823 , description() 1824 , create_callback(nullptr) 1825 { 1826 } 1827 1828 ConstString name; 1829 lldb::ScriptLanguage language; 1830 std::string description; 1831 ScriptInterpreterCreateInstance create_callback; 1832 }; 1833 1834 typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances; 1835 1836 static std::recursive_mutex & 1837 GetScriptInterpreterMutex() 1838 { 1839 static std::recursive_mutex g_instances_mutex; 1840 return g_instances_mutex; 1841 } 1842 1843 static ScriptInterpreterInstances & 1844 GetScriptInterpreterInstances() 1845 { 1846 static ScriptInterpreterInstances g_instances; 1847 return g_instances; 1848 } 1849 1850 bool 1851 PluginManager::RegisterPlugin(const ConstString &name, const char *description, lldb::ScriptLanguage script_language, 1852 ScriptInterpreterCreateInstance create_callback) 1853 { 1854 if (!create_callback) 1855 return false; 1856 ScriptInterpreterInstance instance; 1857 assert((bool)name); 1858 instance.name = name; 1859 if (description && description[0]) 1860 instance.description = description; 1861 instance.create_callback = create_callback; 1862 instance.language = script_language; 1863 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); 1864 GetScriptInterpreterInstances().push_back(instance); 1865 return false; 1866 } 1867 1868 bool 1869 PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback) 1870 { 1871 if (!create_callback) 1872 return false; 1873 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); 1874 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); 1875 1876 ScriptInterpreterInstances::iterator pos, end = instances.end(); 1877 for (pos = instances.begin(); pos != end; ++pos) 1878 { 1879 if (pos->create_callback != create_callback) 1880 continue; 1881 1882 instances.erase(pos); 1883 return true; 1884 } 1885 return false; 1886 } 1887 1888 ScriptInterpreterCreateInstance 1889 PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) 1890 { 1891 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); 1892 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); 1893 if (idx < instances.size()) 1894 return instances[idx].create_callback; 1895 return nullptr; 1896 } 1897 1898 lldb::ScriptInterpreterSP 1899 PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) 1900 { 1901 std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); 1902 ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); 1903 1904 ScriptInterpreterInstances::iterator pos, end = instances.end(); 1905 ScriptInterpreterCreateInstance none_instance = nullptr; 1906 for (pos = instances.begin(); pos != end; ++pos) 1907 { 1908 if (pos->language == lldb::eScriptLanguageNone) 1909 none_instance = pos->create_callback; 1910 1911 if (script_lang == pos->language) 1912 return pos->create_callback(interpreter); 1913 } 1914 1915 // If we didn't find one, return the ScriptInterpreter for the null language. 1916 assert(none_instance != nullptr); 1917 return none_instance(interpreter); 1918 } 1919 1920 #pragma mark - 1921 #pragma mark StructuredDataPlugin 1922 1923 // ----------------------------------------------------------------------------- 1924 // StructuredDataPlugin 1925 // ----------------------------------------------------------------------------- 1926 1927 struct StructuredDataPluginInstance 1928 { 1929 StructuredDataPluginInstance() : 1930 name(), 1931 description(), 1932 create_callback(nullptr), 1933 debugger_init_callback(nullptr), 1934 filter_callback(nullptr) 1935 { 1936 } 1937 1938 ConstString name; 1939 std::string description; 1940 StructuredDataPluginCreateInstance create_callback; 1941 DebuggerInitializeCallback debugger_init_callback; 1942 StructuredDataFilterLaunchInfo filter_callback; 1943 }; 1944 1945 typedef std::vector<StructuredDataPluginInstance> StructuredDataPluginInstances; 1946 1947 static std::recursive_mutex & 1948 GetStructuredDataPluginMutex() 1949 { 1950 static std::recursive_mutex g_instances_mutex; 1951 return g_instances_mutex; 1952 } 1953 1954 static StructuredDataPluginInstances & 1955 GetStructuredDataPluginInstances () 1956 { 1957 static StructuredDataPluginInstances g_instances; 1958 return g_instances; 1959 } 1960 1961 bool 1962 PluginManager::RegisterPlugin(const ConstString &name, 1963 const char *description, 1964 StructuredDataPluginCreateInstance 1965 create_callback, 1966 DebuggerInitializeCallback debugger_init_callback, 1967 StructuredDataFilterLaunchInfo filter_callback) 1968 { 1969 if (create_callback) 1970 { 1971 StructuredDataPluginInstance instance; 1972 assert((bool)name); 1973 instance.name = name; 1974 if (description && description[0]) 1975 instance.description = description; 1976 instance.create_callback = create_callback; 1977 instance.debugger_init_callback = debugger_init_callback; 1978 instance.filter_callback = filter_callback; 1979 std::lock_guard<std::recursive_mutex> guard( 1980 GetStructuredDataPluginMutex()); 1981 GetStructuredDataPluginInstances().push_back(instance); 1982 } 1983 return false; 1984 } 1985 1986 bool 1987 PluginManager::UnregisterPlugin(StructuredDataPluginCreateInstance create_callback) 1988 { 1989 if (create_callback) 1990 { 1991 std::lock_guard<std::recursive_mutex> guard( 1992 GetStructuredDataPluginMutex()); 1993 StructuredDataPluginInstances &instances = 1994 GetStructuredDataPluginInstances(); 1995 1996 StructuredDataPluginInstances::iterator pos, end = instances.end(); 1997 for (pos = instances.begin(); pos != end; ++ pos) 1998 { 1999 if (pos->create_callback == create_callback) 2000 { 2001 instances.erase(pos); 2002 return true; 2003 } 2004 } 2005 } 2006 return false; 2007 } 2008 2009 StructuredDataPluginCreateInstance 2010 PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) 2011 { 2012 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); 2013 StructuredDataPluginInstances &instances = 2014 GetStructuredDataPluginInstances(); 2015 if (idx < instances.size()) 2016 return instances[idx].create_callback; 2017 return nullptr; 2018 } 2019 2020 StructuredDataPluginCreateInstance 2021 PluginManager::GetStructuredDataPluginCreateCallbackForPluginName( 2022 const ConstString &name) 2023 { 2024 if (name) 2025 { 2026 std::lock_guard<std::recursive_mutex> guard( 2027 GetStructuredDataPluginMutex()); 2028 StructuredDataPluginInstances &instances = 2029 GetStructuredDataPluginInstances(); 2030 2031 StructuredDataPluginInstances::iterator pos, end = instances.end(); 2032 for (pos = instances.begin(); pos != end; ++ pos) 2033 { 2034 if (name == pos->name) 2035 return pos->create_callback; 2036 } 2037 } 2038 return nullptr; 2039 } 2040 2041 StructuredDataFilterLaunchInfo 2042 PluginManager::GetStructuredDataFilterCallbackAtIndex(uint32_t idx, 2043 bool &iteration_complete) 2044 { 2045 std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex()); 2046 StructuredDataPluginInstances &instances = 2047 GetStructuredDataPluginInstances(); 2048 if (idx < instances.size()) 2049 { 2050 iteration_complete = false; 2051 return instances[idx].filter_callback; 2052 } 2053 else 2054 { 2055 iteration_complete = true; 2056 } 2057 return nullptr; 2058 } 2059 2060 #pragma mark SymbolFile 2061 2062 struct SymbolFileInstance 2063 { 2064 SymbolFileInstance() : 2065 name(), 2066 description(), 2067 create_callback(nullptr), 2068 debugger_init_callback(nullptr) 2069 { 2070 } 2071 2072 ConstString name; 2073 std::string description; 2074 SymbolFileCreateInstance create_callback; 2075 DebuggerInitializeCallback debugger_init_callback; 2076 }; 2077 2078 typedef std::vector<SymbolFileInstance> SymbolFileInstances; 2079 2080 static std::recursive_mutex & 2081 GetSymbolFileMutex() 2082 { 2083 static std::recursive_mutex g_instances_mutex; 2084 return g_instances_mutex; 2085 } 2086 2087 static SymbolFileInstances & 2088 GetSymbolFileInstances () 2089 { 2090 static SymbolFileInstances g_instances; 2091 return g_instances; 2092 } 2093 2094 bool 2095 PluginManager::RegisterPlugin(const ConstString &name, 2096 const char *description, 2097 SymbolFileCreateInstance create_callback, 2098 DebuggerInitializeCallback debugger_init_callback) 2099 { 2100 if (create_callback) 2101 { 2102 SymbolFileInstance instance; 2103 assert ((bool)name); 2104 instance.name = name; 2105 if (description && description[0]) 2106 instance.description = description; 2107 instance.create_callback = create_callback; 2108 instance.debugger_init_callback = debugger_init_callback; 2109 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); 2110 GetSymbolFileInstances ().push_back (instance); 2111 } 2112 return false; 2113 } 2114 2115 bool 2116 PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback) 2117 { 2118 if (create_callback) 2119 { 2120 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); 2121 SymbolFileInstances &instances = GetSymbolFileInstances (); 2122 2123 SymbolFileInstances::iterator pos, end = instances.end(); 2124 for (pos = instances.begin(); pos != end; ++ pos) 2125 { 2126 if (pos->create_callback == create_callback) 2127 { 2128 instances.erase(pos); 2129 return true; 2130 } 2131 } 2132 } 2133 return false; 2134 } 2135 2136 SymbolFileCreateInstance 2137 PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx) 2138 { 2139 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); 2140 SymbolFileInstances &instances = GetSymbolFileInstances (); 2141 if (idx < instances.size()) 2142 return instances[idx].create_callback; 2143 return nullptr; 2144 } 2145 2146 SymbolFileCreateInstance 2147 PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name) 2148 { 2149 if (name) 2150 { 2151 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); 2152 SymbolFileInstances &instances = GetSymbolFileInstances (); 2153 2154 SymbolFileInstances::iterator pos, end = instances.end(); 2155 for (pos = instances.begin(); pos != end; ++ pos) 2156 { 2157 if (name == pos->name) 2158 return pos->create_callback; 2159 } 2160 } 2161 return nullptr; 2162 } 2163 2164 #pragma mark SymbolVendor 2165 2166 struct SymbolVendorInstance 2167 { 2168 SymbolVendorInstance() : 2169 name(), 2170 description(), 2171 create_callback(nullptr) 2172 { 2173 } 2174 2175 ConstString name; 2176 std::string description; 2177 SymbolVendorCreateInstance create_callback; 2178 }; 2179 2180 typedef std::vector<SymbolVendorInstance> SymbolVendorInstances; 2181 2182 static std::recursive_mutex & 2183 GetSymbolVendorMutex() 2184 { 2185 static std::recursive_mutex g_instances_mutex; 2186 return g_instances_mutex; 2187 } 2188 2189 static SymbolVendorInstances & 2190 GetSymbolVendorInstances () 2191 { 2192 static SymbolVendorInstances g_instances; 2193 return g_instances; 2194 } 2195 2196 bool 2197 PluginManager::RegisterPlugin(const ConstString &name, 2198 const char *description, 2199 SymbolVendorCreateInstance create_callback) 2200 { 2201 if (create_callback) 2202 { 2203 SymbolVendorInstance instance; 2204 assert ((bool)name); 2205 instance.name = name; 2206 if (description && description[0]) 2207 instance.description = description; 2208 instance.create_callback = create_callback; 2209 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); 2210 GetSymbolVendorInstances ().push_back (instance); 2211 } 2212 return false; 2213 } 2214 2215 bool 2216 PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback) 2217 { 2218 if (create_callback) 2219 { 2220 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); 2221 SymbolVendorInstances &instances = GetSymbolVendorInstances (); 2222 2223 SymbolVendorInstances::iterator pos, end = instances.end(); 2224 for (pos = instances.begin(); pos != end; ++ pos) 2225 { 2226 if (pos->create_callback == create_callback) 2227 { 2228 instances.erase(pos); 2229 return true; 2230 } 2231 } 2232 } 2233 return false; 2234 } 2235 2236 SymbolVendorCreateInstance 2237 PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx) 2238 { 2239 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); 2240 SymbolVendorInstances &instances = GetSymbolVendorInstances (); 2241 if (idx < instances.size()) 2242 return instances[idx].create_callback; 2243 return nullptr; 2244 } 2245 2246 SymbolVendorCreateInstance 2247 PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &name) 2248 { 2249 if (name) 2250 { 2251 std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); 2252 SymbolVendorInstances &instances = GetSymbolVendorInstances (); 2253 2254 SymbolVendorInstances::iterator pos, end = instances.end(); 2255 for (pos = instances.begin(); pos != end; ++ pos) 2256 { 2257 if (name == pos->name) 2258 return pos->create_callback; 2259 } 2260 } 2261 return nullptr; 2262 } 2263 2264 #pragma mark UnwindAssembly 2265 2266 struct UnwindAssemblyInstance 2267 { 2268 UnwindAssemblyInstance() : 2269 name(), 2270 description(), 2271 create_callback(nullptr) 2272 { 2273 } 2274 2275 ConstString name; 2276 std::string description; 2277 UnwindAssemblyCreateInstance create_callback; 2278 }; 2279 2280 typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances; 2281 2282 static std::recursive_mutex & 2283 GetUnwindAssemblyMutex() 2284 { 2285 static std::recursive_mutex g_instances_mutex; 2286 return g_instances_mutex; 2287 } 2288 2289 static UnwindAssemblyInstances & 2290 GetUnwindAssemblyInstances () 2291 { 2292 static UnwindAssemblyInstances g_instances; 2293 return g_instances; 2294 } 2295 2296 bool 2297 PluginManager::RegisterPlugin(const ConstString &name, 2298 const char *description, 2299 UnwindAssemblyCreateInstance create_callback) 2300 { 2301 if (create_callback) 2302 { 2303 UnwindAssemblyInstance instance; 2304 assert ((bool)name); 2305 instance.name = name; 2306 if (description && description[0]) 2307 instance.description = description; 2308 instance.create_callback = create_callback; 2309 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); 2310 GetUnwindAssemblyInstances ().push_back (instance); 2311 } 2312 return false; 2313 } 2314 2315 bool 2316 PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback) 2317 { 2318 if (create_callback) 2319 { 2320 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); 2321 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); 2322 2323 UnwindAssemblyInstances::iterator pos, end = instances.end(); 2324 for (pos = instances.begin(); pos != end; ++ pos) 2325 { 2326 if (pos->create_callback == create_callback) 2327 { 2328 instances.erase(pos); 2329 return true; 2330 } 2331 } 2332 } 2333 return false; 2334 } 2335 2336 UnwindAssemblyCreateInstance 2337 PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx) 2338 { 2339 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); 2340 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); 2341 if (idx < instances.size()) 2342 return instances[idx].create_callback; 2343 return nullptr; 2344 } 2345 2346 UnwindAssemblyCreateInstance 2347 PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &name) 2348 { 2349 if (name) 2350 { 2351 std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); 2352 UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); 2353 2354 UnwindAssemblyInstances::iterator pos, end = instances.end(); 2355 for (pos = instances.begin(); pos != end; ++ pos) 2356 { 2357 if (name == pos->name) 2358 return pos->create_callback; 2359 } 2360 } 2361 return nullptr; 2362 } 2363 2364 #pragma mark MemoryHistory 2365 2366 struct MemoryHistoryInstance 2367 { 2368 MemoryHistoryInstance() : 2369 name(), 2370 description(), 2371 create_callback(nullptr) 2372 { 2373 } 2374 2375 ConstString name; 2376 std::string description; 2377 MemoryHistoryCreateInstance create_callback; 2378 }; 2379 2380 typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances; 2381 2382 static std::recursive_mutex & 2383 GetMemoryHistoryMutex() 2384 { 2385 static std::recursive_mutex g_instances_mutex; 2386 return g_instances_mutex; 2387 } 2388 2389 static MemoryHistoryInstances & 2390 GetMemoryHistoryInstances () 2391 { 2392 static MemoryHistoryInstances g_instances; 2393 return g_instances; 2394 } 2395 2396 bool 2397 PluginManager::RegisterPlugin(const ConstString &name, 2398 const char *description, 2399 MemoryHistoryCreateInstance create_callback) 2400 { 2401 if (create_callback) 2402 { 2403 MemoryHistoryInstance instance; 2404 assert ((bool)name); 2405 instance.name = name; 2406 if (description && description[0]) 2407 instance.description = description; 2408 instance.create_callback = create_callback; 2409 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); 2410 GetMemoryHistoryInstances ().push_back (instance); 2411 } 2412 return false; 2413 } 2414 2415 bool 2416 PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback) 2417 { 2418 if (create_callback) 2419 { 2420 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); 2421 MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); 2422 2423 MemoryHistoryInstances::iterator pos, end = instances.end(); 2424 for (pos = instances.begin(); pos != end; ++ pos) 2425 { 2426 if (pos->create_callback == create_callback) 2427 { 2428 instances.erase(pos); 2429 return true; 2430 } 2431 } 2432 } 2433 return false; 2434 } 2435 2436 MemoryHistoryCreateInstance 2437 PluginManager::GetMemoryHistoryCreateCallbackAtIndex (uint32_t idx) 2438 { 2439 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); 2440 MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); 2441 if (idx < instances.size()) 2442 return instances[idx].create_callback; 2443 return nullptr; 2444 } 2445 2446 MemoryHistoryCreateInstance 2447 PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &name) 2448 { 2449 if (name) 2450 { 2451 std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); 2452 MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); 2453 2454 MemoryHistoryInstances::iterator pos, end = instances.end(); 2455 for (pos = instances.begin(); pos != end; ++ pos) 2456 { 2457 if (name == pos->name) 2458 return pos->create_callback; 2459 } 2460 } 2461 return nullptr; 2462 } 2463 2464 #pragma mark InstrumentationRuntime 2465 2466 struct InstrumentationRuntimeInstance 2467 { 2468 InstrumentationRuntimeInstance() : 2469 name(), 2470 description(), 2471 create_callback(nullptr) 2472 { 2473 } 2474 2475 ConstString name; 2476 std::string description; 2477 InstrumentationRuntimeCreateInstance create_callback; 2478 InstrumentationRuntimeGetType get_type_callback; 2479 }; 2480 2481 typedef std::vector<InstrumentationRuntimeInstance> InstrumentationRuntimeInstances; 2482 2483 static std::recursive_mutex & 2484 GetInstrumentationRuntimeMutex() 2485 { 2486 static std::recursive_mutex g_instances_mutex; 2487 return g_instances_mutex; 2488 } 2489 2490 static InstrumentationRuntimeInstances & 2491 GetInstrumentationRuntimeInstances () 2492 { 2493 static InstrumentationRuntimeInstances g_instances; 2494 return g_instances; 2495 } 2496 2497 bool 2498 PluginManager::RegisterPlugin(const ConstString &name, 2499 const char *description, 2500 InstrumentationRuntimeCreateInstance create_callback, 2501 InstrumentationRuntimeGetType get_type_callback) 2502 { 2503 if (create_callback) 2504 { 2505 InstrumentationRuntimeInstance instance; 2506 assert ((bool)name); 2507 instance.name = name; 2508 if (description && description[0]) 2509 instance.description = description; 2510 instance.create_callback = create_callback; 2511 instance.get_type_callback = get_type_callback; 2512 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); 2513 GetInstrumentationRuntimeInstances ().push_back (instance); 2514 } 2515 return false; 2516 } 2517 2518 bool 2519 PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_callback) 2520 { 2521 if (create_callback) 2522 { 2523 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); 2524 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); 2525 2526 InstrumentationRuntimeInstances::iterator pos, end = instances.end(); 2527 for (pos = instances.begin(); pos != end; ++ pos) 2528 { 2529 if (pos->create_callback == create_callback) 2530 { 2531 instances.erase(pos); 2532 return true; 2533 } 2534 } 2535 } 2536 return false; 2537 } 2538 2539 InstrumentationRuntimeGetType 2540 PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx) 2541 { 2542 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); 2543 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); 2544 if (idx < instances.size()) 2545 return instances[idx].get_type_callback; 2546 return nullptr; 2547 } 2548 2549 InstrumentationRuntimeCreateInstance 2550 PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex (uint32_t idx) 2551 { 2552 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); 2553 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); 2554 if (idx < instances.size()) 2555 return instances[idx].create_callback; 2556 return nullptr; 2557 } 2558 2559 InstrumentationRuntimeCreateInstance 2560 PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const ConstString &name) 2561 { 2562 if (name) 2563 { 2564 std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); 2565 InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); 2566 2567 InstrumentationRuntimeInstances::iterator pos, end = instances.end(); 2568 for (pos = instances.begin(); pos != end; ++ pos) 2569 { 2570 if (name == pos->name) 2571 return pos->create_callback; 2572 } 2573 } 2574 return nullptr; 2575 } 2576 2577 #pragma mark TypeSystem 2578 2579 struct TypeSystemInstance 2580 { 2581 TypeSystemInstance() : 2582 name(), 2583 description(), 2584 create_callback(nullptr) 2585 { 2586 } 2587 2588 ConstString name; 2589 std::string description; 2590 TypeSystemCreateInstance create_callback; 2591 TypeSystemEnumerateSupportedLanguages enumerate_callback; 2592 }; 2593 2594 typedef std::vector<TypeSystemInstance> TypeSystemInstances; 2595 2596 static std::recursive_mutex & 2597 GetTypeSystemMutex() 2598 { 2599 static std::recursive_mutex g_instances_mutex; 2600 return g_instances_mutex; 2601 } 2602 2603 static TypeSystemInstances & 2604 GetTypeSystemInstances () 2605 { 2606 static TypeSystemInstances g_instances; 2607 return g_instances; 2608 } 2609 2610 bool 2611 PluginManager::RegisterPlugin (const ConstString &name, 2612 const char *description, 2613 TypeSystemCreateInstance create_callback, 2614 TypeSystemEnumerateSupportedLanguages enumerate_supported_languages_callback) 2615 { 2616 if (create_callback) 2617 { 2618 TypeSystemInstance instance; 2619 assert ((bool)name); 2620 instance.name = name; 2621 if (description && description[0]) 2622 instance.description = description; 2623 instance.create_callback = create_callback; 2624 instance.enumerate_callback = enumerate_supported_languages_callback; 2625 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2626 GetTypeSystemInstances ().push_back (instance); 2627 } 2628 return false; 2629 } 2630 2631 bool 2632 PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback) 2633 { 2634 if (create_callback) 2635 { 2636 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2637 TypeSystemInstances &instances = GetTypeSystemInstances (); 2638 2639 TypeSystemInstances::iterator pos, end = instances.end(); 2640 for (pos = instances.begin(); pos != end; ++ pos) 2641 { 2642 if (pos->create_callback == create_callback) 2643 { 2644 instances.erase(pos); 2645 return true; 2646 } 2647 } 2648 } 2649 return false; 2650 } 2651 2652 TypeSystemCreateInstance 2653 PluginManager::GetTypeSystemCreateCallbackAtIndex (uint32_t idx) 2654 { 2655 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2656 TypeSystemInstances &instances = GetTypeSystemInstances (); 2657 if (idx < instances.size()) 2658 return instances[idx].create_callback; 2659 return nullptr; 2660 } 2661 2662 TypeSystemCreateInstance 2663 PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name) 2664 { 2665 if (name) 2666 { 2667 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2668 TypeSystemInstances &instances = GetTypeSystemInstances (); 2669 2670 TypeSystemInstances::iterator pos, end = instances.end(); 2671 for (pos = instances.begin(); pos != end; ++ pos) 2672 { 2673 if (name == pos->name) 2674 return pos->create_callback; 2675 } 2676 } 2677 return nullptr; 2678 } 2679 2680 TypeSystemEnumerateSupportedLanguages 2681 PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx) 2682 { 2683 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2684 TypeSystemInstances &instances = GetTypeSystemInstances (); 2685 if (idx < instances.size()) 2686 return instances[idx].enumerate_callback; 2687 return nullptr; 2688 } 2689 2690 TypeSystemEnumerateSupportedLanguages 2691 PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name) 2692 { 2693 if (name) 2694 { 2695 std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); 2696 TypeSystemInstances &instances = GetTypeSystemInstances (); 2697 2698 TypeSystemInstances::iterator pos, end = instances.end(); 2699 for (pos = instances.begin(); pos != end; ++ pos) 2700 { 2701 if (name == pos->name) 2702 return pos->enumerate_callback; 2703 } 2704 } 2705 return nullptr; 2706 } 2707 2708 #pragma mark REPL 2709 2710 struct REPLInstance 2711 { 2712 REPLInstance() : 2713 name(), 2714 description(), 2715 create_callback(nullptr) 2716 { 2717 } 2718 2719 ConstString name; 2720 std::string description; 2721 REPLCreateInstance create_callback; 2722 REPLEnumerateSupportedLanguages enumerate_languages_callback; 2723 }; 2724 2725 typedef std::vector<REPLInstance> REPLInstances; 2726 2727 static std::recursive_mutex & 2728 GetREPLMutex() 2729 { 2730 static std::recursive_mutex g_instances_mutex; 2731 return g_instances_mutex; 2732 } 2733 2734 static REPLInstances & 2735 GetREPLInstances () 2736 { 2737 static REPLInstances g_instances; 2738 return g_instances; 2739 } 2740 2741 bool 2742 PluginManager::RegisterPlugin (const ConstString &name, 2743 const char *description, 2744 REPLCreateInstance create_callback, 2745 REPLEnumerateSupportedLanguages enumerate_languages_callback) 2746 { 2747 if (create_callback) 2748 { 2749 REPLInstance instance; 2750 assert ((bool)name); 2751 instance.name = name; 2752 if (description && description[0]) 2753 instance.description = description; 2754 instance.create_callback = create_callback; 2755 instance.enumerate_languages_callback = enumerate_languages_callback; 2756 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2757 GetREPLInstances ().push_back (instance); 2758 } 2759 return false; 2760 } 2761 2762 bool 2763 PluginManager::UnregisterPlugin (REPLCreateInstance create_callback) 2764 { 2765 if (create_callback) 2766 { 2767 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2768 REPLInstances &instances = GetREPLInstances (); 2769 2770 REPLInstances::iterator pos, end = instances.end(); 2771 for (pos = instances.begin(); pos != end; ++ pos) 2772 { 2773 if (pos->create_callback == create_callback) 2774 { 2775 instances.erase(pos); 2776 return true; 2777 } 2778 } 2779 } 2780 return false; 2781 } 2782 2783 REPLCreateInstance 2784 PluginManager::GetREPLCreateCallbackAtIndex (uint32_t idx) 2785 { 2786 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2787 REPLInstances &instances = GetREPLInstances (); 2788 if (idx < instances.size()) 2789 return instances[idx].create_callback; 2790 return nullptr; 2791 } 2792 2793 REPLCreateInstance 2794 PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name) 2795 { 2796 if (name) 2797 { 2798 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2799 REPLInstances &instances = GetREPLInstances (); 2800 2801 REPLInstances::iterator pos, end = instances.end(); 2802 for (pos = instances.begin(); pos != end; ++ pos) 2803 { 2804 if (name == pos->name) 2805 return pos->create_callback; 2806 } 2807 } 2808 return nullptr; 2809 } 2810 2811 REPLEnumerateSupportedLanguages 2812 PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx) 2813 { 2814 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2815 REPLInstances &instances = GetREPLInstances (); 2816 if (idx < instances.size()) 2817 return instances[idx].enumerate_languages_callback; 2818 return nullptr; 2819 } 2820 2821 REPLEnumerateSupportedLanguages 2822 PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name) 2823 { 2824 if (name) 2825 { 2826 std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); 2827 REPLInstances &instances = GetREPLInstances (); 2828 2829 REPLInstances::iterator pos, end = instances.end(); 2830 for (pos = instances.begin(); pos != end; ++ pos) 2831 { 2832 if (name == pos->name) 2833 return pos->enumerate_languages_callback; 2834 } 2835 } 2836 return nullptr; 2837 } 2838 2839 #pragma mark PluginManager 2840 2841 void 2842 PluginManager::DebuggerInitialize (Debugger &debugger) 2843 { 2844 // Initialize the DynamicLoader plugins 2845 { 2846 std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); 2847 DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); 2848 2849 DynamicLoaderInstances::iterator pos, end = instances.end(); 2850 for (pos = instances.begin(); pos != end; ++ pos) 2851 { 2852 if (pos->debugger_init_callback) 2853 pos->debugger_init_callback (debugger); 2854 } 2855 } 2856 2857 // Initialize the JITLoader plugins 2858 { 2859 std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); 2860 JITLoaderInstances &instances = GetJITLoaderInstances (); 2861 2862 JITLoaderInstances::iterator pos, end = instances.end(); 2863 for (pos = instances.begin(); pos != end; ++ pos) 2864 { 2865 if (pos->debugger_init_callback) 2866 pos->debugger_init_callback (debugger); 2867 } 2868 } 2869 2870 // Initialize the Platform plugins 2871 { 2872 std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); 2873 PlatformInstances &instances = GetPlatformInstances (); 2874 2875 PlatformInstances::iterator pos, end = instances.end(); 2876 for (pos = instances.begin(); pos != end; ++ pos) 2877 { 2878 if (pos->debugger_init_callback) 2879 pos->debugger_init_callback (debugger); 2880 } 2881 } 2882 2883 // Initialize the Process plugins 2884 { 2885 std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); 2886 ProcessInstances &instances = GetProcessInstances(); 2887 2888 ProcessInstances::iterator pos, end = instances.end(); 2889 for (pos = instances.begin(); pos != end; ++ pos) 2890 { 2891 if (pos->debugger_init_callback) 2892 pos->debugger_init_callback (debugger); 2893 } 2894 } 2895 2896 // Initialize the SymbolFile plugins 2897 { 2898 std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); 2899 for (auto& sym_file: GetSymbolFileInstances()) 2900 { 2901 if (sym_file.debugger_init_callback) 2902 sym_file.debugger_init_callback (debugger); 2903 } 2904 } 2905 2906 // Initialize the OperatingSystem plugins 2907 { 2908 std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); 2909 for (auto &os : GetOperatingSystemInstances()) 2910 { 2911 if (os.debugger_init_callback) 2912 os.debugger_init_callback(debugger); 2913 } 2914 } 2915 2916 // Initialize the StructuredDataPlugin plugins 2917 { 2918 std::lock_guard<std::recursive_mutex> 2919 guard(GetStructuredDataPluginMutex()); 2920 for (auto &plugin: GetStructuredDataPluginInstances()) 2921 { 2922 if (plugin.debugger_init_callback) 2923 plugin.debugger_init_callback(debugger); 2924 } 2925 } 2926 } 2927 2928 // This is the preferred new way to register plugin specific settings. e.g. 2929 // This will put a plugin's settings under e.g. "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME". 2930 static lldb::OptionValuePropertiesSP 2931 GetDebuggerPropertyForPlugins (Debugger &debugger, 2932 const ConstString &plugin_type_name, 2933 const ConstString &plugin_type_desc, 2934 bool can_create) 2935 { 2936 lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties()); 2937 if (parent_properties_sp) 2938 { 2939 static ConstString g_property_name("plugin"); 2940 2941 OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, g_property_name); 2942 if (!plugin_properties_sp && can_create) 2943 { 2944 plugin_properties_sp.reset (new OptionValueProperties (g_property_name)); 2945 parent_properties_sp->AppendProperty (g_property_name, 2946 ConstString("Settings specify to plugins."), 2947 true, 2948 plugin_properties_sp); 2949 } 2950 2951 if (plugin_properties_sp) 2952 { 2953 lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name); 2954 if (!plugin_type_properties_sp && can_create) 2955 { 2956 plugin_type_properties_sp.reset (new OptionValueProperties (plugin_type_name)); 2957 plugin_properties_sp->AppendProperty (plugin_type_name, 2958 plugin_type_desc, 2959 true, 2960 plugin_type_properties_sp); 2961 } 2962 return plugin_type_properties_sp; 2963 } 2964 } 2965 return lldb::OptionValuePropertiesSP(); 2966 } 2967 2968 // This is deprecated way to register plugin specific settings. e.g. 2969 // "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" 2970 // and Platform generic settings would be under "platform.SETTINGNAME". 2971 static lldb::OptionValuePropertiesSP 2972 GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger, 2973 const ConstString &plugin_type_name, 2974 const ConstString &plugin_type_desc, 2975 bool can_create) 2976 { 2977 static ConstString g_property_name("plugin"); 2978 lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties()); 2979 if (parent_properties_sp) 2980 { 2981 OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, plugin_type_name); 2982 if (!plugin_properties_sp && can_create) 2983 { 2984 plugin_properties_sp.reset (new OptionValueProperties (plugin_type_name)); 2985 parent_properties_sp->AppendProperty (plugin_type_name, 2986 plugin_type_desc, 2987 true, 2988 plugin_properties_sp); 2989 } 2990 2991 if (plugin_properties_sp) 2992 { 2993 lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, g_property_name); 2994 if (!plugin_type_properties_sp && can_create) 2995 { 2996 plugin_type_properties_sp.reset (new OptionValueProperties (g_property_name)); 2997 plugin_properties_sp->AppendProperty (g_property_name, 2998 ConstString("Settings specific to plugins"), 2999 true, 3000 plugin_type_properties_sp); 3001 } 3002 return plugin_type_properties_sp; 3003 } 3004 } 3005 return lldb::OptionValuePropertiesSP(); 3006 } 3007 3008 namespace { 3009 3010 typedef lldb::OptionValuePropertiesSP 3011 GetDebuggerPropertyForPluginsPtr (Debugger&, const ConstString&, const ConstString&, bool can_create); 3012 3013 lldb::OptionValuePropertiesSP 3014 GetSettingForPlugin (Debugger &debugger, 3015 const ConstString &setting_name, 3016 const ConstString &plugin_type_name, 3017 GetDebuggerPropertyForPluginsPtr get_debugger_property= GetDebuggerPropertyForPlugins) 3018 { 3019 lldb::OptionValuePropertiesSP properties_sp; 3020 lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (debugger, 3021 plugin_type_name, 3022 ConstString(), // not creating to so we don't need the description 3023 false)); 3024 if (plugin_type_properties_sp) 3025 properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name); 3026 return properties_sp; 3027 } 3028 3029 bool 3030 CreateSettingForPlugin (Debugger &debugger, 3031 const ConstString &plugin_type_name, 3032 const ConstString &plugin_type_desc, 3033 const lldb::OptionValuePropertiesSP &properties_sp, 3034 const ConstString &description, 3035 bool is_global_property, 3036 GetDebuggerPropertyForPluginsPtr get_debugger_property = GetDebuggerPropertyForPlugins) 3037 { 3038 if (properties_sp) 3039 { 3040 lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property ( 3041 debugger, plugin_type_name, plugin_type_desc, true)); 3042 if (plugin_type_properties_sp) 3043 { 3044 plugin_type_properties_sp->AppendProperty (properties_sp->GetName(), 3045 description, 3046 is_global_property, 3047 properties_sp); 3048 return true; 3049 } 3050 } 3051 return false; 3052 } 3053 3054 const char* kDynamicLoaderPluginName("dynamic-loader"); 3055 const char* kPlatformPluginName("platform"); 3056 const char* kProcessPluginName("process"); 3057 const char* kSymbolFilePluginName("symbol-file"); 3058 const char* kJITLoaderPluginName("jit-loader"); 3059 const char* kStructuredDataPluginName("structured-data"); 3060 3061 } // anonymous namespace 3062 3063 lldb::OptionValuePropertiesSP 3064 PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger, 3065 const ConstString &setting_name) 3066 { 3067 return GetSettingForPlugin(debugger, setting_name, ConstString(kDynamicLoaderPluginName)); 3068 } 3069 3070 bool 3071 PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger, 3072 const lldb::OptionValuePropertiesSP &properties_sp, 3073 const ConstString &description, 3074 bool is_global_property) 3075 { 3076 return CreateSettingForPlugin(debugger, 3077 ConstString(kDynamicLoaderPluginName), 3078 ConstString("Settings for dynamic loader plug-ins"), 3079 properties_sp, 3080 description, 3081 is_global_property); 3082 } 3083 3084 lldb::OptionValuePropertiesSP 3085 PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name) 3086 { 3087 return GetSettingForPlugin(debugger, 3088 setting_name, 3089 ConstString(kPlatformPluginName), 3090 GetDebuggerPropertyForPluginsOldStyle); 3091 } 3092 3093 bool 3094 PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger, 3095 const lldb::OptionValuePropertiesSP &properties_sp, 3096 const ConstString &description, 3097 bool is_global_property) 3098 { 3099 return CreateSettingForPlugin(debugger, 3100 ConstString(kPlatformPluginName), 3101 ConstString("Settings for platform plug-ins"), 3102 properties_sp, 3103 description, 3104 is_global_property, 3105 GetDebuggerPropertyForPluginsOldStyle); 3106 } 3107 3108 lldb::OptionValuePropertiesSP 3109 PluginManager::GetSettingForProcessPlugin (Debugger &debugger, const ConstString &setting_name) 3110 { 3111 return GetSettingForPlugin(debugger, setting_name, ConstString(kProcessPluginName)); 3112 } 3113 3114 bool 3115 PluginManager::CreateSettingForProcessPlugin (Debugger &debugger, 3116 const lldb::OptionValuePropertiesSP &properties_sp, 3117 const ConstString &description, 3118 bool is_global_property) 3119 { 3120 return CreateSettingForPlugin(debugger, 3121 ConstString(kProcessPluginName), 3122 ConstString("Settings for process plug-ins"), 3123 properties_sp, 3124 description, 3125 is_global_property); 3126 } 3127 3128 lldb::OptionValuePropertiesSP 3129 PluginManager::GetSettingForSymbolFilePlugin (Debugger &debugger, 3130 const ConstString &setting_name) 3131 { 3132 return GetSettingForPlugin(debugger, setting_name, ConstString(kSymbolFilePluginName)); 3133 } 3134 3135 bool 3136 PluginManager::CreateSettingForSymbolFilePlugin (Debugger &debugger, 3137 const lldb::OptionValuePropertiesSP &properties_sp, 3138 const ConstString &description, 3139 bool is_global_property) 3140 { 3141 return CreateSettingForPlugin(debugger, 3142 ConstString(kSymbolFilePluginName), 3143 ConstString("Settings for symbol file plug-ins"), 3144 properties_sp, 3145 description, 3146 is_global_property); 3147 } 3148 3149 lldb::OptionValuePropertiesSP 3150 PluginManager::GetSettingForJITLoaderPlugin (Debugger &debugger, 3151 const ConstString &setting_name) 3152 { 3153 return GetSettingForPlugin(debugger, setting_name, ConstString(kJITLoaderPluginName)); 3154 } 3155 3156 bool 3157 PluginManager::CreateSettingForJITLoaderPlugin (Debugger &debugger, 3158 const lldb::OptionValuePropertiesSP &properties_sp, 3159 const ConstString &description, 3160 bool is_global_property) 3161 { 3162 return CreateSettingForPlugin(debugger, 3163 ConstString(kJITLoaderPluginName), 3164 ConstString("Settings for JIT loader plug-ins"), 3165 properties_sp, 3166 description, 3167 is_global_property); 3168 } 3169 3170 static const char *kOperatingSystemPluginName("os"); 3171 3172 lldb::OptionValuePropertiesSP 3173 PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger, const ConstString &setting_name) 3174 { 3175 lldb::OptionValuePropertiesSP properties_sp; 3176 lldb::OptionValuePropertiesSP plugin_type_properties_sp( 3177 GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName), 3178 ConstString(), // not creating to so we don't need the description 3179 false)); 3180 if (plugin_type_properties_sp) 3181 properties_sp = plugin_type_properties_sp->GetSubProperty(nullptr, setting_name); 3182 return properties_sp; 3183 } 3184 3185 bool 3186 PluginManager::CreateSettingForOperatingSystemPlugin(Debugger &debugger, 3187 const lldb::OptionValuePropertiesSP &properties_sp, 3188 const ConstString &description, bool is_global_property) 3189 { 3190 if (properties_sp) 3191 { 3192 lldb::OptionValuePropertiesSP plugin_type_properties_sp( 3193 GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName), 3194 ConstString("Settings for operating system plug-ins"), true)); 3195 if (plugin_type_properties_sp) 3196 { 3197 plugin_type_properties_sp->AppendProperty(properties_sp->GetName(), description, is_global_property, 3198 properties_sp); 3199 return true; 3200 } 3201 } 3202 return false; 3203 } 3204 3205 lldb::OptionValuePropertiesSP 3206 PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger, 3207 const ConstString &setting_name) 3208 { 3209 return GetSettingForPlugin(debugger, setting_name, ConstString(kStructuredDataPluginName)); 3210 } 3211 3212 bool 3213 PluginManager::CreateSettingForStructuredDataPlugin(Debugger &debugger, 3214 const lldb::OptionValuePropertiesSP &properties_sp, 3215 const ConstString &description, 3216 bool is_global_property) 3217 { 3218 return CreateSettingForPlugin(debugger, 3219 ConstString(kStructuredDataPluginName), 3220 ConstString("Settings for structured data plug-ins"), 3221 properties_sp, 3222 description, 3223 is_global_property); 3224 } 3225