LLDB mainline
ObjectFileWasm.cpp File Reference
#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/BinaryFormat/Magic.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Support/CheckedArithmetic.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Format.h"
#include <optional>

Go to the source code of this file.

Classes

struct  WasmFunction
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 (const DataBufferSP &data_sp)
 Checks whether the data buffer starts with a valid Wasm module header.
static llvm::Expected< std::vector< WasmFunction > > ParseFunctions (DataExtractor &data)
static llvm::Expected< std::vector< WasmSegment > > ParseData (DataExtractor &data)
static llvm::Expected< std::vector< Symbol > > ParseNames (SectionSP code_section_sp, DataExtractor &name_data, const std::vector< WasmFunction > &functions, std::vector< WasmSegment > &segments)
static SectionType GetSectionTypeFromName (llvm::StringRef Name)

Variables

static const uint32_t kWasmHeaderSize

Function Documentation

◆ GetSectionTypeFromName()

SectionType GetSectionTypeFromName ( llvm::StringRef Name)
static

◆ GetULEB32() [1/2]

llvm::Expected< uint32_t > GetULEB32 ( DataExtractor & data,
lldb::offset_t & offset )
inlinestatic

Helper to read a 32-bit ULEB using LLDB's DataExtractor.

Definition at line 40 of file ObjectFileWasm.cpp.

References GetULEB32().

Referenced by GetULEB32(), GetWasmString(), ParseData(), ParseFunctions(), and ParseNames().

◆ GetULEB32() [2/2]

llvm::Expected< uint32_t > GetULEB32 ( llvm::DataExtractor & data,
llvm::DataExtractor::Cursor & c )
inlinestatic

Helper to read a 32-bit ULEB using LLVM's DataExtractor.

Definition at line 50 of file ObjectFileWasm.cpp.

◆ GetWasmOffsetFromInitExpr()

lldb::offset_t GetWasmOffsetFromInitExpr ( DataExtractor & data,
lldb::offset_t & offset )
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 78 of file ObjectFileWasm.cpp.

References lldb_private::DataExtractor::GetFloat(), lldb_private::DataExtractor::GetSLEB128(), lldb_private::DataExtractor::GetU8(), lldb_private::DataExtractor::GetULEB128(), and LLDB_INVALID_OFFSET.

Referenced by ParseData().

◆ GetWasmString()

llvm::Expected< std::string > GetWasmString ( llvm::DataExtractor & data,
llvm::DataExtractor::Cursor & c )
inlinestatic

Helper to read a Wasm string, whcih is encoded as a vector of UTF-8 codes.

Definition at line 61 of file ObjectFileWasm.cpp.

References GetULEB32().

Referenced by lldb_private::wasm::ObjectFileWasm::DecodeNextSection(), lldb_private::wasm::ObjectFileWasm::GetExternalDebugInfoFileSpec(), and ParseNames().

◆ ParseData()

◆ ParseFunctions()

llvm::Expected< std::vector< WasmFunction > > ParseFunctions ( DataExtractor & data)
static

Definition at line 311 of file ObjectFileWasm.cpp.

References GetULEB32().

Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections().

◆ ParseNames()

llvm::Expected< std::vector< Symbol > > ParseNames ( SectionSP code_section_sp,
DataExtractor & name_data,
const std::vector< WasmFunction > & functions,
std::vector< WasmSegment > & segments )
static

◆ ValidateModuleHeader()

bool ValidateModuleHeader ( const DataBufferSP & data_sp)
static

Checks whether the data buffer starts with a valid Wasm module header.

Definition at line 116 of file ObjectFileWasm.cpp.

References kWasmHeaderSize.

Referenced by lldb_private::wasm::ObjectFileWasm::CreateInstance(), lldb_private::wasm::ObjectFileWasm::CreateMemoryInstance(), and lldb_private::wasm::ObjectFileWasm::GetModuleSpecifications().

Variable Documentation

◆ kWasmHeaderSize

const uint32_t kWasmHeaderSize
static
Initial value:
=
sizeof(llvm::wasm::WasmMagic) + sizeof(llvm::wasm::WasmVersion)

Definition at line 36 of file ObjectFileWasm.cpp.

Referenced by lldb_private::wasm::ObjectFileWasm::DecodeSections(), and ValidateModuleHeader().