Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ObjectFile/Placeholder/ObjectFilePlaceholder.cpp
39644 views
//===-- ObjectFilePlaceholder.cpp----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "ObjectFilePlaceholder.h"910#include "lldb/Core/Module.h"11#include "lldb/Core/ModuleSpec.h"12#include "lldb/Core/PluginManager.h"13#include "lldb/Core/Section.h"14#include "lldb/Target/SectionLoadList.h"15#include "lldb/Target/Target.h"1617#include <memory>1819using namespace lldb;20using namespace lldb_private;2122LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder)2324ObjectFilePlaceholder::ObjectFilePlaceholder(25const lldb::ModuleSP &module_sp,26const lldb_private::ModuleSpec &module_spec, lldb::addr_t base,27lldb::addr_t size)28: ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,29/*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),30m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),31m_base(base), m_size(size) {32m_symtab_up = std::make_unique<lldb_private::Symtab>(this);33}3435void ObjectFilePlaceholder::CreateSections(36lldb_private::SectionList &unified_section_list) {37m_sections_up = std::make_unique<lldb_private::SectionList>();38auto section_sp = std::make_shared<lldb_private::Section>(39GetModule(), this, /*sect_id*/ 0,40lldb_private::ConstString(".module_image"), eSectionTypeOther, m_base,41m_size, /*file_offset*/ 0, /*file_size*/ 0,42/*log2align*/ 0, /*flags*/ 0);43section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable);44m_sections_up->AddSection(section_sp);45unified_section_list.AddSection(std::move(section_sp));46}4748lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() {49return lldb_private::Address(m_sections_up->GetSectionAtIndex(0), 0);50}5152bool ObjectFilePlaceholder::SetLoadAddress(Target &target, addr_t value,53bool value_is_offset) {54assert(!value_is_offset);55assert(value == m_base);5657// Create sections if they haven't been created already.58GetModule()->GetSectionList();59assert(m_sections_up->GetNumSections(0) == 1);6061target.GetSectionLoadList().SetSectionLoadAddress(62m_sections_up->GetSectionAtIndex(0), m_base);63return true;64}6566void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) {67s->Format("Placeholder object file for {0} loaded at [{1:x}-{2:x})\n",68GetFileSpec(), m_base, m_base + m_size);69}707172