@@ -530,44 +530,43 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
530
530
return true ;
531
531
}
532
532
533
- void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos (
534
- ImageInfo::collection &image_infos ) {
533
+ void DynamicLoaderDarwin::UpdateSpecialBinariesFromPreloadedModules (
534
+ std::vector<std::pair<ImageInfo, ModuleSP>> &images ) {
535
535
uint32_t exe_idx = UINT32_MAX;
536
536
uint32_t dyld_idx = UINT32_MAX;
537
537
Target &target = m_process->GetTarget ();
538
538
Log *log = GetLog (LLDBLog::DynamicLoader);
539
539
ConstString g_dyld_sim_filename (" dyld_sim" );
540
540
541
541
ArchSpec target_arch = target.GetArchitecture ();
542
- const size_t image_infos_size = image_infos.size ();
543
- for (size_t i = 0 ; i < image_infos_size; i++) {
544
- if (image_infos[i].header .filetype == llvm::MachO::MH_DYLINKER) {
542
+ const size_t images_size = images.size ();
543
+ for (size_t i = 0 ; i < images_size; i++) {
544
+ const auto &image_info = images[i].first ;
545
+ if (image_info.header .filetype == llvm::MachO::MH_DYLINKER) {
545
546
// In a "simulator" process we will have two dyld modules --
546
547
// a "dyld" that we want to keep track of, and a "dyld_sim" which
547
548
// we don't need to keep track of here. dyld_sim will have a non-macosx
548
549
// OS.
549
550
if (target_arch.GetTriple ().getEnvironment () == llvm::Triple::Simulator &&
550
- image_infos[i] .os_type != llvm::Triple::OSType ::MacOSX) {
551
+ image_info .os_type != llvm::Triple::OSType ::MacOSX) {
551
552
continue ;
552
553
}
553
554
554
555
dyld_idx = i;
555
556
}
556
- if (image_infos[i] .header .filetype == llvm::MachO::MH_EXECUTE) {
557
+ if (image_info .header .filetype == llvm::MachO::MH_EXECUTE) {
557
558
exe_idx = i;
558
559
}
559
560
}
560
561
561
562
// Set the target executable if we haven't found one so far.
562
563
if (exe_idx != UINT32_MAX && !target.GetExecutableModule ()) {
563
- const bool can_create = true ;
564
- ModuleSP exe_module_sp (FindTargetModuleForImageInfo (image_infos[exe_idx],
565
- can_create, nullptr ));
564
+ ModuleSP exe_module_sp = images[exe_idx].second ;
566
565
if (exe_module_sp) {
567
566
LLDB_LOGF (log , " Found executable module: %s" ,
568
567
exe_module_sp->GetFileSpec ().GetPath ().c_str ());
569
568
target.GetImages ().AppendIfNeeded (exe_module_sp);
570
- UpdateImageLoadAddress (exe_module_sp.get (), image_infos [exe_idx]);
569
+ UpdateImageLoadAddress (exe_module_sp.get (), images [exe_idx]. first );
571
570
if (exe_module_sp.get () != target.GetExecutableModulePointer ())
572
571
target.SetExecutableModule (exe_module_sp, eLoadDependentsNo);
573
572
@@ -594,14 +593,12 @@ void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos(
594
593
}
595
594
596
595
if (dyld_idx != UINT32_MAX) {
597
- const bool can_create = true ;
598
- ModuleSP dyld_sp = FindTargetModuleForImageInfo (image_infos[dyld_idx],
599
- can_create, nullptr );
596
+ ModuleSP dyld_sp = images[dyld_idx].second ;
600
597
if (dyld_sp.get ()) {
601
598
LLDB_LOGF (log , " Found dyld module: %s" ,
602
599
dyld_sp->GetFileSpec ().GetPath ().c_str ());
603
600
target.GetImages ().AppendIfNeeded (dyld_sp);
604
- UpdateImageLoadAddress (dyld_sp.get (), image_infos [dyld_idx]);
601
+ UpdateImageLoadAddress (dyld_sp.get (), images [dyld_idx]. first );
605
602
SetDYLDModule (dyld_sp);
606
603
}
607
604
}
@@ -690,37 +687,51 @@ map(InputIterator first, InputIterator last,
690
687
return results;
691
688
}
692
689
690
+ std::vector<std::pair<DynamicLoaderDarwin::ImageInfo, ModuleSP>>
691
+ DynamicLoaderDarwin::PreloadModulesFromImageInfos (
692
+ const ImageInfo::collection &image_infos) {
693
+ auto ImageLoad = [this ](const ImageInfo &image_info) {
694
+ return std::make_pair (
695
+ image_info, FindTargetModuleForImageInfo (image_info, true , nullptr ));
696
+ };
697
+ bool is_parallel_load =
698
+ DynamicLoaderDarwinProperties::GetGlobal ().GetEnableParallelImageLoad ();
699
+ auto images = is_parallel_load
700
+ ? parallel_map<ImageInfo::collection::const_iterator,
701
+ std::pair<ImageInfo, ModuleSP>>(
702
+ Debugger ::GetThreadPool (), image_infos.begin (),
703
+ image_infos.end (), ImageLoad)
704
+ : map<ImageInfo::collection::const_iterator,
705
+ std::pair<ImageInfo, ModuleSP>>(
706
+ image_infos.begin (), image_infos.end (), ImageLoad);
707
+ return images;
708
+ }
709
+
693
710
bool DynamicLoaderDarwin::AddModulesUsingImageInfos (
694
711
ImageInfo::collection &image_infos) {
695
712
std::lock_guard<std::recursive_mutex> guard (m_mutex);
713
+ auto images = PreloadModulesFromImageInfos (image_infos);
714
+ return AddModulesUsingPreloadedModules (images);
715
+ }
716
+
717
+ bool DynamicLoaderDarwin::AddModulesUsingPreloadedModules (
718
+ std::vector<std::pair<ImageInfo, ModuleSP>> &images) {
719
+ std::lock_guard<std::recursive_mutex> guard (m_mutex);
696
720
// Now add these images to the main list.
697
721
ModuleList loaded_module_list;
698
722
Log *log = GetLog (LLDBLog::DynamicLoader);
699
723
Target &target = m_process->GetTarget ();
700
724
ModuleList &target_images = target.GetImages ();
701
725
702
- auto ImageLoad = [this , log ](const ImageInfo &image_info) {
726
+ for (uint32_t idx = 0 ; idx < images.size (); ++idx) {
727
+ auto &image_info = images[idx].first ;
728
+ const auto &image_module_sp = images[idx].second ;
703
729
if (log ) {
704
730
LLDB_LOGF (log , " Adding new image at address=0x%16.16" PRIx64 " ." ,
705
731
image_info.address );
706
732
image_info.PutToLog (log );
707
733
}
708
- return FindTargetModuleForImageInfo (image_info, true , nullptr );
709
- };
710
- bool is_parallel_load =
711
- DynamicLoaderDarwinProperties::GetGlobal ().GetEnableParallelImageLoad ();
712
- auto images =
713
- is_parallel_load
714
- ? parallel_map<ImageInfo::collection::const_iterator, ModuleSP>(
715
- Debugger ::GetThreadPool (), image_infos.begin (),
716
- image_infos.end (), ImageLoad)
717
- : map<ImageInfo::collection::const_iterator, ModuleSP>(
718
- image_infos.begin (), image_infos.end (), ImageLoad);
719
-
720
- for (uint32_t idx = 0 ; idx < image_infos.size (); ++idx) {
721
- m_dyld_image_infos.push_back (image_infos[idx]);
722
-
723
- ModuleSP image_module_sp = images[idx];
734
+ m_dyld_image_infos.push_back (image_info);
724
735
725
736
if (image_module_sp) {
726
737
ObjectFile *objfile = image_module_sp->GetObjectFile ();
@@ -732,7 +743,7 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos(
732
743
sections->FindSectionByName (commpage_dbstr).get ();
733
744
if (commpage_section) {
734
745
ModuleSpec module_spec (objfile->GetFileSpec (),
735
- image_infos[idx] .GetArchitecture ());
746
+ image_info .GetArchitecture ());
736
747
module_spec.GetObjectName () = commpage_dbstr;
737
748
ModuleSP commpage_image_module_sp (
738
749
target_images.FindFirstModule (module_spec));
@@ -745,17 +756,17 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos(
745
756
if (!commpage_image_module_sp ||
746
757
commpage_image_module_sp->GetObjectFile () == nullptr ) {
747
758
commpage_image_module_sp = m_process->ReadModuleFromMemory (
748
- image_infos[idx] .file_spec , image_infos[idx] .address );
759
+ image_info .file_spec , image_info .address );
749
760
// Always load a memory image right away in the target in case
750
761
// we end up trying to read the symbol table from memory... The
751
762
// __LINKEDIT will need to be mapped so we can figure out where
752
763
// the symbol table bits are...
753
764
bool changed = false ;
754
765
UpdateImageLoadAddress (commpage_image_module_sp.get (),
755
- image_infos[idx] );
766
+ image_info );
756
767
target.GetImages ().Append (commpage_image_module_sp);
757
768
if (changed) {
758
- image_infos[idx] .load_stop_id = m_process->GetStopID ();
769
+ image_info .load_stop_id = m_process->GetStopID ();
759
770
loaded_module_list.AppendIfNeeded (commpage_image_module_sp);
760
771
}
761
772
}
@@ -768,14 +779,14 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos(
768
779
// address. We need to check this so we don't mention that all loaded
769
780
// shared libraries are newly loaded each time we hit out dyld breakpoint
770
781
// since dyld will list all shared libraries each time.
771
- if (UpdateImageLoadAddress (image_module_sp.get (), image_infos[idx] )) {
782
+ if (UpdateImageLoadAddress (image_module_sp.get (), image_info )) {
772
783
target_images.AppendIfNeeded (image_module_sp);
773
784
loaded_module_list.AppendIfNeeded (image_module_sp);
774
785
}
775
786
776
787
// To support macCatalyst and legacy iOS simulator,
777
788
// update the module's platform with the DYLD info.
778
- ArchSpec dyld_spec = image_infos[idx] .GetArchitecture ();
789
+ ArchSpec dyld_spec = image_info .GetArchitecture ();
779
790
auto &dyld_triple = dyld_spec.GetTriple ();
780
791
if ((dyld_triple.getEnvironment () == llvm::Triple::MacABI &&
781
792
dyld_triple.getOS () == llvm::Triple::IOS) ||
0 commit comments