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
14#include <optional>
15
16namespace lldb_private {
17namespace wasm {
18
19/// Generic Wasm object file reader.
20///
21/// This class provides a generic wasm32 reader plugin implementing the
22/// ObjectFile protocol.
23class ObjectFileWasm : public ObjectFile {
24public:
25 static void Initialize();
26 static void Terminate();
27
28 static llvm::StringRef GetPluginNameStatic() { return "wasm"; }
29 static const char *GetPluginDescriptionStatic() {
30 return "WebAssembly object file reader.";
31 }
32
33 static ObjectFile *CreateInstance(const lldb::ModuleSP &module_sp,
34 lldb::DataExtractorSP extractor_sp,
35 lldb::offset_t data_offset,
36 const FileSpec *file,
37 lldb::offset_t file_offset,
38 lldb::offset_t length);
39
40 static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,
42 const lldb::ProcessSP &process_sp,
43 lldb::addr_t header_addr);
44
45 static ModuleSpecList
47 lldb::DataExtractorSP &extractor_sp,
48 lldb::offset_t file_offset, lldb::offset_t length);
49
50 /// PluginInterface protocol.
51 /// \{
52 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
53 /// \}
54
55 /// LLVM RTTI support
56 /// \{
57 static char ID;
58 bool isA(const void *ClassID) const override {
59 return ClassID == &ID || ObjectFile::isA(ClassID);
60 }
61 static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
62 /// \}
63
64 /// ObjectFile Protocol.
65 /// \{
66 bool ParseHeader() override;
67
68 lldb::ByteOrder GetByteOrder() const override {
69 return m_arch.GetByteOrder();
70 }
71
72 bool IsExecutable() const override { return false; }
73
74 uint32_t GetAddressByteSize() const override {
75 return m_arch.GetAddressByteSize();
76 }
77
80 }
81
82 void ParseSymtab(lldb_private::Symtab &symtab) override;
83
84 bool IsStripped() override { return !!GetExternalDebugInfoFileSpec(); }
85
86 void CreateSections(SectionList &unified_section_list) override;
87
88 void Dump(Stream *s) override;
89
90 ArchSpec GetArchitecture() override { return m_arch; }
91
92 UUID GetUUID() override { return m_uuid; }
93
94 uint32_t GetDependentModules(FileSpecList &files) override { return 0; }
95
96 Type CalculateType() override { return eTypeSharedLibrary; }
97
98 Strata CalculateStrata() override { return eStrataUser; }
99
101 bool value_is_offset) override;
102
106 /// \}
107
108 /// A Wasm module that has external DWARF debug information should contain a
109 /// custom section named "external_debug_info", whose payload is an UTF-8
110 /// encoded string that points to a Wasm module that contains the debug
111 /// information for this module.
112 std::optional<FileSpec> GetExternalDebugInfoFileSpec();
113
114private:
115 ObjectFileWasm(const lldb::ModuleSP &module_sp,
116 lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset,
117 const FileSpec *file, lldb::offset_t offset,
118 lldb::offset_t length);
119 ObjectFileWasm(const lldb::ModuleSP &module_sp,
120 lldb::WritableDataBufferSP header_data_sp,
121 const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
122
123 /// Wasm section decoding routines.
124 /// \{
125 bool DecodeNextSection(lldb::offset_t *offset_ptr);
126 bool DecodeSections();
127 /// \}
128
129 /// Read a range of bytes from the Wasm module.
130 DataExtractor ReadImageData(lldb::offset_t offset, uint32_t size);
131
134 uint32_t size;
135 uint32_t id;
137 lldb::offset_t GetFileOffset() const { return offset & 0xffffffff; }
138 };
139
140 std::optional<section_info> GetSectionInfo(uint32_t section_id);
141 std::optional<section_info> GetSectionInfo(llvm::StringRef section_name);
142
143 /// Wasm section header dump routines.
144 /// \{
145 void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info &sh);
146 void DumpSectionHeaders(llvm::raw_ostream &ostream);
147 /// \}
148
149 std::vector<section_info> m_sect_infos;
151 std::vector<Symbol> m_symbols;
154};
155
156} // namespace wasm
157} // namespace lldb_private
158#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H
A section + offset based address class.
Definition Address.h:62
An architecture specification class.
Definition ArchSpec.h:32
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
A file collection class.
A file utility class.
Definition FileSpec.h:57
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
Definition ObjectFile.h:773
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:63
virtual bool isA(const void *ClassID) const
Definition ObjectFile.h:216
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition ObjectFile.h:685
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Represents UUID's of various sizes.
Definition UUID.h:27
ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
std::optional< FileSpec > GetExternalDebugInfoFileSpec()
A Wasm module that has external DWARF debug information should contain a custom section named "extern...
static bool classof(const ObjectFile *obj)
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...
bool DecodeNextSection(lldb::offset_t *offset_ptr)
Wasm section decoding routines.
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
void CreateSections(SectionList &unified_section_list) override
ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
std::optional< section_info > GetSectionInfo(uint32_t section_id)
void Dump(Stream *s) override
Dump a description of this object to a Stream.
static llvm::StringRef GetPluginNameStatic()
std::vector< section_info > m_sect_infos
void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info &sh)
Wasm section header dump routines.
void DumpSectionHeaders(llvm::raw_ostream &ostream)
static ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
static char ID
LLVM RTTI support.
void ParseSymtab(lldb_private::Symtab &symtab) override
Parse the symbol table into the provides symbol table object.
uint32_t GetDependentModules(FileSpecList &files) override
Extract the dependent modules from an object file.
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::DataExtractorSP &extractor_sp, lldb::offset_t file_offset, lldb::offset_t length)
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
UUID GetUUID() override
Gets the UUID for this object file.
static ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
bool ParseHeader() override
ObjectFile Protocol.
Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
bool isA(const void *ClassID) const override
Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
llvm::StringRef GetPluginName() override
PluginInterface protocol.
static const char * GetPluginDescriptionStatic()
DataExtractor ReadImageData(lldb::offset_t offset, uint32_t size)
Read a range of bytes from the Wasm module.
A class that represents a running process on the host machine.
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP