@@ -815,13 +815,27 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
815815 return LLDB_INVALID_ADDRESS;
816816 }
817817
818+ ModuleList non_local_images = target->GetImages ();
819+ // We'll process module_sp separately, before the other modules.
820+ non_local_images.Remove (sc.module_sp );
821+ // BEGIN SWIFT
822+ if (m_in_populate_symtab)
823+ if (lldb::ModuleSP module_sp = m_jit_module_wp.lock ())
824+ non_local_images.Remove (module_sp);
825+ // END SWIFT
826+
818827 LoadAddressResolver resolver (target, symbol_was_missing_weak);
819828
820829 ModuleFunctionSearchOptions function_options;
821830 function_options.include_symbols = true ;
822831 function_options.include_inlines = false ;
823832
824833 for (const ConstString &name : names) {
834+ // The lookup order here is as follows:
835+ // 1) Functions in `sc.module_sp`
836+ // 2) Functions in the other modules
837+ // 3) Symbols in `sc.module_sp`
838+ // 4) Symbols in the other modules
825839 if (sc.module_sp ) {
826840 SymbolContextList sc_list;
827841 sc.module_sp ->FindFunctions (name, CompilerDeclContext (),
@@ -831,21 +845,26 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
831845 return *load_addr;
832846 }
833847
834- if (sc. target_sp ) {
835- ModuleList images = sc. target_sp -> GetImages () ;
836- // BEGIN SWIFT
837- if (m_in_populate_symtab)
838- if (lldb::ModuleSP module_sp = m_jit_module_wp. lock ( ))
839- images. Remove (module_sp) ;
840- // END SWIFT
848+ {
849+ SymbolContextList sc_list ;
850+ non_local_images. FindFunctions (name, lldb::eFunctionNameTypeFull,
851+ function_options, sc_list);
852+ if (auto load_addr = resolver. Resolve (sc_list ))
853+ return *load_addr ;
854+ }
841855
856+ if (sc.module_sp ) {
842857 SymbolContextList sc_list;
843- images. FindFunctions (name, lldb::eFunctionNameTypeFull, function_options ,
844- sc_list);
858+ sc. module_sp -> FindSymbolsWithNameAndType (name, lldb::eSymbolTypeAny ,
859+ sc_list);
845860 if (auto load_addr = resolver.Resolve (sc_list))
846861 return *load_addr;
862+ }
847863
848- images.FindSymbolsWithNameAndType (name, lldb::eSymbolTypeAny, sc_list);
864+ {
865+ SymbolContextList sc_list;
866+ non_local_images.FindSymbolsWithNameAndType (name, lldb::eSymbolTypeAny,
867+ sc_list);
849868 if (auto load_addr = resolver.Resolve (sc_list))
850869 return *load_addr;
851870 }
0 commit comments