/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
Line | Count | Source (jump to first uncovered line) |
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 | | #include <optional> |
15 | | |
16 | | namespace lldb_private { |
17 | | namespace wasm { |
18 | | |
19 | | /// Generic Wasm object file reader. |
20 | | /// |
21 | | /// This class provides a generic wasm32 reader plugin implementing the |
22 | | /// ObjectFile protocol. |
23 | | class ObjectFileWasm : public ObjectFile { |
24 | | public: |
25 | | static void Initialize(); |
26 | | static void Terminate(); |
27 | | |
28 | 3.93k | static llvm::StringRef GetPluginNameStatic() { return "wasm"; } |
29 | 3.92k | static const char *GetPluginDescriptionStatic() { |
30 | 3.92k | return "WebAssembly object file reader."; |
31 | 3.92k | } |
32 | | |
33 | | static ObjectFile * |
34 | | CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, |
35 | | lldb::offset_t data_offset, const FileSpec *file, |
36 | | lldb::offset_t file_offset, lldb::offset_t length); |
37 | | |
38 | | static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp, |
39 | | lldb::WritableDataBufferSP data_sp, |
40 | | const lldb::ProcessSP &process_sp, |
41 | | lldb::addr_t header_addr); |
42 | | |
43 | | static size_t GetModuleSpecifications(const FileSpec &file, |
44 | | lldb::DataBufferSP &data_sp, |
45 | | lldb::offset_t data_offset, |
46 | | lldb::offset_t file_offset, |
47 | | lldb::offset_t length, |
48 | | ModuleSpecList &specs); |
49 | | |
50 | | /// PluginInterface protocol. |
51 | | /// \{ |
52 | 4 | llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } |
53 | | /// \} |
54 | | |
55 | | /// LLVM RTTI support |
56 | | /// \{ |
57 | | static char ID; |
58 | 37 | bool isA(const void *ClassID) const override { |
59 | 37 | return ClassID == &ID || ObjectFile::isA(ClassID)30 ; |
60 | 37 | } |
61 | 5.11k | static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } |
62 | | /// \} |
63 | | |
64 | | /// ObjectFile Protocol. |
65 | | /// \{ |
66 | | bool ParseHeader() override; |
67 | | |
68 | 61 | lldb::ByteOrder GetByteOrder() const override { |
69 | 61 | return m_arch.GetByteOrder(); |
70 | 61 | } |
71 | | |
72 | 27 | bool IsExecutable() const override { return false; } |
73 | | |
74 | 43 | uint32_t GetAddressByteSize() const override { |
75 | 43 | return m_arch.GetAddressByteSize(); |
76 | 43 | } |
77 | | |
78 | 0 | AddressClass GetAddressClass(lldb::addr_t file_addr) override { |
79 | 0 | return AddressClass::eInvalid; |
80 | 0 | } |
81 | | |
82 | | void ParseSymtab(lldb_private::Symtab &symtab) override; |
83 | | |
84 | 5 | bool IsStripped() override { return !!GetExternalDebugInfoFileSpec(); } |
85 | | |
86 | | void CreateSections(SectionList &unified_section_list) override; |
87 | | |
88 | | void Dump(Stream *s) override; |
89 | | |
90 | 16 | ArchSpec GetArchitecture() override { return m_arch; } |
91 | | |
92 | 7 | UUID GetUUID() override { return m_uuid; } |
93 | | |
94 | 0 | uint32_t GetDependentModules(FileSpecList &files) override { return 0; } |
95 | | |
96 | 13 | Type CalculateType() override { return eTypeSharedLibrary; } |
97 | | |
98 | 7 | Strata CalculateStrata() override { return eStrataUser; } |
99 | | |
100 | | bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, |
101 | | bool value_is_offset) override; |
102 | | |
103 | 4 | lldb_private::Address GetBaseAddress() override { |
104 | 4 | return IsInMemory() ? Address(m_memory_addr)0 : Address(0); |
105 | 4 | } |
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 | | |
114 | | private: |
115 | | ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, |
116 | | lldb::offset_t data_offset, const FileSpec *file, |
117 | | lldb::offset_t offset, lldb::offset_t length); |
118 | | ObjectFileWasm(const lldb::ModuleSP &module_sp, |
119 | | lldb::WritableDataBufferSP header_data_sp, |
120 | | const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); |
121 | | |
122 | | /// Wasm section decoding routines. |
123 | | /// \{ |
124 | | bool DecodeNextSection(lldb::offset_t *offset_ptr); |
125 | | bool DecodeSections(); |
126 | | /// \} |
127 | | |
128 | | /// Read a range of bytes from the Wasm module. |
129 | | DataExtractor ReadImageData(lldb::offset_t offset, uint32_t size); |
130 | | |
131 | | typedef struct section_info { |
132 | | lldb::offset_t offset; |
133 | | uint32_t size; |
134 | | uint32_t id; |
135 | | ConstString name; |
136 | | } section_info_t; |
137 | | |
138 | | /// Wasm section header dump routines. |
139 | | /// \{ |
140 | | void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info_t &sh); |
141 | | void DumpSectionHeaders(llvm::raw_ostream &ostream); |
142 | | /// \} |
143 | | |
144 | | std::vector<section_info_t> m_sect_infos; |
145 | | ArchSpec m_arch; |
146 | | UUID m_uuid; |
147 | | }; |
148 | | |
149 | | } // namespace wasm |
150 | | } // namespace lldb_private |
151 | | #endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H |