Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
39642 views
//===-- ObjectFileWasm.h ----------------------------------------*- C++ -*-===//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#ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H9#define LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H1011#include "lldb/Symbol/ObjectFile.h"12#include "lldb/Utility/ArchSpec.h"13#include <optional>1415namespace lldb_private {16namespace wasm {1718/// Generic Wasm object file reader.19///20/// This class provides a generic wasm32 reader plugin implementing the21/// ObjectFile protocol.22class ObjectFileWasm : public ObjectFile {23public:24static void Initialize();25static void Terminate();2627static llvm::StringRef GetPluginNameStatic() { return "wasm"; }28static const char *GetPluginDescriptionStatic() {29return "WebAssembly object file reader.";30}3132static ObjectFile *33CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,34lldb::offset_t data_offset, const FileSpec *file,35lldb::offset_t file_offset, lldb::offset_t length);3637static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,38lldb::WritableDataBufferSP data_sp,39const lldb::ProcessSP &process_sp,40lldb::addr_t header_addr);4142static size_t GetModuleSpecifications(const FileSpec &file,43lldb::DataBufferSP &data_sp,44lldb::offset_t data_offset,45lldb::offset_t file_offset,46lldb::offset_t length,47ModuleSpecList &specs);4849/// PluginInterface protocol.50/// \{51llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }52/// \}5354/// LLVM RTTI support55/// \{56static char ID;57bool isA(const void *ClassID) const override {58return ClassID == &ID || ObjectFile::isA(ClassID);59}60static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }61/// \}6263/// ObjectFile Protocol.64/// \{65bool ParseHeader() override;6667lldb::ByteOrder GetByteOrder() const override {68return m_arch.GetByteOrder();69}7071bool IsExecutable() const override { return false; }7273uint32_t GetAddressByteSize() const override {74return m_arch.GetAddressByteSize();75}7677AddressClass GetAddressClass(lldb::addr_t file_addr) override {78return AddressClass::eInvalid;79}8081void ParseSymtab(lldb_private::Symtab &symtab) override;8283bool IsStripped() override { return !!GetExternalDebugInfoFileSpec(); }8485void CreateSections(SectionList &unified_section_list) override;8687void Dump(Stream *s) override;8889ArchSpec GetArchitecture() override { return m_arch; }9091UUID GetUUID() override { return m_uuid; }9293uint32_t GetDependentModules(FileSpecList &files) override { return 0; }9495Type CalculateType() override { return eTypeSharedLibrary; }9697Strata CalculateStrata() override { return eStrataUser; }9899bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,100bool value_is_offset) override;101102lldb_private::Address GetBaseAddress() override {103return IsInMemory() ? Address(m_memory_addr) : Address(0);104}105/// \}106107/// A Wasm module that has external DWARF debug information should contain a108/// custom section named "external_debug_info", whose payload is an UTF-8109/// encoded string that points to a Wasm module that contains the debug110/// information for this module.111std::optional<FileSpec> GetExternalDebugInfoFileSpec();112113private:114ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,115lldb::offset_t data_offset, const FileSpec *file,116lldb::offset_t offset, lldb::offset_t length);117ObjectFileWasm(const lldb::ModuleSP &module_sp,118lldb::WritableDataBufferSP header_data_sp,119const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);120121/// Wasm section decoding routines.122/// \{123bool DecodeNextSection(lldb::offset_t *offset_ptr);124bool DecodeSections();125/// \}126127/// Read a range of bytes from the Wasm module.128DataExtractor ReadImageData(lldb::offset_t offset, uint32_t size);129130typedef struct section_info {131lldb::offset_t offset;132uint32_t size;133uint32_t id;134ConstString name;135} section_info_t;136137/// Wasm section header dump routines.138/// \{139void DumpSectionHeader(llvm::raw_ostream &ostream, const section_info_t &sh);140void DumpSectionHeaders(llvm::raw_ostream &ostream);141/// \}142143std::vector<section_info_t> m_sect_infos;144ArchSpec m_arch;145UUID m_uuid;146};147148} // namespace wasm149} // namespace lldb_private150#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_WASM_OBJECTFILEWASM_H151152153