@@ -1836,11 +1836,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1836
1836
// Add Swift interfaces in the .dSYM at the end of the search paths.
1837
1837
// .swiftmodules win over .swiftinterfaces, when they are loaded
1838
1838
// directly from the .swift_ast section.
1839
- //
1840
- // FIXME: Since these paths also end up in the scratch context, we
1841
- // would need a mechanism to ensure that and newer versions
1842
- // (in the library evolution sense, not the date on disk) win
1843
- // over older versions of the same .swiftinterface.
1844
1839
if (auto dsym = GetDSYMBundle (module )) {
1845
1840
llvm::SmallString<256 > path (*dsym);
1846
1841
llvm::Triple triple (swift_ast_sp->GetTriple ());
@@ -1949,7 +1944,7 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1949
1944
return ModuleSP ();
1950
1945
}
1951
1946
1952
- // / Scan a newly added lldb::Module fdor Swift modules and report any errors in
1947
+ // / Scan a newly added lldb::Module for Swift modules and report any errors in
1953
1948
// / its module SwiftASTContext to Target.
1954
1949
static void
1955
1950
ProcessModule (ModuleSP module_sp, std::string m_description,
@@ -2068,20 +2063,60 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
2068
2063
2069
2064
if (ast_context->HasErrors ())
2070
2065
return ;
2071
- if (use_all_compiler_flags ||
2072
- target.GetExecutableModulePointer () == module_sp.get ()) {
2073
-
2074
- const auto &opts = ast_context->GetSearchPathOptions ();
2075
- module_search_paths.insert (module_search_paths.end (),
2076
- opts.ImportSearchPaths .begin (),
2077
- opts.ImportSearchPaths .end ());
2078
- for (const auto &fwsp : opts.FrameworkSearchPaths )
2079
- framework_search_paths.push_back ({fwsp.Path , fwsp.IsSystem });
2080
- for (const std::string &arg : ast_context->GetClangArguments ()) {
2081
- extra_clang_args.push_back (arg);
2082
- LOG_VERBOSE_PRINTF (LIBLLDB_LOG_TYPES, " adding Clang argument \" %s\" ." ,
2083
- arg.c_str ());
2084
- }
2066
+
2067
+ // Load search path options from the module.
2068
+ if (!use_all_compiler_flags &&
2069
+ target.GetExecutableModulePointer () != module_sp.get ())
2070
+ return ;
2071
+
2072
+ // Add Swift interfaces in the .dSYM at the end of the search paths.
2073
+ // .swiftmodules win over .swiftinterfaces, when they are loaded
2074
+ // directly from the .swift_ast section.
2075
+ //
2076
+ // FIXME: Since these paths end up in the scratch context, we would
2077
+ // need a mechanism to ensure that and newer versions (in the
2078
+ // library evolution sense, not the date on disk) win over
2079
+ // older versions of the same .swiftinterface.
2080
+ if (auto dsym = GetDSYMBundle (*module_sp)) {
2081
+ llvm::SmallString<256 > path (*dsym);
2082
+ llvm::Triple triple (ast_context->GetTriple ());
2083
+ StringRef arch = llvm::Triple::getArchTypeName (triple.getArch ());
2084
+ llvm::sys::path::append (path, " Contents" , " Resources" , " Swift" , arch);
2085
+ bool exists = false ;
2086
+ llvm::sys::fs::is_directory (path, exists);
2087
+ if (exists)
2088
+ module_search_paths.push_back (std::string (path));
2089
+ }
2090
+
2091
+ // Create a one-off CompilerInvocation as a place to load the
2092
+ // deserialized search path options into.
2093
+ SymbolFile *sym_file = module_sp->GetSymbolFile ();
2094
+ if (!sym_file)
2095
+ return ;
2096
+ bool found_swift_modules = false ;
2097
+ bool got_serialized_options = false ;
2098
+ llvm::SmallString<0 > error;
2099
+ llvm::raw_svector_ostream errs (error);
2100
+ swift::CompilerInvocation invocation;
2101
+ if (DeserializeAllCompilerFlags (invocation, *module_sp, m_description, errs,
2102
+ got_serialized_options,
2103
+ found_swift_modules)) {
2104
+ // TODO: After removing DeserializeAllCompilerFlags from
2105
+ // CreateInstance(per-Module), errs will need to be
2106
+ // collected here and surfaced.
2107
+ }
2108
+
2109
+ const auto &opts = invocation.getSearchPathOptions ();
2110
+ module_search_paths.insert (module_search_paths.end (),
2111
+ opts.ImportSearchPaths .begin (),
2112
+ opts.ImportSearchPaths .end ());
2113
+ for (const auto &fwsp : opts.FrameworkSearchPaths )
2114
+ framework_search_paths.push_back ({fwsp.Path , fwsp.IsSystem });
2115
+ auto &clang_opts = invocation.getClangImporterOptions ().ExtraArgs ;
2116
+ for (const std::string &arg : clang_opts) {
2117
+ extra_clang_args.push_back (arg);
2118
+ LOG_VERBOSE_PRINTF (LIBLLDB_LOG_TYPES, " adding Clang argument \" %s\" ." ,
2119
+ arg.c_str ());
2085
2120
}
2086
2121
}
2087
2122
0 commit comments