aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp
blob: e8745d6dd6b83c5d44527b46180150f2f2773886 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===-- ObjectFilePlaceholder.cpp----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "ObjectFilePlaceholder.h"

#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Section.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"

#include <memory>

using namespace lldb;
using namespace lldb_private;

LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)

ObjectFilePlaceholder::ObjectFilePlaceholder(
    const lldb::ModuleSP &module_sp,
    const lldb_private::ModuleSpec &module_spec, lldb::addr_t base,
    lldb::addr_t size)
    : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,
                 /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),
      m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),
      m_base(base), m_size(size) {
  m_symtab_up = std::make_unique<lldb_private::Symtab>(this);
}

void ObjectFilePlaceholder::CreateSections(
    lldb_private::SectionList &unified_section_list) {
  m_sections_up = std::make_unique<lldb_private::SectionList>();
  auto section_sp = std::make_shared<lldb_private::Section>(
      GetModule(), this, /*sect_id*/ 0,
      lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base,
      m_size, /*file_offset*/ 0, /*file_size*/ 0,
      /*log2align*/ 0, /*flags*/ 0);
  section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable);
  m_sections_up->AddSection(section_sp);
  unified_section_list.AddSection(std::move(section_sp));
}

lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() {
  return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0);
}

bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value,
                                           bool value_is_offset) {
  assert(!value_is_offset);
  assert(value == m_base);

  // Create sections if they haven't been created already.
  GetModule()->GetSectionList();
  assert(m_sections_up->GetNumSections(0) == 1);

  target.SetSectionLoadAddress(m_sections_up->GetSectionAtIndex(0), m_base);
  return true;
}

void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) {
  s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n",
            GetFileSpec(), m_base, m_base + m_size);
}