@@ -623,8 +623,25 @@ GetObjectFileFormat(llvm::Triple::ObjectFormatType obj_format_type) {
623
623
return obj_file_format;
624
624
}
625
625
626
+ static llvm::SmallVector<llvm::StringRef, 1 >
627
+ GetLikelySwiftImageNamesForModule (ModuleSP module ) {
628
+ if (!module || !module ->GetFileSpec ())
629
+ return {};
630
+
631
+ auto name =
632
+ module ->GetFileSpec ().GetFileNameStrippingExtension ().GetStringRef ();
633
+ if (name == " libswiftCore" )
634
+ name = " Swift" ;
635
+ if (name.startswith (" libswift" ))
636
+ name = name.drop_front (8 );
637
+ if (name.startswith (" lib" ))
638
+ name = name.drop_front (3 );
639
+ return {name};
640
+ }
641
+
626
642
bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext (
627
- ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type) {
643
+ ObjectFile &obj_file, llvm::Triple::ObjectFormatType obj_format_type,
644
+ llvm::SmallVector<llvm::StringRef, 1 > likely_module_names) {
628
645
assert (obj_file.GetType () == ObjectFile::eTypeJIT &&
629
646
" Not a JIT object file!" );
630
647
auto obj_file_format = GetObjectFileFormat (obj_format_type);
@@ -635,8 +652,7 @@ bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext(
635
652
return m_reflection_ctx->addImage (
636
653
[&](swift::ReflectionSectionKind section_kind)
637
654
-> std::pair<swift::remote::RemoteRef<void >, uint64_t > {
638
- auto section_name =
639
- obj_file_format->getSectionName (section_kind);
655
+ auto section_name = obj_file_format->getSectionName (section_kind);
640
656
for (auto section : *obj_file.GetSectionList ()) {
641
657
JITSection *jit_section = llvm::dyn_cast<JITSection>(section.get ());
642
658
if (jit_section && section->GetName ().AsCString () == section_name) {
@@ -658,11 +674,13 @@ bool SwiftLanguageRuntimeImpl::AddJitObjectFileToReflectionContext(
658
674
}
659
675
}
660
676
return {};
661
- });
677
+ },
678
+ likely_module_names);
662
679
}
663
680
664
681
bool SwiftLanguageRuntimeImpl::AddObjectFileToReflectionContext (
665
- ModuleSP module ) {
682
+ ModuleSP module ,
683
+ llvm::SmallVector<llvm::StringRef, 1 > likely_module_names) {
666
684
auto obj_format_type =
667
685
module ->GetArchitecture ().GetTriple ().getObjectFormat ();
668
686
@@ -787,14 +805,16 @@ bool SwiftLanguageRuntimeImpl::AddObjectFileToReflectionContext(
787
805
}
788
806
return {};
789
807
};
808
+
790
809
return m_reflection_ctx->addImage (
791
810
[&](swift::ReflectionSectionKind section_kind)
792
811
-> std::pair<swift::remote::RemoteRef<void >, uint64_t > {
793
812
auto pair = find_section_with_kind (segment, section_kind);
794
813
if (pair.first )
795
814
return pair;
796
815
return find_section_with_kind (maybe_secondary_segment, section_kind);
797
- });
816
+ },
817
+ likely_module_names);
798
818
}
799
819
800
820
bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext (
@@ -813,10 +833,12 @@ bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext(
813
833
Address start_address = obj_file->GetBaseAddress ();
814
834
auto load_ptr = static_cast <uintptr_t >(
815
835
start_address.GetLoadAddress (&target));
836
+ auto likely_module_names = GetLikelySwiftImageNamesForModule (module_sp);
816
837
if (obj_file->GetType () == ObjectFile::eTypeJIT) {
817
838
auto object_format_type =
818
839
module_sp->GetArchitecture ().GetTriple ().getObjectFormat ();
819
- return AddJitObjectFileToReflectionContext (*obj_file, object_format_type);
840
+ return AddJitObjectFileToReflectionContext (*obj_file, object_format_type,
841
+ likely_module_names);
820
842
}
821
843
822
844
if (load_ptr == 0 || load_ptr == LLDB_INVALID_ADDRESS) {
@@ -843,13 +865,17 @@ bool SwiftLanguageRuntimeImpl::AddModuleToReflectionContext(
843
865
llvm::sys::MemoryBlock file_buffer ((void *)file_data, size);
844
866
m_reflection_ctx->readELF (
845
867
swift::remote::RemoteAddress (load_ptr),
846
- llvm::Optional<llvm::sys::MemoryBlock>(file_buffer));
868
+ llvm::Optional<llvm::sys::MemoryBlock>(file_buffer),
869
+ likely_module_names);
847
870
} else if (read_from_file_cache &&
848
871
obj_file->GetPluginName ().equals (" mach-o" )) {
849
- if (!AddObjectFileToReflectionContext (module_sp))
850
- m_reflection_ctx->addImage (swift::remote::RemoteAddress (load_ptr));
872
+ if (!AddObjectFileToReflectionContext (module_sp, likely_module_names)) {
873
+ m_reflection_ctx->addImage (swift::remote::RemoteAddress (load_ptr),
874
+ likely_module_names);
875
+ }
851
876
} else {
852
- m_reflection_ctx->addImage (swift::remote::RemoteAddress (load_ptr));
877
+ m_reflection_ctx->addImage (swift::remote::RemoteAddress (load_ptr),
878
+ likely_module_names);
853
879
}
854
880
return true ;
855
881
}
0 commit comments