diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index a99f95f0e207c..1cefa8cfb589a 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -1220,7 +1220,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation, getFrameworkSearchPaths(), framework_search_paths, .Path); - std::vector plugin_search_options; + std::vector plugin_search_options; llvm::StringSet<> known_plugin_search_paths; llvm::StringSet<> known_external_plugin_search_paths; llvm::StringSet<> known_compiler_plugin_library_paths; @@ -1311,87 +1311,93 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation, return false; }; - // Discover, rewrite, and unique compiler plugin paths. - for (auto path : extended_validation_info.getPluginSearchPaths()) { - // System plugins shipping with the compiler. - // Rewrite them to go through an ABI-compatible swift-plugin-server. - if (known_plugin_search_paths.insert(path).second) { - if (known_external_plugin_search_paths.insert(path).second) { - std::string server = get_plugin_server( - path, [&]() { return GetPluginServer(path); }); - if (server.empty()) - continue; - if (exists(path)) - plugin_search_options.emplace_back( - swift::PluginSearchOption::ExternalPluginPath{path.str(), - server}); + for (auto &opt : extended_validation_info.getPluginSearchOptions()) { + switch (opt.first) { + case swift::PluginSearchOption::Kind::PluginPath: { + StringRef path = opt.second; + // System plugins shipping with the compiler. + // Rewrite them to go through an ABI-compatible swift-plugin-server. + if (known_plugin_search_paths.insert(path).second) { + if (known_external_plugin_search_paths.insert(path).second) { + std::string server = get_plugin_server( + path, [&]() { return GetPluginServer(path); }); + if (server.empty()) + continue; + if (exists(path)) + plugin_search_options.emplace_back( + swift::PluginSearchOption::ExternalPluginPath{path.str(), + server}); + } } + continue; } - } - for (auto path : - extended_validation_info.getExternalPluginSearchPaths()) { - // Sandboxed system plugins shipping with some compiler. - // Keep the original plugin server path, it needs to be ABI - // compatible with the version of SwiftSyntax used by the plugin. - auto plugin_server = path.split('#'); - llvm::StringRef plugin = plugin_server.first; - std::string server = get_plugin_server( - plugin, [&]() { return plugin_server.second.str(); }); - if (server.empty()) + case swift::PluginSearchOption::Kind::ExternalPluginPath: { + // Sandboxed system plugins shipping with some compiler. + // Keep the original plugin server path, it needs to be ABI + // compatible with the version of SwiftSyntax used by the plugin. + auto plugin_server = opt.second.split('#'); + llvm::StringRef plugin = plugin_server.first; + std::string server = get_plugin_server( + plugin, [&]() { return plugin_server.second.str(); }); + if (server.empty()) + continue; + if (known_external_plugin_search_paths.insert(plugin).second) + if (exists(plugin)) + plugin_search_options.emplace_back( + swift::PluginSearchOption::ExternalPluginPath{plugin.str(), + server}); continue; - if (known_external_plugin_search_paths.insert(plugin).second) - if (exists(plugin)) - plugin_search_options.emplace_back( - swift::PluginSearchOption::ExternalPluginPath{plugin.str(), - server}); - } + } + case swift::PluginSearchOption::Kind::LoadPluginLibrary: { + // Compiler plugin libraries. + StringRef dylib = opt.second; + if (known_compiler_plugin_library_paths.insert(dylib).second) + if (exists(dylib)) { + // We never want to directly load any plugins, since a crash in + // the plugin would bring down LLDB. Here, we assume that the + // correct plugin server for a direct compiler plugin is the one + // from the SDK the compiler was building for. This is just a + // heuristic. + // This works because the Swift compiler enforces + // '-load-plugin-library' dylibs to be named + // libModuleName.[dylib|so|dll] just like + // '-external-plugin-path'. + llvm::SmallString<0> dir(dylib); + llvm::sys::path::remove_filename(dir); + std::string server = get_plugin_server(dir, [&]() { + return GetPluginServerForSDK(invocation.getSDKPath()); + }); + if (server.empty()) + continue; - for (auto dylib : - extended_validation_info.getCompilerPluginLibraryPaths()) { - // Compiler plugin libraries. - if (known_compiler_plugin_library_paths.insert(dylib).second) - if (exists(dylib)) { - // We never want to directly load any plugins, since a crash in - // the plugin would bring down LLDB. Here, we assume that the - // correct plugin server for a direct compiler plugin is the one - // from the SDK the compiler was building for. This is just a - // heuristic. - llvm::SmallString<0> dir(dylib); - llvm::sys::path::remove_filename(dir); - std::string server = get_plugin_server(dir, [&]() { - return GetPluginServerForSDK(invocation.getSDKPath()); - }); - if (server.empty()) - continue; - - // FIXME: The Swift compiler expects external plugins - // to be named libModuleName.[dylib|so|dll]. This - // means this our translation attempts only work for - // macro libraries following this convention. cf. - // PluginLoader::lookupExternalLibraryPluginByModuleName(). - plugin_search_options.emplace_back( - swift::PluginSearchOption::ExternalPluginPath{dir.str().str(), - server}); - } + plugin_search_options.emplace_back( + swift::PluginSearchOption::ExternalPluginPath{ + dir.str().str(), server}); + } + continue; + } + case swift::PluginSearchOption::Kind::LoadPluginExecutable: { + // Compiler plugin executables. + auto plugin_modules = opt.second.split('#'); + llvm::StringRef plugin = plugin_modules.first; + llvm::StringRef modules_list = plugin_modules.second; + llvm::SmallVector modules; + modules_list.split(modules, ","); + std::vector modules_vec; + for (auto m : modules) + modules_vec.push_back(m.str()); + if (known_compiler_plugin_executable_paths.insert(opt.second) + .second) + if (exists(plugin)) + plugin_search_options.emplace_back( + swift::PluginSearchOption::LoadPluginExecutable{ + plugin.str(), modules_vec}); + continue; + } + } + llvm_unreachable("unhandled plugin search option kind"); } - for (auto path : - extended_validation_info.getCompilerPluginExecutablePaths()) { - // Compiler plugin executables. - auto plugin_modules = path.split('#'); - llvm::StringRef plugin = plugin_modules.first; - llvm::StringRef modules_list = plugin_modules.second; - llvm::SmallVector modules; - modules_list.split(modules, ","); - std::vector modules_vec; - for (auto m : modules) - modules_vec.push_back(m.str()); - if (known_compiler_plugin_executable_paths.insert(path).second) - if (exists(plugin)) - plugin_search_options.emplace_back( - swift::PluginSearchOption::LoadPluginExecutable{plugin.str(), - modules_vec}); - } return true; }; @@ -2018,7 +2024,7 @@ static void ProcessModule( ModuleSP module_sp, std::string m_description, bool discover_implicit_search_paths, bool use_all_compiler_flags, Target &target, llvm::Triple triple, - std::vector &plugin_search_options, + std::vector &plugin_search_options, std::vector &module_search_paths, std::vector> &framework_search_paths, std::vector &extra_clang_args) { @@ -2164,7 +2170,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance( LLDB_SCOPED_TIMER(); std::string m_description = "SwiftASTContextForExpressions"; - std::vector plugin_search_options; + std::vector plugin_search_options; std::vector module_search_paths; std::vector> framework_search_paths; TargetSP target_sp = typeref_typesystem.GetTargetWP().lock(); @@ -4629,7 +4635,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) { bool use_all_compiler_flags = target_sp->GetUseAllCompilerFlags(); unsigned num_images = module_list.GetSize(); for (size_t mi = 0; mi != num_images; ++mi) { - std::vector plugin_search_options; + std::vector plugin_search_options; std::vector module_search_paths; std::vector> framework_search_paths; std::vector extra_clang_args;