...

Package wasmdebug

import "github.com/tetratelabs/wazero/internal/wasmdebug"
Overview
Index

Overview ▾

Package wasmdebug contains utilities used to give consistent search keys between stack traces and error messages. Note: This is named wasmdebug to avoid conflicts with the normal go module. Note: This only imports "api" as importing "wasm" would create a cyclic dependency.

Constants

GoRuntimeErrorTracePrefix is the prefix coming before the Go runtime stack trace included in the face of runtime.Error. This is exported for testing purpose.

const GoRuntimeErrorTracePrefix = "Go runtime stack trace:"

func FuncName

func FuncName(moduleName, funcName string, funcIdx uint32) string

FuncName returns the naming convention of "moduleName.funcName".

Note: "moduleName.$funcIdx" is used when the funcName is empty, as commonly the case in TinyGo.

type DWARFLines

DWARFLines is used to retrieve source code line information from the DWARF data.

type DWARFLines struct {
    // contains filtered or unexported fields
}

func NewDWARFLines

func NewDWARFLines(d *dwarf.Data) *DWARFLines

NewDWARFLines returns DWARFLines for the given *dwarf.Data.

func (*DWARFLines) Line

func (d *DWARFLines) Line(instructionOffset uint64) (ret []string)

Line returns the line information for the given instructionOffset which is an offset in the code section of the original Wasm binary. Returns empty string if the info is not found.

type ErrorBuilder

ErrorBuilder helps build consistent errors, particularly adding a WASM stack trace.

AddFrame should be called beginning at the frame that panicked until no more frames exist. Once done, call Format.

type ErrorBuilder interface {
    // AddFrame adds the next frame.
    //
    // * funcName should be from FuncName
    // * paramTypes should be from wasm.FunctionType
    // * resultTypes should be from wasm.FunctionType
    // * sources is the source code information for this frame and can be empty.
    //
    // Note: paramTypes and resultTypes are present because signature misunderstanding, mismatch or overflow are common.
    AddFrame(funcName string, paramTypes, resultTypes []api.ValueType, sources []string)

    // FromRecovered returns an error with the wasm stack trace appended to it.
    FromRecovered(recovered interface{}) error
}

func NewErrorBuilder

func NewErrorBuilder() ErrorBuilder