diff options
Diffstat (limited to 'source/Core/PluginManager.cpp')
-rw-r--r-- | source/Core/PluginManager.cpp | 151 |
1 files changed, 38 insertions, 113 deletions
diff --git a/source/Core/PluginManager.cpp b/source/Core/PluginManager.cpp index b7b6b9a54efe..bd4ba5995204 100644 --- a/source/Core/PluginManager.cpp +++ b/source/Core/PluginManager.cpp @@ -9,24 +9,35 @@ #include "lldb/Core/PluginManager.h" -// C Includes -// C++ Includes -#include <climits> +#include "lldb/Core/Debugger.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Interpreter/OptionValueProperties.h" +#include "lldb/Utility/ConstString.h" // for ConstString +#include "lldb/Utility/Error.h" +#include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/StringList.h" // for StringList + +#if defined(LLVM_ON_WIN32) +#include "lldb/Host/windows/PosixApi.h" // for PATH_MAX +#endif + +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FileSystem.h" // for file_type, file_... +#include "llvm/Support/raw_ostream.h" // for fs + +#include <map> // for map<>::const_ite... +#include <memory> // for shared_ptr #include <mutex> #include <string> +#include <utility> // for pair #include <vector> -// Other libraries and framework includes -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/DynamicLibrary.h" +#include <assert.h> // for assert -// Project includes -#include "lldb/Core/Debugger.h" -#include "lldb/Core/Error.h" -#include "lldb/Host/FileSpec.h" -#include "lldb/Host/Host.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Interpreter/OptionValueProperties.h" +namespace lldb_private { +class CommandInterpreter; +} using namespace lldb; using namespace lldb_private; @@ -79,18 +90,18 @@ template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) { } static FileSpec::EnumerateDirectoryResult -LoadPluginCallback(void *baton, FileSpec::FileType file_type, +LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { // PluginManager *plugin_manager = (PluginManager *)baton; Error error; + namespace fs = llvm::sys::fs; // If we have a regular file, a symbolic link or unknown file type, try // and process the file. We must handle unknown as sometimes the directory // enumeration might be enumerating a file system that doesn't have correct // file type information. - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink || - file_type == FileSpec::eFileTypeUnknown) { + if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { FileSpec plugin_file_spec(file_spec); plugin_file_spec.ResolvePath(); @@ -135,9 +146,8 @@ LoadPluginCallback(void *baton, FileSpec::FileType file_type, } } - if (file_type == FileSpec::eFileTypeUnknown || - file_type == FileSpec::eFileTypeDirectory || - file_type == FileSpec::eFileTypeSymbolicLink) { + if (ft == fs::file_type::directory_file || + ft == fs::file_type::symlink_file || ft == fs::file_type::type_unknown) { // Try and recurse into anything that a directory or symbolic link. // We must also do this for unknown as sometimes the directory enumeration // might be enumerating a file system that doesn't have correct file type @@ -1167,93 +1177,6 @@ PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex( return nullptr; } -#pragma mark LogChannel - -struct LogInstance { - LogInstance() : name(), description(), create_callback(nullptr) {} - - ConstString name; - std::string description; - LogChannelCreateInstance create_callback; -}; - -typedef std::vector<LogInstance> LogInstances; - -static std::recursive_mutex &GetLogMutex() { - static std::recursive_mutex g_instances_mutex; - return g_instances_mutex; -} - -static LogInstances &GetLogInstances() { - static LogInstances g_instances; - return g_instances; -} - -bool PluginManager::RegisterPlugin(const ConstString &name, - const char *description, - LogChannelCreateInstance create_callback) { - if (create_callback) { - LogInstance instance; - assert((bool)name); - instance.name = name; - if (description && description[0]) - instance.description = description; - instance.create_callback = create_callback; - std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); - GetLogInstances().push_back(instance); - } - return false; -} - -bool PluginManager::UnregisterPlugin(LogChannelCreateInstance create_callback) { - if (create_callback) { - std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); - LogInstances &instances = GetLogInstances(); - - LogInstances::iterator pos, end = instances.end(); - for (pos = instances.begin(); pos != end; ++pos) { - if (pos->create_callback == create_callback) { - instances.erase(pos); - return true; - } - } - } - return false; -} - -const char *PluginManager::GetLogChannelCreateNameAtIndex(uint32_t idx) { - std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); - LogInstances &instances = GetLogInstances(); - if (idx < instances.size()) - return instances[idx].name.GetCString(); - return nullptr; -} - -LogChannelCreateInstance -PluginManager::GetLogChannelCreateCallbackAtIndex(uint32_t idx) { - std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); - LogInstances &instances = GetLogInstances(); - if (idx < instances.size()) - return instances[idx].create_callback; - return nullptr; -} - -LogChannelCreateInstance -PluginManager::GetLogChannelCreateCallbackForPluginName( - const ConstString &name) { - if (name) { - std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); - LogInstances &instances = GetLogInstances(); - - LogInstances::iterator pos, end = instances.end(); - for (pos = instances.begin(); pos != end; ++pos) { - if (name == pos->name) - return pos->create_callback; - } - } - return nullptr; -} - #pragma mark Platform struct PlatformInstance { @@ -2403,7 +2326,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins( OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, g_property_name); if (!plugin_properties_sp && can_create) { - plugin_properties_sp.reset(new OptionValueProperties(g_property_name)); + plugin_properties_sp = + std::make_shared<OptionValueProperties>(g_property_name); parent_properties_sp->AppendProperty( g_property_name, ConstString("Settings specify to plugins."), true, plugin_properties_sp); @@ -2413,8 +2337,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins( lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name); if (!plugin_type_properties_sp && can_create) { - plugin_type_properties_sp.reset( - new OptionValueProperties(plugin_type_name)); + plugin_type_properties_sp = + std::make_shared<OptionValueProperties>(plugin_type_name); plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc, true, plugin_type_properties_sp); } @@ -2437,7 +2361,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle( OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, plugin_type_name); if (!plugin_properties_sp && can_create) { - plugin_properties_sp.reset(new OptionValueProperties(plugin_type_name)); + plugin_properties_sp = + std::make_shared<OptionValueProperties>(plugin_type_name); parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc, true, plugin_properties_sp); } @@ -2446,8 +2371,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle( lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, g_property_name); if (!plugin_type_properties_sp && can_create) { - plugin_type_properties_sp.reset( - new OptionValueProperties(g_property_name)); + plugin_type_properties_sp = + std::make_shared<OptionValueProperties>(g_property_name); plugin_properties_sp->AppendProperty( g_property_name, ConstString("Settings specific to plugins"), true, plugin_type_properties_sp); |