|
LLDB mainline
|
#include "ObjectFileWasm.h"#include "lldb/Core/Module.h"#include "lldb/Core/ModuleSpec.h"#include "lldb/Core/PluginManager.h"#include "lldb/Core/Section.h"#include "lldb/Target/Process.h"#include "lldb/Target/SectionLoadList.h"#include "lldb/Target/Target.h"#include "lldb/Utility/DataBufferHeap.h"#include "lldb/Utility/LLDBLog.h"#include "lldb/Utility/Log.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/StringRef.h"#include "llvm/ADT/StringSwitch.h"#include "llvm/BinaryFormat/Magic.h"#include "llvm/BinaryFormat/Wasm.h"#include "llvm/Support/CheckedArithmetic.h"#include "llvm/Support/Endian.h"#include "llvm/Support/Format.h"#include <cstring>#include <optional>Go to the source code of this file.
Classes | |
| struct | WasmFunction |
| struct | WasmImports |
| The number of imports of each kind. More... | |
| struct | WasmSegment |
Functions | |
| static llvm::Expected< uint32_t > | GetULEB32 (DataExtractor &data, lldb::offset_t &offset) |
| Helper to read a 32-bit ULEB using LLDB's DataExtractor. | |
| static llvm::Expected< uint32_t > | GetULEB32 (llvm::DataExtractor &data, llvm::DataExtractor::Cursor &c) |
| Helper to read a 32-bit ULEB using LLVM's DataExtractor. | |
| static llvm::Expected< std::string > | GetWasmString (llvm::DataExtractor &data, llvm::DataExtractor::Cursor &c) |
| Helper to read a Wasm string, whcih is encoded as a vector of UTF-8 codes. | |
| static lldb::offset_t | GetWasmOffsetFromInitExpr (DataExtractor &data, lldb::offset_t &offset) |
| An "init expr" refers to a constant expression used to determine the initial value of certain elements within a module during instantiation. | |
| static bool | ValidateModuleHeader (llvm::ArrayRef< uint8_t > data) |
| Checks whether the data buffer starts with a valid Wasm module header. | |
| static llvm::Expected< WasmImports > | ParseImports (DataExtractor &import_data) |
| static llvm::Expected< uint32_t > | GetFunctionCodeOffset (DataExtractor &data, lldb::offset_t offset) |
| Get the offset in the function to the first instruction. | |
| static llvm::Expected< std::vector< WasmFunction > > | ParseFunctions (DataExtractor &data) |
| static llvm::Expected< std::vector< WasmSegment > > | ParseData (DataExtractor &data) |
| static llvm::Expected< uint64_t > | ParseMemoryMinSize (DataExtractor &data) |
| Parse the minimum size in bytes of the module's first linear memory. | |
| static std::optional< uint32_t > | GetWasmValueTypeSize (uint8_t type) |
| Size in bytes of a WebAssembly value type, or nothing for the types whose values cannot be read. | |
| static std::optional< uint64_t > | ParseGlobalInitValue (DataExtractor &data, lldb::offset_t &offset) |
| Parse the init expr that gives a global its initial value. | |
| static llvm::Expected< std::vector< WasmGlobal > > | ParseGlobals (DataExtractor &data) |
| Parse the module's own globals, which start at the number of imported ones. | |
| static llvm::Expected< std::vector< Symbol > > | ParseNames (SectionSP code_section_sp, SectionSP global_section_sp, DataExtractor &name_data, const std::vector< WasmFunction > &functions, std::vector< WasmSegment > &segments, const std::vector< WasmGlobal > &globals, uint32_t num_imported_functions, uint32_t num_imported_globals) |
| static SectionType | GetSectionTypeFromName (llvm::StringRef Name) |
| static SectionType | GetSegmentTypeFromName (llvm::StringRef Name) |
| A section attribute on a data variable lands in a named data segment on wasm, not a top-level custom section, so formatter sections appear as segment names rather than section names. | |
Variables | |
| static const uint32_t | kWasmHeaderSize |
| static constexpr lldb::addr_t | kWasmGlobalFileAddress |
| File address the synthetic global section is based at. | |
|
static |
Get the offset in the function to the first instruction.
Definition at line 405 of file ObjectFileWasm.cpp.
References lldb_private::DataExtractor::GetU8(), and lldb_private::DataExtractor::GetULEB128().
Referenced by ParseFunctions().
|
static |
Definition at line 765 of file ObjectFileWasm.cpp.
References lldb::eSectionTypeOther, lldb::eSectionTypeWasmName, and lldb_private::ObjectFile::GetDWARFSectionTypeFromName().
|
static |
A section attribute on a data variable lands in a named data segment on wasm, not a top-level custom section, so formatter sections appear as segment names rather than section names.
Definition at line 776 of file ObjectFileWasm.cpp.
References lldb::eSectionTypeData, lldb::eSectionTypeLLDBFormatters, and lldb::eSectionTypeLLDBTypeSummaries.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
inlinestatic |
Helper to read a 32-bit ULEB using LLDB's DataExtractor.
Definition at line 48 of file ObjectFileWasm.cpp.
References GetULEB32().
Referenced by GetULEB32(), GetWasmString(), ParseData(), ParseFunctions(), ParseGlobals(), ParseImports(), ParseMemoryMinSize(), and ParseNames().
|
inlinestatic |
Helper to read a 32-bit ULEB using LLVM's DataExtractor.
Definition at line 58 of file ObjectFileWasm.cpp.
|
static |
An "init expr" refers to a constant expression used to determine the initial value of certain elements within a module during instantiation.
These expressions are restricted to operations that can be evaluated at module instantiation time. Currently we only support simple constant opcodes.
Definition at line 86 of file ObjectFileWasm.cpp.
References lldb_private::DataExtractor::GetFloat(), lldb_private::DataExtractor::GetSLEB128(), lldb_private::DataExtractor::GetU8(), lldb_private::DataExtractor::GetULEB128(), LLDB_INVALID_OFFSET, and lldb_private::DataExtractor::ValidOffset().
Referenced by ParseData().
|
inlinestatic |
Helper to read a Wasm string, whcih is encoded as a vector of UTF-8 codes.
Definition at line 69 of file ObjectFileWasm.cpp.
References GetULEB32().
Referenced by lldb_private::wasm::ObjectFileWasm::DecodeNextSection(), lldb_private::wasm::ObjectFileWasm::GetExternalDebugInfoFileSpec(), ParseImports(), and ParseNames().
|
static |
Size in bytes of a WebAssembly value type, or nothing for the types whose values cannot be read.
Definition at line 552 of file ObjectFileWasm.cpp.
Referenced by ParseGlobals().
|
static |
Definition at line 474 of file ObjectFileWasm.cpp.
References WasmSegment::Active, GetULEB32(), GetWasmOffsetFromInitExpr(), WasmSegment::Passive, and segment::size.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Definition at line 421 of file ObjectFileWasm.cpp.
References GetFunctionCodeOffset(), and GetULEB32().
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Parse the init expr that gives a global its initial value.
The result is the bit pattern of the value, so an operand that has to be evaluated against module state yields nothing.
Definition at line 568 of file ObjectFileWasm.cpp.
References lldb_private::DataExtractor::GetSLEB128(), lldb_private::DataExtractor::GetU32(), lldb_private::DataExtractor::GetU64(), lldb_private::DataExtractor::GetU8(), lldb_private::DataExtractor::GetULEB128(), and lldb_private::DataExtractor::ValidOffset().
Referenced by ParseGlobals().
|
static |
Parse the module's own globals, which start at the number of imported ones.
Definition at line 606 of file ObjectFileWasm.cpp.
References lldb_private::DataExtractor::GetU8(), GetULEB32(), GetWasmValueTypeSize(), lldb_private::wasm::WasmGlobal::init_expr_value, ParseGlobalInitValue(), lldb_private::wasm::WasmGlobal::size, and lldb_private::DataExtractor::ValidOffset().
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Definition at line 339 of file ObjectFileWasm.cpp.
References WasmImports::functions, lldb_private::DataExtractor::GetAsLLVM(), GetULEB32(), GetWasmString(), and WasmImports::globals.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Parse the minimum size in bytes of the module's first linear memory.
This is the memory guaranteed to exist at instantiation, and so the upper bound of the static data region.
Definition at line 531 of file ObjectFileWasm.cpp.
References lldb_private::DataExtractor::GetU8(), and GetULEB32().
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Definition at line 632 of file ObjectFileWasm.cpp.
References WasmFunction::code_offset, lldb::eSymbolTypeCode, lldb::eSymbolTypeData, lldb_private::DataExtractor::GetAsLLVM(), GetULEB32(), GetWasmString(), WasmFunction::section_offset, and WasmFunction::size.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Checks whether the data buffer starts with a valid Wasm module header.
Definition at line 124 of file ObjectFileWasm.cpp.
References kWasmHeaderSize.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateInstance(), lldb_private::wasm::ObjectFileWasm::CreateMemoryInstance(), and lldb_private::wasm::ObjectFileWasm::GetModuleSpecifications().
|
staticconstexpr |
File address the synthetic global section is based at.
Code and linear memory are both addressed from zero, so the globals need a range of their own to keep a global index from naming a code or data address as well.
Definition at line 44 of file ObjectFileWasm.cpp.
Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().
|
static |
Definition at line 38 of file ObjectFileWasm.cpp.
Referenced by lldb_private::wasm::ObjectFileWasm::DecodeSections(), and ValidateModuleHeader().