@@ -1765,6 +1765,16 @@ static bool IsDWARFImported(swift::ModuleDecl &module) {
1765
1765
});
1766
1766
}
1767
1767
1768
+ // / Detect whether this is a proper Swift module.
1769
+ static bool IsSerializedAST (swift::ModuleDecl &module ) {
1770
+ return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1771
+ [](swift::FileUnit *file_unit) {
1772
+ return (file_unit->getKind () ==
1773
+ swift::FileUnitKind::SerializedAST);
1774
+ });
1775
+ }
1776
+
1777
+
1768
1778
lldb::TypeSystemSP
1769
1779
SwiftASTContext::CreateInstance (lldb::LanguageType language, Module &module ,
1770
1780
TypeSystemSwiftTypeRef &typeref_typesystem,
@@ -1871,7 +1881,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1871
1881
bool got_serialized_options = false ;
1872
1882
llvm::SmallString<0 > error;
1873
1883
llvm::raw_svector_ostream errs (error);
1874
- // Implicit search paths will be discoverd by ValidateSecionModules().
1884
+ // Implicit search paths will be discovered by ValidateSecionModules().
1875
1885
bool discover_implicit_search_paths = false ;
1876
1886
1877
1887
auto ast_file_datas = module .GetASTData (eLanguageTypeSwift);
@@ -8363,10 +8373,42 @@ bool SwiftASTContextForExpressions::CacheUserImports(
8363
8373
LOG_PRINTF (GetLog (LLDBLog::Types | LLDBLog::Expressions),
8364
8374
" Performing auto import on found module: %s.\n " ,
8365
8375
module_name.c_str ());
8366
- if (!LoadOneModule (module_info, *this , process_sp,
8367
- /* import_dylibs=*/ true , error))
8376
+ auto *module_decl = LoadOneModule (module_info, *this , process_sp,
8377
+ /* import_dylibs=*/ true , error);
8378
+ if (!module_decl)
8368
8379
return false ;
8369
-
8380
+ if (IsSerializedAST (*module_decl)) {
8381
+ // Parse additional search paths from the module.
8382
+ StringRef ast_file = module_decl->getModuleLoadedFilename ();
8383
+ if (llvm::sys::path::is_absolute (ast_file)) {
8384
+ auto file_or_err =
8385
+ llvm::MemoryBuffer::getFile (ast_file, /* IsText=*/ false ,
8386
+ /* RequiresNullTerminator=*/ false );
8387
+ if (!file_or_err.getError () && file_or_err->get ()) {
8388
+ PathMappingList path_remap;
8389
+ llvm::SmallString<0 > error;
8390
+ bool found_swift_modules = false ;
8391
+ bool got_serialized_options = false ;
8392
+ llvm::raw_svector_ostream errs (error);
8393
+ bool discover_implicit_search_paths = false ;
8394
+ swift::CompilerInvocation &invocation = GetCompilerInvocation ();
8395
+
8396
+ LOG_PRINTF (GetLog (LLDBLog::Types),
8397
+ " Scanning for search paths in %s" ,
8398
+ ast_file.str ().c_str ());
8399
+ if (DeserializeAllCompilerFlags (
8400
+ invocation, ast_file, {file_or_err->get ()->getBuffer ()},
8401
+ path_remap, discover_implicit_search_paths,
8402
+ m_description.str ().str (), errs, got_serialized_options,
8403
+ found_swift_modules)) {
8404
+ LOG_PRINTF (GetLog (LLDBLog::Types), " Could not parse %s: %s" ,
8405
+ ast_file.str ().c_str (), error.str ().str ().c_str ());
8406
+ }
8407
+ if (got_serialized_options)
8408
+ LogConfiguration ();
8409
+ }
8410
+ }
8411
+ }
8370
8412
// How do we tell we are in REPL or playground mode?
8371
8413
AddHandLoadedModule (module_const_str, attributed_import);
8372
8414
}
0 commit comments