@@ -1814,11 +1814,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1814
1814
// Add Swift interfaces in the .dSYM at the end of the search paths.
1815
1815
// .swiftmodules win over .swiftinterfaces, when they are loaded
1816
1816
// directly from the .swift_ast section.
1817
- //
1818
- // FIXME: Since these paths also end up in the scratch context, we
1819
- // would need a mechanism to ensure that and newer versions
1820
- // (in the library evolution sense, not the date on disk) win
1821
- // over older versions of the same .swiftinterface.
1822
1817
if (auto dsym = GetDSYMBundle (module )) {
1823
1818
llvm::SmallString<256 > path (*dsym);
1824
1819
llvm::Triple triple (swift_ast_sp->GetTriple ());
@@ -1927,7 +1922,7 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1927
1922
return ModuleSP ();
1928
1923
}
1929
1924
1930
- // / Scan a newly added lldb::Module fdor Swift modules and report any errors in
1925
+ // / Scan a newly added lldb::Module for Swift modules and report any errors in
1931
1926
// / its module SwiftASTContext to Target.
1932
1927
static void
1933
1928
ProcessModule (ModuleSP module_sp, std::string m_description,
@@ -2046,20 +2041,60 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
2046
2041
2047
2042
if (ast_context->HasErrors ())
2048
2043
return ;
2049
- if (use_all_compiler_flags ||
2050
- target.GetExecutableModulePointer () == module_sp.get ()) {
2051
-
2052
- const auto &opts = ast_context->GetSearchPathOptions ();
2053
- module_search_paths.insert (module_search_paths.end (),
2054
- opts.ImportSearchPaths .begin (),
2055
- opts.ImportSearchPaths .end ());
2056
- for (const auto &fwsp : opts.FrameworkSearchPaths )
2057
- framework_search_paths.push_back ({fwsp.Path , fwsp.IsSystem });
2058
- for (const std::string &arg : ast_context->GetClangArguments ()) {
2059
- extra_clang_args.push_back (arg);
2060
- LOG_VERBOSE_PRINTF (LIBLLDB_LOG_TYPES, " adding Clang argument \" %s\" ." ,
2061
- arg.c_str ());
2062
- }
2044
+
2045
+ // Load search path options from the module.
2046
+ if (!use_all_compiler_flags &&
2047
+ target.GetExecutableModulePointer () != module_sp.get ())
2048
+ return ;
2049
+
2050
+ // Add Swift interfaces in the .dSYM at the end of the search paths.
2051
+ // .swiftmodules win over .swiftinterfaces, when they are loaded
2052
+ // directly from the .swift_ast section.
2053
+ //
2054
+ // FIXME: Since these paths end up in the scratch context, we would
2055
+ // need a mechanism to ensure that and newer versions (in the
2056
+ // library evolution sense, not the date on disk) win over
2057
+ // older versions of the same .swiftinterface.
2058
+ if (auto dsym = GetDSYMBundle (*module_sp)) {
2059
+ llvm::SmallString<256 > path (*dsym);
2060
+ llvm::Triple triple (ast_context->GetTriple ());
2061
+ StringRef arch = llvm::Triple::getArchTypeName (triple.getArch ());
2062
+ llvm::sys::path::append (path, " Contents" , " Resources" , " Swift" , arch);
2063
+ bool exists = false ;
2064
+ llvm::sys::fs::is_directory (path, exists);
2065
+ if (exists)
2066
+ module_search_paths.push_back (std::string (path));
2067
+ }
2068
+
2069
+ // Create a one-off CompilerInvocation as a place to load the
2070
+ // deserialized search path options into.
2071
+ SymbolFile *sym_file = module_sp->GetSymbolFile ();
2072
+ if (!sym_file)
2073
+ return ;
2074
+ bool found_swift_modules = false ;
2075
+ bool got_serialized_options = false ;
2076
+ llvm::SmallString<0 > error;
2077
+ llvm::raw_svector_ostream errs (error);
2078
+ swift::CompilerInvocation invocation;
2079
+ if (DeserializeAllCompilerFlags (invocation, *module_sp, m_description, errs,
2080
+ got_serialized_options,
2081
+ found_swift_modules)) {
2082
+ // TODO: After removing DeserializeAllCompilerFlags from
2083
+ // CreateInstance(per-Module), errs will need to be
2084
+ // collected here and surfaced.
2085
+ }
2086
+
2087
+ const auto &opts = invocation.getSearchPathOptions ();
2088
+ module_search_paths.insert (module_search_paths.end (),
2089
+ opts.ImportSearchPaths .begin (),
2090
+ opts.ImportSearchPaths .end ());
2091
+ for (const auto &fwsp : opts.FrameworkSearchPaths )
2092
+ framework_search_paths.push_back ({fwsp.Path , fwsp.IsSystem });
2093
+ auto &clang_opts = invocation.getClangImporterOptions ().ExtraArgs ;
2094
+ for (const std::string &arg : clang_opts) {
2095
+ extra_clang_args.push_back (arg);
2096
+ LOG_VERBOSE_PRINTF (LIBLLDB_LOG_TYPES, " adding Clang argument \" %s\" ." ,
2097
+ arg.c_str ());
2063
2098
}
2064
2099
}
2065
2100
0 commit comments