17fa27ce4SDimitry Andric //===-- ObjectFilePlaceholder.cpp----------------------------------------===//
27fa27ce4SDimitry Andric //
37fa27ce4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47fa27ce4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
57fa27ce4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67fa27ce4SDimitry Andric //
77fa27ce4SDimitry Andric //===----------------------------------------------------------------------===//
87fa27ce4SDimitry Andric
97fa27ce4SDimitry Andric #include "ObjectFilePlaceholder.h"
107fa27ce4SDimitry Andric
117fa27ce4SDimitry Andric #include "lldb/Core/Module.h"
127fa27ce4SDimitry Andric #include "lldb/Core/ModuleSpec.h"
137fa27ce4SDimitry Andric #include "lldb/Core/PluginManager.h"
147fa27ce4SDimitry Andric #include "lldb/Core/Section.h"
157fa27ce4SDimitry Andric #include "lldb/Target/SectionLoadList.h"
167fa27ce4SDimitry Andric #include "lldb/Target/Target.h"
177fa27ce4SDimitry Andric
187fa27ce4SDimitry Andric #include <memory>
197fa27ce4SDimitry Andric
207fa27ce4SDimitry Andric using namespace lldb;
217fa27ce4SDimitry Andric using namespace lldb_private;
227fa27ce4SDimitry Andric
LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)237fa27ce4SDimitry Andric LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)
247fa27ce4SDimitry Andric
257fa27ce4SDimitry Andric ObjectFilePlaceholder::ObjectFilePlaceholder(
267fa27ce4SDimitry Andric const lldb::ModuleSP &module_sp,
277fa27ce4SDimitry Andric const lldb_private::ModuleSpec &module_spec, lldb::addr_t base,
287fa27ce4SDimitry Andric lldb::addr_t size)
297fa27ce4SDimitry Andric : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,
307fa27ce4SDimitry Andric /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),
317fa27ce4SDimitry Andric m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),
327fa27ce4SDimitry Andric m_base(base), m_size(size) {
337fa27ce4SDimitry Andric m_symtab_up = std::make_unique<lldb_private::Symtab>(this);
347fa27ce4SDimitry Andric }
357fa27ce4SDimitry Andric
CreateSections(lldb_private::SectionList & unified_section_list)367fa27ce4SDimitry Andric void ObjectFilePlaceholder::CreateSections(
377fa27ce4SDimitry Andric lldb_private::SectionList &unified_section_list) {
387fa27ce4SDimitry Andric m_sections_up = std::make_unique<lldb_private::SectionList>();
397fa27ce4SDimitry Andric auto section_sp = std::make_shared<lldb_private::Section>(
407fa27ce4SDimitry Andric GetModule(), this, /*sect_id*/ 0,
417fa27ce4SDimitry Andric lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base,
427fa27ce4SDimitry Andric m_size, /*file_offset*/ 0, /*file_size*/ 0,
437fa27ce4SDimitry Andric /*log2align*/ 0, /*flags*/ 0);
447fa27ce4SDimitry Andric section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable);
457fa27ce4SDimitry Andric m_sections_up->AddSection(section_sp);
467fa27ce4SDimitry Andric unified_section_list.AddSection(std::move(section_sp));
477fa27ce4SDimitry Andric }
487fa27ce4SDimitry Andric
GetBaseAddress()497fa27ce4SDimitry Andric lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() {
507fa27ce4SDimitry Andric return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0);
517fa27ce4SDimitry Andric }
527fa27ce4SDimitry Andric
SetLoadAddress(Target & target,addr_t value,bool value_is_offset)537fa27ce4SDimitry Andric bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value,
547fa27ce4SDimitry Andric bool value_is_offset) {
557fa27ce4SDimitry Andric assert(!value_is_offset);
567fa27ce4SDimitry Andric assert(value == m_base);
577fa27ce4SDimitry Andric
587fa27ce4SDimitry Andric // Create sections if they haven't been created already.
597fa27ce4SDimitry Andric GetModule()->GetSectionList();
607fa27ce4SDimitry Andric assert(m_sections_up->GetNumSections(0) == 1);
617fa27ce4SDimitry Andric
627fa27ce4SDimitry Andric target.GetSectionLoadList().SetSectionLoadAddress(
637fa27ce4SDimitry Andric m_sections_up->GetSectionAtIndex(0), m_base);
647fa27ce4SDimitry Andric return true;
657fa27ce4SDimitry Andric }
667fa27ce4SDimitry Andric
Dump(lldb_private::Stream * s)677fa27ce4SDimitry Andric void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) {
687fa27ce4SDimitry Andric s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n",
697fa27ce4SDimitry Andric GetFileSpec(), m_base, m_base + m_size);
707fa27ce4SDimitry Andric }
71