1*fe013be4SDimitry Andric //===-- ObjectFilePlaceholder.cpp----------------------------------------===//
2*fe013be4SDimitry Andric //
3*fe013be4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*fe013be4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*fe013be4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*fe013be4SDimitry Andric //
7*fe013be4SDimitry Andric //===----------------------------------------------------------------------===//
8*fe013be4SDimitry Andric
9*fe013be4SDimitry Andric #include "ObjectFilePlaceholder.h"
10*fe013be4SDimitry Andric
11*fe013be4SDimitry Andric #include "lldb/Core/Module.h"
12*fe013be4SDimitry Andric #include "lldb/Core/ModuleSpec.h"
13*fe013be4SDimitry Andric #include "lldb/Core/PluginManager.h"
14*fe013be4SDimitry Andric #include "lldb/Core/Section.h"
15*fe013be4SDimitry Andric #include "lldb/Target/SectionLoadList.h"
16*fe013be4SDimitry Andric #include "lldb/Target/Target.h"
17*fe013be4SDimitry Andric
18*fe013be4SDimitry Andric #include <memory>
19*fe013be4SDimitry Andric
20*fe013be4SDimitry Andric using namespace lldb;
21*fe013be4SDimitry Andric using namespace lldb_private;
22*fe013be4SDimitry Andric
LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)23*fe013be4SDimitry Andric LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)
24*fe013be4SDimitry Andric
25*fe013be4SDimitry Andric ObjectFilePlaceholder::ObjectFilePlaceholder(
26*fe013be4SDimitry Andric const lldb::ModuleSP &module_sp,
27*fe013be4SDimitry Andric const lldb_private::ModuleSpec &module_spec, lldb::addr_t base,
28*fe013be4SDimitry Andric lldb::addr_t size)
29*fe013be4SDimitry Andric : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,
30*fe013be4SDimitry Andric /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),
31*fe013be4SDimitry Andric m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),
32*fe013be4SDimitry Andric m_base(base), m_size(size) {
33*fe013be4SDimitry Andric m_symtab_up = std::make_unique<lldb_private::Symtab>(this);
34*fe013be4SDimitry Andric }
35*fe013be4SDimitry Andric
CreateSections(lldb_private::SectionList & unified_section_list)36*fe013be4SDimitry Andric void ObjectFilePlaceholder::CreateSections(
37*fe013be4SDimitry Andric lldb_private::SectionList &unified_section_list) {
38*fe013be4SDimitry Andric m_sections_up = std::make_unique<lldb_private::SectionList>();
39*fe013be4SDimitry Andric auto section_sp = std::make_shared<lldb_private::Section>(
40*fe013be4SDimitry Andric GetModule(), this, /*sect_id*/ 0,
41*fe013be4SDimitry Andric lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base,
42*fe013be4SDimitry Andric m_size, /*file_offset*/ 0, /*file_size*/ 0,
43*fe013be4SDimitry Andric /*log2align*/ 0, /*flags*/ 0);
44*fe013be4SDimitry Andric section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable);
45*fe013be4SDimitry Andric m_sections_up->AddSection(section_sp);
46*fe013be4SDimitry Andric unified_section_list.AddSection(std::move(section_sp));
47*fe013be4SDimitry Andric }
48*fe013be4SDimitry Andric
GetBaseAddress()49*fe013be4SDimitry Andric lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() {
50*fe013be4SDimitry Andric return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0);
51*fe013be4SDimitry Andric }
52*fe013be4SDimitry Andric
SetLoadAddress(Target & target,addr_t value,bool value_is_offset)53*fe013be4SDimitry Andric bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value,
54*fe013be4SDimitry Andric bool value_is_offset) {
55*fe013be4SDimitry Andric assert(!value_is_offset);
56*fe013be4SDimitry Andric assert(value == m_base);
57*fe013be4SDimitry Andric
58*fe013be4SDimitry Andric // Create sections if they haven't been created already.
59*fe013be4SDimitry Andric GetModule()->GetSectionList();
60*fe013be4SDimitry Andric assert(m_sections_up->GetNumSections(0) == 1);
61*fe013be4SDimitry Andric
62*fe013be4SDimitry Andric target.GetSectionLoadList().SetSectionLoadAddress(
63*fe013be4SDimitry Andric m_sections_up->GetSectionAtIndex(0), m_base);
64*fe013be4SDimitry Andric return true;
65*fe013be4SDimitry Andric }
66*fe013be4SDimitry Andric
Dump(lldb_private::Stream * s)67*fe013be4SDimitry Andric void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) {
68*fe013be4SDimitry Andric s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n",
69*fe013be4SDimitry Andric GetFileSpec(), m_base, m_base + m_size);
70*fe013be4SDimitry Andric }
71