ModuleSP DynamicLoader::GetTargetExecutable() { Target &target = m_process->GetTarget(); ModuleSP executable = target.GetExecutableModule(); if (executable) { if (FileSystem::Instance().Exists(executable->GetFileSpec())) { ModuleSpec module_spec(executable->GetFileSpec(), executable->GetArchitecture()); auto module_sp = std::make_shared<Module>(module_spec); // Check if the executable has changed and set it to the target // executable if they differ. if (module_sp && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid()) { if (module_sp->GetUUID() != executable->GetUUID()) executable.reset(); } else if (executable->FileHasChanged()) { executable.reset(); } if (!executable) { executable = target.GetOrCreateModule(module_spec, true /* notify */); if (executable.get() != target.GetExecutableModulePointer()) { // Don't load dependent images since we are in dyld where we will // know and find out about all images that are loaded target.SetExecutableModule(executable, eLoadDependentsNo); } } } } return executable; }
bool SearchFilterByModuleList::ModulePasses(const ModuleSP &module_sp) { if (m_module_spec_list.GetSize() == 0) return true; return module_sp && m_module_spec_list.FindFileIndex( 0, module_sp->GetFileSpec(), false) != UINT32_MAX; }
void ModuleList::ReplaceEquivalent (const ModuleSP &module_sp) { if (module_sp) { Mutex::Locker locker(m_modules_mutex); // First remove any equivalent modules. Equivalent modules are modules // whose path, platform path and architecture match. ModuleSpec equivalent_module_spec (module_sp->GetFileSpec(), module_sp->GetArchitecture()); equivalent_module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec(); size_t idx = 0; while (idx < m_modules.size()) { ModuleSP module_sp (m_modules[idx]); if (module_sp->MatchesModuleSpec (equivalent_module_spec)) RemoveImpl(m_modules.begin() + idx); else ++idx; } // Now add the new module to the list Append(module_sp); } }
bool SearchFilterByModule::ModulePasses (const ModuleSP &module_sp) { if (module_sp && FileSpec::Compare (module_sp->GetFileSpec(), m_module_spec, false) == 0) return true; else return false; }
/// Checks to see if the target module has changed, updates the target /// accordingly and returns the target executable module. ModuleSP DynamicLoaderHexagonDYLD::GetTargetExecutable() { Target &target = m_process->GetTarget(); ModuleSP executable = target.GetExecutableModule(); // There is no executable if (! executable.get()) return executable; // The target executable file does not exits if (! executable->GetFileSpec().Exists()) return executable; // Prep module for loading ModuleSpec module_spec(executable->GetFileSpec(), executable->GetArchitecture()); ModuleSP module_sp (new Module (module_spec)); // Check if the executable has changed and set it to the target executable if they differ. if (module_sp.get() && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid()) { // if the executable has changed ?? if (module_sp->GetUUID() != executable->GetUUID()) executable.reset(); } else if (executable->FileHasChanged()) executable.reset(); if ( executable.get( ) ) return executable; // TODO: What case is this code used? executable = target.GetSharedModule(module_spec); if (executable.get() != target.GetExecutableModulePointer()) { // Don't load dependent images since we are in dyld where we will know // and find out about all images that are loaded const bool get_dependent_images = false; target.SetExecutableModule(executable, get_dependent_images); } return executable; }
Error ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, const ModuleSpec &module_spec, ModuleSP &cached_module_sp, bool *did_create_ptr) { const auto find_it = m_loaded_modules.find(module_spec.GetUUID().GetAsString()); if (find_it != m_loaded_modules.end()) { cached_module_sp = (*find_it).second.lock(); if (cached_module_sp) return Error(); m_loaded_modules.erase(find_it); } const auto module_spec_dir = GetModuleDirectory(root_dir_spec, module_spec.GetUUID()); const auto module_file_path = JoinPath( module_spec_dir, module_spec.GetFileSpec().GetFilename().AsCString()); if (!module_file_path.Exists()) return Error("Module %s not found", module_file_path.GetPath().c_str()); if (module_file_path.GetByteSize() != module_spec.GetObjectSize()) return Error("Module %s has invalid file size", module_file_path.GetPath().c_str()); // We may have already cached module but downloaded from an another host - in // this case let's create a link to it. auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path, false); if (error.Fail()) return Error("Failed to create link to %s: %s", module_file_path.GetPath().c_str(), error.AsCString()); auto cached_module_spec(module_spec); cached_module_spec.GetUUID().Clear(); // Clear UUID since it may contain md5 // content hash instead of real UUID. cached_module_spec.GetFileSpec() = module_file_path; cached_module_spec.GetPlatformFileSpec() = module_spec.GetFileSpec(); error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp, nullptr, nullptr, did_create_ptr, false); if (error.Fail()) return error; FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec()); if (symfile_spec.Exists()) cached_module_sp->SetSymbolFileFileSpec(symfile_spec); m_loaded_modules.insert( std::make_pair(module_spec.GetUUID().GetAsString(), cached_module_sp)); return Error(); }
bool ObjCTrampolineHandler::ModuleIsObjCLibrary (const ModuleSP &module_sp) { const FileSpec &module_file_spec = module_sp->GetFileSpec(); static ConstString ObjCName ("libobjc.A.dylib"); if (module_file_spec) { if (module_file_spec.GetFilename() == ObjCName) return true; } return false; }
bool AppleObjCRuntime::AppleIsModuleObjCLibrary (const ModuleSP &module_sp) { const FileSpec &module_file_spec = module_sp->GetFileSpec(); static ConstString ObjCName ("libobjc.A.dylib"); if (module_file_spec) { if (module_file_spec.GetFilename() == ObjCName) return true; } return false; }
//-------------------------------------------------------------- /// Unary predicate function object callback. //-------------------------------------------------------------- bool operator () (const ModuleSP& module_sp) const { if (m_file_spec_ptr) { if (m_file_spec_is_platform) { if (!FileSpec::Equal (*m_file_spec_ptr, module_sp->GetPlatformFileSpec(), m_file_spec_compare_basename_only)) return false; } else { if (!FileSpec::Equal (*m_file_spec_ptr, module_sp->GetFileSpec(), m_file_spec_compare_basename_only)) return false; } } if (m_arch_ptr && m_arch_ptr->IsValid()) { if (module_sp->GetArchitecture() != *m_arch_ptr) return false; } if (m_uuid_ptr && m_uuid_ptr->IsValid()) { if (module_sp->GetUUID() != *m_uuid_ptr) return false; } if (m_object_name) { if (module_sp->GetObjectName() != *m_object_name) return false; } return true; }
static void ModuleSharedPtrLogger(void* p, const ModuleSP& sp, bool will_decrement) { if (sp.get()) { const char *module_basename = sp->GetFileSpec().GetFilename().GetCString(); // If "p" is set, then it is the basename of a module to watch for. This // basename MUST be uniqued first by getting it from a ConstString or this // won't work. if (p && p != module_basename) { return; } long use_count = sp.use_count(); if (will_decrement) --use_count; printf("\nModuleSP(%p): %c %p {%lu} %s/%s\n", &sp, will_decrement ? '-' : '+', sp.get(), use_count, sp->GetFileSpec().GetDirectory().GetCString(), module_basename); StreamFile stdout_strm(stdout, false); Host::Backtrace (stdout_strm, 512); } }
bool SearchFilterByModule::ModulePasses(const ModuleSP &module_sp) { return (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false)); }
void Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) { m_images.Clear(); m_scratch_ast_context_ap.reset(); if (executable_sp.get()) { Timer scoped_timer (__PRETTY_FUNCTION__, "Target::SetExecutableModule (executable = '%s/%s')", executable_sp->GetFileSpec().GetDirectory().AsCString(), executable_sp->GetFileSpec().GetFilename().AsCString()); m_images.Append(executable_sp); // The first image is our exectuable file ArchSpec exe_arch = executable_sp->GetArchitecture(); // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. if (!m_arch_spec.IsValid()) m_arch_spec = exe_arch; FileSpecList dependent_files; ObjectFile * executable_objfile = executable_sp->GetObjectFile(); if (executable_objfile == NULL) { FileSpec bundle_executable(executable_sp->GetFileSpec()); if (Host::ResolveExecutableInBundle (bundle_executable)) { ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable, exe_arch)); SetExecutableModule (bundle_exe_module_sp, get_dependent_files); if (bundle_exe_module_sp->GetObjectFile() != NULL) executable_sp = bundle_exe_module_sp; return; } } if (executable_objfile) { executable_objfile->GetDependentModules(dependent_files); for (uint32_t i=0; i<dependent_files.GetSize(); i++) { ModuleSP image_module_sp(GetSharedModule(dependent_files.GetFileSpecPointerAtIndex(i), exe_arch)); if (image_module_sp.get()) { //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY ObjectFile *objfile = image_module_sp->GetObjectFile(); if (objfile) objfile->GetDependentModules(dependent_files); } } } // Now see if we know the target triple, and if so, create our scratch AST context: if (m_arch_spec.IsValid()) { m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch_spec.GetTriple().str().c_str())); } } UpdateInstanceName(); }