34
34
35
35
#include " Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
36
36
#include " Plugins/TypeSystem/Clang/TypeSystemClang.h"
37
+ #include " llvm/Support/ThreadPool.h"
37
38
38
39
// #define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
39
40
#ifdef ENABLE_DEBUG_PRINTF
48
49
using namespace lldb ;
49
50
using namespace lldb_private ;
50
51
52
+ #define LLDB_PROPERTIES_dynamicloaderdarwin
53
+ #include " DynamicLoaderDarwinProperties.inc"
54
+
55
+ enum {
56
+ #define LLDB_PROPERTIES_dynamicloaderdarwin
57
+ #include " DynamicLoaderDarwinPropertiesEnum.inc"
58
+ };
59
+
60
+ ConstString &DynamicLoaderDarwinProperties::GetSettingName () {
61
+ static ConstString g_setting_name (" darwin" );
62
+ return g_setting_name;
63
+ }
64
+
65
+ DynamicLoaderDarwinProperties::DynamicLoaderDarwinProperties () : Properties() {
66
+ m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName ());
67
+ m_collection_sp->Initialize (g_dynamicloaderdarwin_properties);
68
+ }
69
+
70
+ bool DynamicLoaderDarwinProperties::GetEnableParallelImageLoad () const {
71
+ return GetPropertyAtIndexAs<bool >(
72
+ ePropertyEnableParallelImageLoad,
73
+ g_dynamicloaderdarwin_properties[ePropertyEnableParallelImageLoad]
74
+ .default_uint_value != 0 );
75
+ }
76
+
77
+ DynamicLoaderDarwinProperties &DynamicLoaderDarwinProperties::GetGlobal () {
78
+ static DynamicLoaderDarwinProperties g_settings;
79
+ return g_settings;
80
+ }
81
+
51
82
// Constructor
52
83
DynamicLoaderDarwin::DynamicLoaderDarwin (Process *process)
53
84
: DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(),
@@ -77,6 +108,17 @@ void DynamicLoaderDarwin::DidLaunch() {
77
108
SetNotificationBreakpoint ();
78
109
}
79
110
111
+ void DynamicLoaderDarwin::CreateSettings (lldb_private::Debugger &debugger) {
112
+ if (!PluginManager::GetSettingForDynamicLoaderPlugin (
113
+ debugger, DynamicLoaderDarwinProperties::GetSettingName ())) {
114
+ const bool is_global_setting = true ;
115
+ PluginManager::CreateSettingForDynamicLoaderPlugin (
116
+ debugger,
117
+ DynamicLoaderDarwinProperties::GetGlobal ().GetValueProperties (),
118
+ " Properties for the DynamicLoaderDarwin plug-in." , is_global_setting);
119
+ }
120
+ }
121
+
80
122
// Clear out the state of this class.
81
123
void DynamicLoaderDarwin::Clear (bool clear_process) {
82
124
std::lock_guard<std::recursive_mutex> guard (m_mutex);
@@ -640,6 +682,41 @@ ModuleSP DynamicLoaderDarwin::GetDYLDModule() {
640
682
641
683
void DynamicLoaderDarwin::ClearDYLDModule () { m_dyld_module_wp.reset (); }
642
684
685
+ template <typename InputIterator, typename ResultType>
686
+ std::vector<ResultType>
687
+ parallel_map (llvm::ThreadPoolInterface &threadPool, InputIterator first,
688
+ InputIterator last,
689
+ llvm::function_ref<ResultType(
690
+ typename std::iterator_traits<InputIterator>::value_type &)>
691
+ transform) {
692
+ const auto size = std::distance (first, last);
693
+ std::vector<ResultType> results (size);
694
+ if (size > 0 ) {
695
+ llvm::ThreadPoolTaskGroup taskGroup (threadPool);
696
+ auto it = first;
697
+ for (ssize_t i = 0 ; i < size; ++i, ++it) {
698
+ taskGroup.async ([&, i, it]() { results[i] = transform (*it); });
699
+ }
700
+ taskGroup.wait ();
701
+ }
702
+ return results;
703
+ }
704
+
705
+ template <typename InputIterator, typename ResultType>
706
+ std::vector<ResultType>
707
+ map (InputIterator first, InputIterator last,
708
+ llvm::function_ref<
709
+ ResultType (typename std::iterator_traits<InputIterator>::value_type &)>
710
+ transform) {
711
+ const auto size = std::distance (first, last);
712
+ std::vector<ResultType> results (size);
713
+ auto it = first;
714
+ for (ssize_t i = 0 ; i < size; ++i, ++it) {
715
+ results[i] = transform (*it);
716
+ }
717
+ return results;
718
+ }
719
+
643
720
bool DynamicLoaderDarwin::AddModulesUsingImageInfos (
644
721
ImageInfo::collection &image_infos) {
645
722
std::lock_guard<std::recursive_mutex> guard (m_mutex);
@@ -649,17 +726,27 @@ bool DynamicLoaderDarwin::AddModulesUsingImageInfos(
649
726
Target &target = m_process->GetTarget ();
650
727
ModuleList &target_images = target.GetImages ();
651
728
652
- for ( uint32_t idx = 0 ; idx < image_infos. size (); ++idx ) {
729
+ auto ImageLoad = [ this , log ](ImageInfo &image_info ) {
653
730
if (log ) {
654
731
LLDB_LOGF (log , " Adding new image at address=0x%16.16" PRIx64 " ." ,
655
- image_infos[idx] .address );
656
- image_infos[idx] .PutToLog (log );
732
+ image_info .address );
733
+ image_info .PutToLog (log );
657
734
}
735
+ return FindTargetModuleForImageInfo (image_info, true , nullptr );
736
+ };
737
+ bool is_parallel_load =
738
+ DynamicLoaderDarwinProperties::GetGlobal ().GetEnableParallelImageLoad ();
739
+ auto images = is_parallel_load
740
+ ? parallel_map<ImageInfo::collection::iterator, ModuleSP>(
741
+ Debugger ::GetThreadPool (), image_infos.begin (),
742
+ image_infos.end (), ImageLoad)
743
+ : map<ImageInfo::collection::iterator, ModuleSP>(
744
+ image_infos.begin (), image_infos.end (), ImageLoad);
658
745
746
+ for (uint32_t idx = 0 ; idx < image_infos.size (); ++idx) {
659
747
m_dyld_image_infos.push_back (image_infos[idx]);
660
748
661
- ModuleSP image_module_sp (
662
- FindTargetModuleForImageInfo (image_infos[idx], true , nullptr ));
749
+ ModuleSP image_module_sp = images[idx];
663
750
664
751
if (image_module_sp) {
665
752
ObjectFile *objfile = image_module_sp->GetObjectFile ();
0 commit comments