LLDB  mainline
ObjectFileWasm.h
Go to the documentation of this file.
1 //===-- ObjectFileWasm.h ----------------------------------------*- C++ -*-===//
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 #ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H
10 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H
11 
12 #include "lldb/Symbol/ObjectFile.h"
13 #include "lldb/Utility/ArchSpec.h"
14 
15 namespace lldb_private {
16 namespace wasm {
17 
18 /// Generic Wasm object file reader.
19 ///
20 /// This class provides a generic wasm32 reader plugin implementing the
21 /// ObjectFile protocol.
22 class ObjectFileWasm : public ObjectFile {
23 public:
24  static void Initialize();
25  static void Terminate();
26 
27  static llvm::StringRef GetPluginNameStatic() { return "wasm"; }
28  static const char *GetPluginDescriptionStatic() {
29  return "WebAssembly object file reader.";
30  }
31 
32  static ObjectFile *
33  CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
34  lldb::offset_t data_offset, const FileSpec *file,
35  lldb::offset_t file_offset, lldb::offset_t length);
36 
37  static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,
38  lldb::DataBufferSP &data_sp,
39  const lldb::ProcessSP &process_sp,
40  lldb::addr_t header_addr);
41 
42  static size_t GetModuleSpecifications(const FileSpec &file,
43  lldb::DataBufferSP &data_sp,
44  lldb::offset_t data_offset,
45  lldb::offset_t file_offset,
46  lldb::offset_t length,
47  ModuleSpecList &specs);
48 
49  /// PluginInterface protocol.
50  /// \{
51  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
52  /// \}
53 
54  /// LLVM RTTI support
55  /// \{
56  static char ID;
57  bool isA(const void *ClassID) const override {
58  return ClassID == &ID || ObjectFile::isA(ClassID);
59  }
60  static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
61  /// \}
62 
63  /// ObjectFile Protocol.
64  /// \{
65  bool ParseHeader() override;
66 
67  lldb::ByteOrder GetByteOrder() const override {
68  return m_arch.GetByteOrder();
69  }
70 
71  bool IsExecutable() const override { return false; }
72 
73  uint32_t GetAddressByteSize() const override {
74  return m_arch.GetAddressByteSize();
75  }
76 
79  }
80 
81  Symtab *GetSymtab() override;
82 
83  bool IsStripped() override { return !!GetExternalDebugInfoFileSpec(); }
84 
85  void CreateSections(SectionList &unified_section_list) override;
86 
87  void Dump(Stream *s) override;
88 
89  ArchSpec GetArchitecture() override { return m_arch; }
90 
91  UUID GetUUID() override { return m_uuid; }
92 
93  uint32_t GetDependentModules(FileSpecList &files) override { return 0; }
94 
95  Type CalculateType() override { return eTypeSharedLibrary; }
96 
97  Strata CalculateStrata() override { return eStrataUser; }
98 
100  bool value_is_offset) override;
101 
103  return IsInMemory() ? Address(m_memory_addr) : Address(0);
104  }
105  /// \}
106 
107  /// A Wasm module that has external DWARF debug information should contain a
108  /// custom section named "external_debug_info", whose payload is an UTF-8
109  /// encoded string that points to a Wasm module that contains the debug
110  /// information for this module.
111  llvm::Optional<FileSpec> GetExternalDebugInfoFileSpec();
112 
113 private:
114  ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
115  lldb::offset_t data_offset, const FileSpec *file,
116  lldb::offset_t offset, lldb::offset_t length);
117  ObjectFileWasm(const lldb::ModuleSP &module_sp,
118  lldb::DataBufferSP &header_data_sp,
119  const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
120 
121  /// Wasm section decoding routines.
122  /// \{
123  bool DecodeNextSection(lldb::offset_t *offset_ptr);
124  bool DecodeSections();
125  /// \}
126 
127  /// Read a range of bytes from the Wasm module.
129 
130  typedef struct section_info {
135  } section_info_t;
136 
137  /// Wasm section header dump routines.
138  /// \{
139  void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info_t &sh);
140  void DumpSectionHeaders(llvm::raw_ostream &ostream);
141  /// \}
142 
143  std::vector<section_info_t> m_sect_infos;
146 };
147 
148 } // namespace wasm
149 } // namespace lldb_private
150 #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H
lldb_private::ObjectFile::isA
virtual bool isA(const void *ClassID) const
Definition: ObjectFile.h:226
lldb_private::UUID
Definition: UUID.h:23
lldb_private::wasm::ObjectFileWasm::section_info::size
uint32_t size
Definition: ObjectFileWasm.h:132
lldb_private::wasm::ObjectFileWasm::DecodeNextSection
bool DecodeNextSection(lldb::offset_t *offset_ptr)
Wasm section decoding routines.
Definition: ObjectFileWasm.cpp:157
lldb_private::ArchSpec::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:730
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ObjectFile::m_memory_addr
const lldb::addr_t m_memory_addr
Definition: ObjectFile.h:708
lldb_private::wasm::ObjectFileWasm::GetModuleSpecifications
static size_t GetModuleSpecifications(const FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, ModuleSpecList &specs)
Definition: ObjectFileWasm.cpp:217
lldb_private::wasm::ObjectFileWasm::CalculateStrata
Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
Definition: ObjectFileWasm.h:97
lldb_private::wasm::ObjectFileWasm::GetUUID
UUID GetUUID() override
Gets the UUID for this object file.
Definition: ObjectFileWasm.h:91
lldb_private::AddressClass
AddressClass
Definition: lldb-private-enumerations.h:48
lldb_private::wasm::ObjectFileWasm::GetAddressClass
AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
Definition: ObjectFileWasm.h:77
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:280
lldb_private::wasm::ObjectFileWasm::ID
static char ID
LLVM RTTI support.
Definition: ObjectFileWasm.h:56
lldb_private::wasm::ObjectFileWasm::GetBaseAddress
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
Definition: ObjectFileWasm.h:102
lldb_private::SectionList
Definition: Section.h:34
lldb_private::wasm::ObjectFileWasm::GetArchitecture
ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
Definition: ObjectFileWasm.h:89
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::wasm::ObjectFileWasm::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: ObjectFileWasm.h:28
lldb_private::ObjectFile::Type
Type
Definition: ObjectFile.h:64
lldb_private::wasm::ObjectFileWasm::CreateInstance
static ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
Definition: ObjectFileWasm.cpp:90
lldb_private::Target
Definition: Target.h:451
lldb_private::wasm::ObjectFileWasm
Generic Wasm object file reader.
Definition: ObjectFileWasm.h:22
lldb_private::AddressClass::eInvalid
@ eInvalid
lldb_private::wasm::ObjectFileWasm::IsStripped
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
Definition: ObjectFileWasm.h:83
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::wasm::ObjectFileWasm::m_uuid
UUID m_uuid
Definition: ObjectFileWasm.h:145
lldb_private::wasm::ObjectFileWasm::GetDependentModules
uint32_t GetDependentModules(FileSpecList &files) override
Extract the dependent modules from an object file.
Definition: ObjectFileWasm.h:93
lldb_private::wasm::ObjectFileWasm::ReadImageData
DataExtractor ReadImageData(lldb::offset_t offset, uint32_t size)
Read a range of bytes from the Wasm module.
Definition: ObjectFileWasm.cpp:388
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ObjectFile::eStrataUser
@ eStrataUser
Definition: ObjectFile.h:88
lldb_private::wasm::ObjectFileWasm::section_info::name
ConstString name
Definition: ObjectFileWasm.h:134
lldb_private::wasm::ObjectFileWasm::section_info
Definition: ObjectFileWasm.h:130
lldb_private::wasm::ObjectFileWasm::section_info::id
uint32_t id
Definition: ObjectFileWasm.h:133
lldb_private::wasm::ObjectFileWasm::section_info::offset
lldb::offset_t offset
Definition: ObjectFileWasm.h:131
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::wasm::ObjectFileWasm::GetAddressByteSize
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
Definition: ObjectFileWasm.h:73
lldb_private::wasm::ObjectFileWasm::CalculateType
Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
Definition: ObjectFileWasm.h:95
lldb_private::wasm::ObjectFileWasm::classof
static bool classof(const ObjectFile *obj)
Definition: ObjectFileWasm.h:60
lldb_private::ObjectFile::eTypeSharedLibrary
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition: ObjectFile.h:77
lldb_private::wasm::ObjectFileWasm::section_info_t
struct lldb_private::wasm::ObjectFileWasm::section_info section_info_t
lldb_private::wasm::ObjectFileWasm::ObjectFileWasm
ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
lldb_private::wasm::ObjectFileWasm::ParseHeader
bool ParseHeader() override
ObjectFile Protocol.
Definition: ObjectFileWasm.cpp:244
lldb_private::ArchSpec::GetAddressByteSize
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:683
ObjectFile.h
lldb_private::wasm::ObjectFileWasm::IsExecutable
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
Definition: ObjectFileWasm.h:71
lldb_private::wasm::ObjectFileWasm::m_arch
ArchSpec m_arch
Definition: ObjectFileWasm.h:144
lldb_private::wasm::ObjectFileWasm::GetPluginName
llvm::StringRef GetPluginName() override
PluginInterface protocol.
Definition: ObjectFileWasm.h:51
lldb_private::Symtab
Definition: Symtab.h:22
uint32_t
lldb_private::wasm::ObjectFileWasm::GetSymtab
Symtab * GetSymtab() override
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFileWasm.cpp:249
lldb_private::wasm::ObjectFileWasm::m_sect_infos
std::vector< section_info_t > m_sect_infos
Definition: ObjectFileWasm.h:143
lldb_private::wasm::ObjectFileWasm::Initialize
static void Initialize()
Definition: ObjectFileWasm.cpp:79
lldb_private::Address
Definition: Address.h:59
lldb_private::wasm::ObjectFileWasm::SetLoadAddress
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset) override
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
Definition: ObjectFileWasm.cpp:344
lldb_private::wasm::ObjectFileWasm::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ObjectFileWasm.h:27
lldb_private::wasm::ObjectFileWasm::Dump
void Dump(Stream *s) override
Dump a description of this object to a Stream.
Definition: ObjectFileWasm.cpp:432
lldb_private::wasm::ObjectFileWasm::DumpSectionHeader
void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info_t &sh)
Wasm section header dump routines.
Definition: ObjectFileWasm.cpp:457
ArchSpec.h
lldb_private::wasm::ObjectFileWasm::DumpSectionHeaders
void DumpSectionHeaders(llvm::raw_ostream &ostream)
Definition: ObjectFileWasm.cpp:465
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjectFile::IsInMemory
bool IsInMemory() const
Definition: ObjectFile.h:654
lldb_private::wasm::ObjectFileWasm::DecodeSections
bool DecodeSections()
Definition: ObjectFileWasm.cpp:206
lldb_private::ObjectFile::Strata
Strata
Definition: ObjectFile.h:85
lldb_private::wasm::ObjectFileWasm::isA
bool isA(const void *ClassID) const override
Definition: ObjectFileWasm.h:57
lldb_private::wasm::ObjectFileWasm::CreateSections
void CreateSections(SectionList &unified_section_list) override
Definition: ObjectFileWasm.cpp:288
lldb_private::wasm::ObjectFileWasm::GetExternalDebugInfoFileSpec
llvm::Optional< FileSpec > GetExternalDebugInfoFileSpec()
A Wasm module that has external DWARF debug information should contain a custom section named "extern...
Definition: ObjectFileWasm.cpp:414
lldb_private::wasm::ObjectFileWasm::GetByteOrder
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
Definition: ObjectFileWasm.h:67
lldb_private::ObjectFile
Definition: ObjectFile.h:58
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::wasm::ObjectFileWasm::Terminate
static void Terminate()
Definition: ObjectFileWasm.cpp:85
lldb_private::wasm::ObjectFileWasm::CreateMemoryInstance
static ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
Definition: ObjectFileWasm.cpp:142