5#ifndef WASMTIME_TRAP_HH
6#define WASMTIME_TRAP_HH
40 if (name !=
nullptr) {
41 return std::string_view(name->data, name->size);
52 if (name !=
nullptr) {
53 return std::string_view(name->data, name->size);
97inline Trace Error::trace()
const {
100 return Trace(frames);
114 WASMTIME_OWN_WRAPPER(
Trap, wasm_trap);
117 explicit Trap(std::string_view msg)
124 std::string message()
const {
127 std::string ret(msg.
data, msg.
size - 1);
135 Trace trace()
const {
138 return Trace(frames);
143 std::optional<wasmtime_trap_code_t> code()
const {
155 std::variant<Trap, Error>
data;
164 if (
const auto *trap = std::get_if<Trap>(&
data)) {
165 return trap->message();
167 if (
const auto *error = std::get_if<Error>(&
data)) {
168 return std::string(error->message());
Errors coming from Wasmtime.
Definition: error.hh:26
Non-owning reference to a WebAssembly function frame as part of a Trace
Definition: trap.hh:20
size_t module_offset() const
Definition: trap.hh:32
std::optional< std::string_view > module_name() const
Definition: trap.hh:50
uint32_t func_index() const
Definition: trap.hh:26
std::optional< std::string_view > func_name() const
Definition: trap.hh:38
size_t func_offset() const
Definition: trap.hh:29
Fallible result type used for Wasmtime.
Definition: error.hh:70
An owned vector of FrameRef instances representing the WebAssembly call-stack on a trap.
Definition: trap.hh:66
iterator begin() const
Returns the start of iteration.
Definition: trap.hh:86
const FrameRef * iterator
Iterator used to iterate over this trace.
Definition: trap.hh:83
size_t size() const
Returns the size of this trace, or how many frames it contains.
Definition: trap.hh:94
iterator end() const
Returns the end of iteration.
Definition: trap.hh:90
Information about a WebAssembly trap.
Definition: trap.hh:113
WASM_API_EXTERN void wasmtime_error_wasm_trace(const wasmtime_error_t *, wasm_frame_vec_t *out)
Attempts to extract a WebAssembly trace from this error.
A list of bytes.
Definition: wasm.h:102
size_t size
Length of this vector.
Definition: wasm.h:102
wasm_byte_t * data
Pointer to the base of this vector.
Definition: wasm.h:102
Opaque struct representing a frame of a wasm stack trace.
A list of wasm_frame_t frameues.
Definition: wasm.h:373
wasm_frame_t ** data
Pointer to the base of this vector.
Definition: wasm.h:373
size_t size
Length of this vector.
Definition: wasm.h:373
Structure used to represent either a Trap or an Error.
Definition: trap.hh:153
TrapError(Trap t)
Creates a new TrapError from a Trap
Definition: trap.hh:158
TrapError(Error e)
Creates a new TrapError from an Error
Definition: trap.hh:160
std::string message() const
Dispatches internally to return the message associated with this error.
Definition: trap.hh:163
std::variant< Trap, Error > data
Storage for what this trap represents.
Definition: trap.hh:155
WASM_API_EXTERN const wasm_name_t * wasmtime_frame_module_name(const wasm_frame_t *)
Returns a human-readable name for this frame's module.
WASM_API_EXTERN const wasm_name_t * wasmtime_frame_func_name(const wasm_frame_t *)
Returns a human-readable name for this frame's function.
WASM_API_EXTERN wasm_trap_t * wasmtime_trap_new_code(wasmtime_trap_code_t code)
Creates a new trap from the given trap code.
WASM_API_EXTERN bool wasmtime_trap_code(const wasm_trap_t *, wasmtime_trap_code_t *code)
Attempts to extract the trap code from this trap.
wasmtime_trap_code_enum
Trap codes for instruction traps.
Definition: trap.h:26
uint8_t wasmtime_trap_code_t
Code of an instruction trap.
Definition: trap.h:21
WASM_API_EXTERN wasm_trap_t * wasmtime_trap_new(const char *msg, size_t msg_len)
Creates a new trap with the given message.
uint32_t wasm_frame_func_index(const wasm_frame_t *)
Returns the function index in the original wasm module that this frame corresponds to.
void wasm_trap_message(const wasm_trap_t *, wasm_message_t *out)
Retrieves the message associated with this trap.
void wasm_trap_trace(const wasm_trap_t *, wasm_frame_vec_t *out)
Returns the trace of wasm frames for this trap.
size_t wasm_frame_module_offset(const wasm_frame_t *)
Returns the byte offset from the beginning of the original wasm file to the instruction this frame po...
void wasm_byte_vec_delete(wasm_byte_vec_t *)
Deletes a byte vector.
void wasm_frame_vec_delete(wasm_frame_vec_t *)
Deallocates export for a vector.
size_t wasm_frame_func_offset(const wasm_frame_t *)
Returns the byte offset from the beginning of the function in the original wasm file to the instructi...