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-exception |
6 | // |
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 | |
20 | using namespace lldb; |
21 | using namespace lldb_private; |
22 | |
23 | LLDB_PLUGIN_DEFINE(ObjectFilePlaceholder) |
24 | |
25 | ObjectFilePlaceholder::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>(args: this); |
34 | } |
35 | |
36 | void 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 | args: GetModule(), args: this, /*sect_id*/ args: 0, |
41 | args: lldb_private::ConstString(".module_image" ), args: eSectionTypeOther, args&: m_base, |
42 | args&: m_size, /*file_offset*/ args: 0, /*file_size*/ args: 0, |
43 | /*log2align*/ args: 0, /*flags*/ args: 0); |
44 | section_sp->SetPermissions(ePermissionsReadable | ePermissionsExecutable); |
45 | m_sections_up->AddSection(section_sp); |
46 | unified_section_list.AddSection(section_sp: std::move(section_sp)); |
47 | } |
48 | |
49 | lldb_private::Address ObjectFilePlaceholder::GetBaseAddress() { |
50 | return lldb_private::Address(m_sections_up->GetSectionAtIndex(idx: 0), 0); |
51 | } |
52 | |
53 | bool 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.GetSectionLoadList().SetSectionLoadAddress( |
63 | section_sp: m_sections_up->GetSectionAtIndex(idx: 0), load_addr: m_base); |
64 | return true; |
65 | } |
66 | |
67 | void ObjectFilePlaceholder::Dump(lldb_private::Stream *s) { |
68 | s->Format(format: "Placeholder object file for {0} loaded at [{1:x}-{2:x})\n" , |
69 | args&: GetFileSpec(), args&: m_base, args: m_base + m_size); |
70 | } |
71 | |