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