|
19 | 19 | #include "lldb/Symbol/SymbolContext.h" |
20 | 20 | #include "lldb/Symbol/TypeList.h" |
21 | 21 | #include "lldb/Symbol/VariableList.h" |
| 22 | +#include "lldb/Target/Platform.h" |
| 23 | +#include "lldb/Target/Target.h" |
22 | 24 | #include "lldb/Utility/ArchSpec.h" |
23 | 25 | #include "lldb/Utility/ConstString.h" |
24 | 26 | #include "lldb/Utility/FileSpecList.h" |
@@ -1038,9 +1040,9 @@ size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) { |
1038 | 1040 |
|
1039 | 1041 | Status |
1040 | 1042 | ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, |
1041 | | - const FileSpecList *module_search_paths_ptr, |
1042 | 1043 | llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, |
1043 | | - bool *did_create_ptr, bool always_create) { |
| 1044 | + bool *did_create_ptr, bool always_create, |
| 1045 | + bool invoke_locate_callback) { |
1044 | 1046 | SharedModuleList &shared_module_list = GetSharedModuleList(); |
1045 | 1047 | std::lock_guard<std::recursive_mutex> guard(shared_module_list.GetMutex()); |
1046 | 1048 | char path[PATH_MAX]; |
@@ -1095,6 +1097,22 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, |
1095 | 1097 | if (module_sp) |
1096 | 1098 | return error; |
1097 | 1099 |
|
| 1100 | + // Try target's platform locate module callback before second attempt. |
| 1101 | + if (invoke_locate_callback) { |
| 1102 | + TargetSP target_sp = module_spec.GetTargetSP(); |
| 1103 | + if (target_sp && target_sp->IsValid()) { |
| 1104 | + if (PlatformSP platform_sp = target_sp->GetPlatform()) { |
| 1105 | + FileSpec symbol_file_spec; |
| 1106 | + platform_sp->CallLocateModuleCallbackIfSet( |
| 1107 | + module_spec, module_sp, symbol_file_spec, did_create_ptr); |
| 1108 | + if (module_sp) { |
| 1109 | + // The callback found a module. |
| 1110 | + return error; |
| 1111 | + } |
| 1112 | + } |
| 1113 | + } |
| 1114 | + } |
| 1115 | + |
1098 | 1116 | module_sp = std::make_shared<Module>(module_spec); |
1099 | 1117 | // Make sure there are a module and an object file since we can specify a |
1100 | 1118 | // valid file path with an architecture that might not be in that file. By |
@@ -1122,10 +1140,16 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp, |
1122 | 1140 | module_sp.reset(); |
1123 | 1141 | } |
1124 | 1142 |
|
1125 | | - if (module_search_paths_ptr) { |
1126 | | - const auto num_directories = module_search_paths_ptr->GetSize(); |
| 1143 | + // Get module search paths from the target if available. |
| 1144 | + lldb::TargetSP target_sp = module_spec.GetTargetSP(); |
| 1145 | + FileSpecList module_search_paths; |
| 1146 | + if (target_sp) |
| 1147 | + module_search_paths = target_sp->GetExecutableSearchPaths(); |
| 1148 | + |
| 1149 | + if (!module_search_paths.IsEmpty()) { |
| 1150 | + const auto num_directories = module_search_paths.GetSize(); |
1127 | 1151 | for (size_t idx = 0; idx < num_directories; ++idx) { |
1128 | | - auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx); |
| 1152 | + auto search_path_spec = module_search_paths.GetFileSpecAtIndex(idx); |
1129 | 1153 | FileSystem::Instance().Resolve(search_path_spec); |
1130 | 1154 | namespace fs = llvm::sys::fs; |
1131 | 1155 | if (!FileSystem::Instance().IsDirectory(search_path_spec)) |
|
0 commit comments