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; }
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); } }
DWARFExpression lldb_private::npdb::MakeConstantLocationExpression( TypeIndex underlying_ti, TpiStream &tpi, const llvm::APSInt &constant, ModuleSP module) { const ArchSpec &architecture = module->GetArchitecture(); uint32_t address_size = architecture.GetAddressByteSize(); size_t size = 0; bool is_signed = false; std::tie(size, is_signed) = GetIntegralTypeInfo(underlying_ti, tpi); union { llvm::support::little64_t I; llvm::support::ulittle64_t U; } Value; std::shared_ptr<DataBufferHeap> buffer = std::make_shared<DataBufferHeap>(); buffer->SetByteSize(size); llvm::ArrayRef<uint8_t> bytes; if (is_signed) { Value.I = constant.getSExtValue(); } else { Value.U = constant.getZExtValue(); } bytes = llvm::makeArrayRef(reinterpret_cast<const uint8_t *>(&Value), 8) .take_front(size); buffer->CopyData(bytes.data(), size); DataExtractor extractor(buffer, lldb::eByteOrderLittle, address_size); DWARFExpression result(nullptr, extractor, nullptr, 0, size); return result; }
/// 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; }
//-------------------------------------------------------------- /// 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; }
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(); }