diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 94dc44ee28600d..556febcbfda960 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -197,16 +197,25 @@ void PluginManager::Terminate() { plugin_map.clear(); } -#pragma mark ABI - -struct ABIInstance { - ABIInstance() : name(), description(), create_callback(nullptr) {} +template struct PluginInstance { + PluginInstance() = default; + PluginInstance(ConstString name, std::string description, + Callback create_callback = nullptr, + DebuggerInitializeCallback debugger_init_callback = nullptr) + : name(name), description(std::move(description)), + create_callback(create_callback), + debugger_init_callback(debugger_init_callback) {} ConstString name; std::string description; - ABICreateInstance create_callback; + Callback create_callback; + DebuggerInitializeCallback debugger_init_callback; }; +#pragma mark ABI + +typedef PluginInstance ABIInstance; + typedef std::vector ABIInstances; static std::recursive_mutex &GetABIInstancesMutex() { @@ -219,8 +228,7 @@ static ABIInstances &GetABIInstances() { return g_instances; } -bool PluginManager::RegisterPlugin(ConstString name, - const char *description, +bool PluginManager::RegisterPlugin(ConstString name, const char *description, ABICreateInstance create_callback) { if (create_callback) { ABIInstance instance; @@ -277,17 +285,13 @@ PluginManager::GetABICreateCallbackForPluginName(ConstString name) { #pragma mark Architecture -struct ArchitectureInstance { - ConstString name; - std::string description; - PluginManager::ArchitectureCreateInstance create_callback; -}; - +typedef PluginInstance + ArchitectureInstance; typedef std::vector ArchitectureInstances; static std::mutex &GetArchitectureMutex() { - static std::mutex g_architecture_mutex; - return g_architecture_mutex; + static std::mutex g_architecture_mutex; + return g_architecture_mutex; } static ArchitectureInstances &GetArchitectureInstances() { @@ -329,13 +333,7 @@ PluginManager::CreateArchitectureInstance(const ArchSpec &arch) { #pragma mark Disassembler -struct DisassemblerInstance { - DisassemblerInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - DisassemblerCreateInstance create_callback; -}; +typedef PluginInstance DisassemblerInstance; typedef std::vector DisassemblerInstances; @@ -349,8 +347,7 @@ static DisassemblerInstances &GetDisassemblerInstances() { return g_instances; } -bool PluginManager::RegisterPlugin(ConstString name, - const char *description, +bool PluginManager::RegisterPlugin(ConstString name, const char *description, DisassemblerCreateInstance create_callback) { if (create_callback) { DisassemblerInstance instance; @@ -393,8 +390,7 @@ PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) { } DisassemblerCreateInstance -PluginManager::GetDisassemblerCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetDisassemblerCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetDisassemblerMutex()); DisassemblerInstances &instances = GetDisassemblerInstances(); @@ -410,16 +406,7 @@ PluginManager::GetDisassemblerCreateCallbackForPluginName( #pragma mark DynamicLoader -struct DynamicLoaderInstance { - DynamicLoaderInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - DynamicLoaderCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; +typedef PluginInstance DynamicLoaderInstance; typedef std::vector DynamicLoaderInstances; @@ -478,8 +465,7 @@ PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) { } DynamicLoaderCreateInstance -PluginManager::GetDynamicLoaderCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetDynamicLoaderCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetDynamicLoaderMutex()); DynamicLoaderInstances &instances = GetDynamicLoaderInstances(); @@ -495,17 +481,7 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName( #pragma mark JITLoader -struct JITLoaderInstance { - JITLoaderInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - JITLoaderCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; - +typedef PluginInstance JITLoaderInstance; typedef std::vector JITLoaderInstances; static std::recursive_mutex &GetJITLoaderMutex() { @@ -561,8 +537,8 @@ PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) { return nullptr; } -JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackForPluginName( - ConstString name) { +JITLoaderCreateInstance +PluginManager::GetJITLoaderCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetJITLoaderMutex()); JITLoaderInstances &instances = GetJITLoaderInstances(); @@ -578,15 +554,8 @@ JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackForPluginName( #pragma mark EmulateInstruction -struct EmulateInstructionInstance { - EmulateInstructionInstance() - : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - EmulateInstructionCreateInstance create_callback; -}; - +typedef PluginInstance + EmulateInstructionInstance; typedef std::vector EmulateInstructionInstances; static std::recursive_mutex &GetEmulateInstructionMutex() { @@ -659,17 +628,7 @@ PluginManager::GetEmulateInstructionCreateCallbackForPluginName( #pragma mark OperatingSystem -struct OperatingSystemInstance { - OperatingSystemInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - OperatingSystemCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; - +typedef PluginInstance OperatingSystemInstance; typedef std::vector OperatingSystemInstances; static std::recursive_mutex &GetOperatingSystemMutex() { @@ -727,8 +686,7 @@ PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) { } OperatingSystemCreateInstance -PluginManager::GetOperatingSystemCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetOperatingSystemCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetOperatingSystemMutex()); OperatingSystemInstances &instances = GetOperatingSystemInstances(); @@ -744,14 +702,7 @@ PluginManager::GetOperatingSystemCreateCallbackForPluginName( #pragma mark Language -struct LanguageInstance { - LanguageInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - LanguageCreateInstance create_callback; -}; - +typedef PluginInstance LanguageInstance; typedef std::vector LanguageInstances; static std::recursive_mutex &GetLanguageMutex() { @@ -764,8 +715,7 @@ static LanguageInstances &GetLanguageInstances() { return g_instances; } -bool PluginManager::RegisterPlugin(ConstString name, - const char *description, +bool PluginManager::RegisterPlugin(ConstString name, const char *description, LanguageCreateInstance create_callback) { if (create_callback) { LanguageInstance instance; @@ -822,12 +772,8 @@ PluginManager::GetLanguageCreateCallbackForPluginName(ConstString name) { #pragma mark LanguageRuntime -struct LanguageRuntimeInstance { - LanguageRuntimeInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - LanguageRuntimeCreateInstance create_callback; +struct LanguageRuntimeInstance + : public PluginInstance { LanguageRuntimeGetCommandObject command_callback; LanguageRuntimeGetExceptionPrecondition precondition_callback; }; @@ -909,8 +855,7 @@ PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) { } LanguageRuntimeCreateInstance -PluginManager::GetLanguageRuntimeCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetLanguageRuntimeCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetLanguageRuntimeMutex()); LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances(); @@ -926,14 +871,7 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName( #pragma mark SystemRuntime -struct SystemRuntimeInstance { - SystemRuntimeInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - SystemRuntimeCreateInstance create_callback; -}; - +typedef PluginInstance SystemRuntimeInstance; typedef std::vector SystemRuntimeInstances; static std::recursive_mutex &GetSystemRuntimeMutex() { @@ -989,8 +927,7 @@ PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) { } SystemRuntimeCreateInstance -PluginManager::GetSystemRuntimeCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetSystemRuntimeCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetSystemRuntimeMutex()); SystemRuntimeInstances &instances = GetSystemRuntimeInstances(); @@ -1006,15 +943,7 @@ PluginManager::GetSystemRuntimeCreateCallbackForPluginName( #pragma mark ObjectFile -struct ObjectFileInstance { - ObjectFileInstance() - : name(), description(), create_callback(nullptr), - create_memory_callback(nullptr), get_module_specifications(nullptr), - save_core(nullptr) {} - - ConstString name; - std::string description; - ObjectFileCreateInstance create_callback; +struct ObjectFileInstance : public PluginInstance { ObjectFileCreateMemoryInstance create_memory_callback; ObjectFileGetModuleSpecifications get_module_specifications; ObjectFileSaveCore save_core; @@ -1099,8 +1028,7 @@ PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex( } ObjectFileCreateInstance -PluginManager::GetObjectFileCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetObjectFileCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances(); @@ -1148,14 +1076,7 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp, #pragma mark ObjectContainer -struct ObjectContainerInstance { - ObjectContainerInstance() - : name(), description(), create_callback(nullptr), - get_module_specifications(nullptr) {} - - ConstString name; - std::string description; - ObjectContainerCreateInstance create_callback; +struct ObjectContainerInstance : PluginInstance { ObjectFileGetModuleSpecifications get_module_specifications; }; @@ -1216,8 +1137,7 @@ PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) { } ObjectContainerCreateInstance -PluginManager::GetObjectContainerCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetObjectContainerCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetObjectContainerMutex()); ObjectContainerInstances &instances = GetObjectContainerInstances(); @@ -1243,17 +1163,7 @@ PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex( #pragma mark Platform -struct PlatformInstance { - PlatformInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - PlatformCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; - +typedef PluginInstance PlatformInstance; typedef std::vector PlatformInstances; static std::recursive_mutex &GetPlatformInstancesMutex() { @@ -1361,17 +1271,7 @@ void PluginManager::AutoCompletePlatformName(llvm::StringRef name, #pragma mark Process -struct ProcessInstance { - ProcessInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - ProcessCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; - +typedef PluginInstance ProcessInstance; typedef std::vector ProcessInstances; static std::recursive_mutex &GetProcessMutex() { @@ -1460,15 +1360,9 @@ PluginManager::GetProcessCreateCallbackForPluginName(ConstString name) { #pragma mark ScriptInterpreter -struct ScriptInterpreterInstance { - ScriptInterpreterInstance() - : name(), language(lldb::eScriptLanguageNone), description(), - create_callback(nullptr) {} - - ConstString name; - lldb::ScriptLanguage language; - std::string description; - ScriptInterpreterCreateInstance create_callback; +struct ScriptInterpreterInstance + : public PluginInstance { + lldb::ScriptLanguage language = lldb::eScriptLanguageNone; }; typedef std::vector ScriptInterpreterInstances; @@ -1552,18 +1446,9 @@ PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, #pragma mark - #pragma mark StructuredDataPlugin -// StructuredDataPlugin - -struct StructuredDataPluginInstance { - StructuredDataPluginInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr), filter_callback(nullptr) {} - - ConstString name; - std::string description; - StructuredDataPluginCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; - StructuredDataFilterLaunchInfo filter_callback; +struct StructuredDataPluginInstance + : public PluginInstance { + StructuredDataFilterLaunchInfo filter_callback = nullptr; }; typedef std::vector StructuredDataPluginInstances; @@ -1658,17 +1543,7 @@ PluginManager::GetStructuredDataFilterCallbackAtIndex( #pragma mark SymbolFile -struct SymbolFileInstance { - SymbolFileInstance() - : name(), description(), create_callback(nullptr), - debugger_init_callback(nullptr) {} - - ConstString name; - std::string description; - SymbolFileCreateInstance create_callback; - DebuggerInitializeCallback debugger_init_callback; -}; - +typedef PluginInstance SymbolFileInstance; typedef std::vector SymbolFileInstances; static std::recursive_mutex &GetSymbolFileMutex() { @@ -1725,8 +1600,7 @@ PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) { } SymbolFileCreateInstance -PluginManager::GetSymbolFileCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetSymbolFileCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetSymbolFileMutex()); SymbolFileInstances &instances = GetSymbolFileInstances(); @@ -1742,14 +1616,7 @@ PluginManager::GetSymbolFileCreateCallbackForPluginName( #pragma mark SymbolVendor -struct SymbolVendorInstance { - SymbolVendorInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - SymbolVendorCreateInstance create_callback; -}; - +typedef PluginInstance SymbolVendorInstance; typedef std::vector SymbolVendorInstances; static std::recursive_mutex &GetSymbolVendorMutex() { @@ -1762,8 +1629,7 @@ static SymbolVendorInstances &GetSymbolVendorInstances() { return g_instances; } -bool PluginManager::RegisterPlugin(ConstString name, - const char *description, +bool PluginManager::RegisterPlugin(ConstString name, const char *description, SymbolVendorCreateInstance create_callback) { if (create_callback) { SymbolVendorInstance instance; @@ -1804,32 +1670,9 @@ PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) { return nullptr; } -SymbolVendorCreateInstance -PluginManager::GetSymbolVendorCreateCallbackForPluginName( - ConstString name) { - if (name) { - std::lock_guard guard(GetSymbolVendorMutex()); - SymbolVendorInstances &instances = GetSymbolVendorInstances(); - - SymbolVendorInstances::iterator pos, end = instances.end(); - for (pos = instances.begin(); pos != end; ++pos) { - if (name == pos->name) - return pos->create_callback; - } - } - return nullptr; -} - #pragma mark UnwindAssembly -struct UnwindAssemblyInstance { - UnwindAssemblyInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - UnwindAssemblyCreateInstance create_callback; -}; - +typedef PluginInstance UnwindAssemblyInstance; typedef std::vector UnwindAssemblyInstances; static std::recursive_mutex &GetUnwindAssemblyMutex() { @@ -1885,8 +1728,7 @@ PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) { } UnwindAssemblyCreateInstance -PluginManager::GetUnwindAssemblyCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetUnwindAssemblyCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetUnwindAssemblyMutex()); UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances(); @@ -1902,14 +1744,7 @@ PluginManager::GetUnwindAssemblyCreateCallbackForPluginName( #pragma mark MemoryHistory -struct MemoryHistoryInstance { - MemoryHistoryInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - MemoryHistoryCreateInstance create_callback; -}; - +typedef PluginInstance MemoryHistoryInstance; typedef std::vector MemoryHistoryInstances; static std::recursive_mutex &GetMemoryHistoryMutex() { @@ -1965,8 +1800,7 @@ PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) { } MemoryHistoryCreateInstance -PluginManager::GetMemoryHistoryCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetMemoryHistoryCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetMemoryHistoryMutex()); MemoryHistoryInstances &instances = GetMemoryHistoryInstances(); @@ -1982,14 +1816,9 @@ PluginManager::GetMemoryHistoryCreateCallbackForPluginName( #pragma mark InstrumentationRuntime -struct InstrumentationRuntimeInstance { - InstrumentationRuntimeInstance() - : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - InstrumentationRuntimeCreateInstance create_callback; - InstrumentationRuntimeGetType get_type_callback; +struct InstrumentationRuntimeInstance + : public PluginInstance { + InstrumentationRuntimeGetType get_type_callback = nullptr; }; typedef std::vector @@ -2083,10 +1912,7 @@ PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName( #pragma mark TypeSystem -struct TypeSystemInstance { - ConstString name; - std::string description; - TypeSystemCreateInstance create_callback; +struct TypeSystemInstance : public PluginInstance { LanguageSet supported_languages_for_types; LanguageSet supported_languages_for_expressions; }; @@ -2116,7 +1942,8 @@ bool PluginManager::RegisterPlugin( instance.description = description; instance.create_callback = create_callback; instance.supported_languages_for_types = supported_languages_for_types; - instance.supported_languages_for_expressions = supported_languages_for_expressions; + instance.supported_languages_for_expressions = + supported_languages_for_expressions; std::lock_guard guard(GetTypeSystemMutex()); GetTypeSystemInstances().push_back(instance); } @@ -2149,8 +1976,7 @@ PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) { } TypeSystemCreateInstance -PluginManager::GetTypeSystemCreateCallbackForPluginName( - ConstString name) { +PluginManager::GetTypeSystemCreateCallbackForPluginName(ConstString name) { if (name) { std::lock_guard guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances(); @@ -2184,12 +2010,7 @@ LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() { #pragma mark REPL -struct REPLInstance { - REPLInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - REPLCreateInstance create_callback; +struct REPLInstance : public PluginInstance { LanguageSet supported_languages; }; @@ -2352,9 +2173,9 @@ void PluginManager::DebuggerInitialize(Debugger &debugger) { // This is the preferred new way to register plugin specific settings. e.g. // This will put a plugin's settings under e.g. // "plugin...SETTINGNAME". -static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins( - Debugger &debugger, ConstString plugin_type_name, - ConstString plugin_type_desc, bool can_create) { +static lldb::OptionValuePropertiesSP +GetDebuggerPropertyForPlugins(Debugger &debugger, ConstString plugin_type_name, + ConstString plugin_type_desc, bool can_create) { lldb::OptionValuePropertiesSP parent_properties_sp( debugger.GetValueProperties()); if (parent_properties_sp) { @@ -2423,8 +2244,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle( namespace { typedef lldb::OptionValuePropertiesSP -GetDebuggerPropertyForPluginsPtr(Debugger &, ConstString , - ConstString , bool can_create); +GetDebuggerPropertyForPluginsPtr(Debugger &, ConstString, ConstString, + bool can_create); lldb::OptionValuePropertiesSP GetSettingForPlugin(Debugger &debugger, ConstString setting_name, @@ -2445,8 +2266,8 @@ GetSettingForPlugin(Debugger &debugger, ConstString setting_name, bool CreateSettingForPlugin( Debugger &debugger, ConstString plugin_type_name, ConstString plugin_type_desc, - const lldb::OptionValuePropertiesSP &properties_sp, - ConstString description, bool is_global_property, + const lldb::OptionValuePropertiesSP &properties_sp, ConstString description, + bool is_global_property, GetDebuggerPropertyForPluginsPtr get_debugger_property = GetDebuggerPropertyForPlugins) { if (properties_sp) { @@ -2472,8 +2293,9 @@ const char *kStructuredDataPluginName("structured-data"); } // anonymous namespace -lldb::OptionValuePropertiesSP PluginManager::GetSettingForDynamicLoaderPlugin( - Debugger &debugger, ConstString setting_name) { +lldb::OptionValuePropertiesSP +PluginManager::GetSettingForDynamicLoaderPlugin(Debugger &debugger, + ConstString setting_name) { return GetSettingForPlugin(debugger, setting_name, ConstString(kDynamicLoaderPluginName)); } @@ -2552,8 +2374,9 @@ bool PluginManager::CreateSettingForJITLoaderPlugin( static const char *kOperatingSystemPluginName("os"); -lldb::OptionValuePropertiesSP PluginManager::GetSettingForOperatingSystemPlugin( - Debugger &debugger, ConstString setting_name) { +lldb::OptionValuePropertiesSP +PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger, + ConstString setting_name) { lldb::OptionValuePropertiesSP properties_sp; lldb::OptionValuePropertiesSP plugin_type_properties_sp( GetDebuggerPropertyForPlugins( @@ -2584,8 +2407,9 @@ bool PluginManager::CreateSettingForOperatingSystemPlugin( return false; } -lldb::OptionValuePropertiesSP PluginManager::GetSettingForStructuredDataPlugin( - Debugger &debugger, ConstString setting_name) { +lldb::OptionValuePropertiesSP +PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger, + ConstString setting_name) { return GetSettingForPlugin(debugger, setting_name, ConstString(kStructuredDataPluginName)); }