146c2e4c4SJeffrey Tan //===-- ObjectFilePlaceholder.cpp----------------------------------------===// 246c2e4c4SJeffrey Tan // 346c2e4c4SJeffrey Tan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 446c2e4c4SJeffrey Tan // See https://llvm.org/LICENSE.txt for license information. 546c2e4c4SJeffrey Tan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 646c2e4c4SJeffrey Tan // 746c2e4c4SJeffrey Tan //===----------------------------------------------------------------------===// 846c2e4c4SJeffrey Tan 946c2e4c4SJeffrey Tan #include "ObjectFilePlaceholder.h" 1046c2e4c4SJeffrey Tan 1146c2e4c4SJeffrey Tan #include "lldb/Core/Module.h" 1246c2e4c4SJeffrey Tan #include "lldb/Core/ModuleSpec.h" 1346c2e4c4SJeffrey Tan #include "lldb/Core/PluginManager.h" 1446c2e4c4SJeffrey Tan #include "lldb/Core/Section.h" 1546c2e4c4SJeffrey Tan #include "lldb/Target/SectionLoadList.h" 1646c2e4c4SJeffrey Tan #include "lldb/Target/Target.h" 1746c2e4c4SJeffrey Tan 1846c2e4c4SJeffrey Tan #include <memory> 1946c2e4c4SJeffrey Tan 2046c2e4c4SJeffrey Tan using namespace lldb; 2146c2e4c4SJeffrey Tan using namespace lldb_private; 2246c2e4c4SJeffrey Tan 2346c2e4c4SJeffrey Tan LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder) 2446c2e4c4SJeffrey Tan 2546c2e4c4SJeffrey Tan ObjectFilePlaceholder::ObjectFilePlaceholder( 2646c2e4c4SJeffrey Tan const lldb::ModuleSP &module_sp, 2746c2e4c4SJeffrey Tan const lldb_private::ModuleSpec &module_spec, lldb::addr_t base, 2846c2e4c4SJeffrey Tan lldb::addr_t size) 2946c2e4c4SJeffrey Tan : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0, 3046c2e4c4SJeffrey Tan /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0), 3146c2e4c4SJeffrey Tan m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()), 3246c2e4c4SJeffrey Tan m_base(base), m_size(size) { 3346c2e4c4SJeffrey Tan m_symtab_up = std::make_unique<lldb_private::Symtab>(this); 3446c2e4c4SJeffrey Tan } 3546c2e4c4SJeffrey Tan 3646c2e4c4SJeffrey Tan void ObjectFilePlaceholder::CreateSections( 3746c2e4c4SJeffrey Tan lldb_private::SectionList &unified_section_list) { 3846c2e4c4SJeffrey Tan m_sections_up = std::make_unique<lldb_private::SectionList>(); 3946c2e4c4SJeffrey Tan auto section_sp = std::make_shared<lldb_private::Section>( 4046c2e4c4SJeffrey Tan GetModule(), this, /*sect_id*/ 0, 4146c2e4c4SJeffrey Tan lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base, 4246c2e4c4SJeffrey Tan m_size, /*file_offset*/ 0, /*file_size*/ 0, 4346c2e4c4SJeffrey Tan /*log2align*/ 0, /*flags*/ 0); 4446c2e4c4SJeffrey Tan section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable); 4546c2e4c4SJeffrey Tan m_sections_up->AddSection(section_sp); 4646c2e4c4SJeffrey Tan unified_section_list.AddSection(std::move(section_sp)); 4746c2e4c4SJeffrey Tan } 4846c2e4c4SJeffrey Tan 4946c2e4c4SJeffrey Tan lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() { 5046c2e4c4SJeffrey Tan return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0); 5146c2e4c4SJeffrey Tan } 5246c2e4c4SJeffrey Tan 5346c2e4c4SJeffrey Tan bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value, 5446c2e4c4SJeffrey Tan bool value_is_offset) { 5546c2e4c4SJeffrey Tan assert(!value_is_offset); 5646c2e4c4SJeffrey Tan assert(value == m_base); 5746c2e4c4SJeffrey Tan 5846c2e4c4SJeffrey Tan // Create sections if they haven't been created already. 5946c2e4c4SJeffrey Tan GetModule()->GetSectionList(); 6046c2e4c4SJeffrey Tan assert(m_sections_up->GetNumSections(0) == 1); 6146c2e4c4SJeffrey Tan 62*c4fb7180SGreg Clayton target.SetSectionLoadAddress(m_sections_up->GetSectionAtIndex(0), m_base); 6346c2e4c4SJeffrey Tan return true; 6446c2e4c4SJeffrey Tan } 6546c2e4c4SJeffrey Tan 6646c2e4c4SJeffrey Tan void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) { 6746c2e4c4SJeffrey Tan s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n", 6846c2e4c4SJeffrey Tan GetFileSpec(), m_base, m_base + m_size); 6946c2e4c4SJeffrey Tan } 70