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);
100 return Trace(frames);
117 template <
typename Params,
typename Results>
friend class TypedFunc;
123 std::unique_ptr<wasm_trap_t, deleter> ptr;
129 explicit Trap(std::string_view msg)
136 std::string ret(msg.
data, msg.
size - 1);
147 return Trace(frames);
152 std::optional<wasmtime_trap_code_t>
code()
const {
164 std::variant<Trap, Error>
data;
173 if (
const auto *trap = std::get_if<Trap>(&
data)) {
174 return trap->message();
176 if (
const auto *error = std::get_if<Error>(&
data)) {
177 return std::string(error->message());
Errors coming from Wasmtime.
Definition: error.hh:24
Trace trace() const
Definition: trap.hh:97
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
Representation of a WebAssembly function.
Definition: wasmtime.hh:347
A WebAssembly instance.
Definition: wasmtime.hh:929
Helper class for linking modules together with name-based resolution.
Definition: wasmtime.hh:1061
Fallible result type used for Wasmtime.
Definition: error.hh:83
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
std::optional< wasmtime_trap_code_t > code() const
Returns the trap code associated with this trap, or nothing if it was a manually created trap.
Definition: trap.hh:152
Trap(std::string_view msg)
Creates a new host-defined trap with the specified message.
Definition: trap.hh:129
std::string message() const
Returns the descriptive message associated with this trap.
Definition: trap.hh:133
Trace trace() const
Definition: trap.hh:144
A version of a WebAssembly Func where the type signature of the function is statically known.
Definition: wasmtime.hh:606
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
Opaque struct representing a wasm trap.
Structure used to represent either a Trap or an Error.
Definition: trap.hh:162
TrapError(Trap t)
Creates a new TrapError from a Trap
Definition: trap.hh:167
TrapError(Error e)
Creates a new TrapError from an Error
Definition: trap.hh:169
std::string message() const
Dispatches internally to return the message associated with this error.
Definition: trap.hh:172
std::variant< Trap, Error > data
Storage for what this trap represents.
Definition: trap.hh:164
const wasm_name_t * wasmtime_frame_module_name(const wasm_frame_t *)
Returns a human-readable name for this frame's module.
bool wasmtime_trap_code(const wasm_trap_t *, wasmtime_trap_code_t *code)
Attempts to extract the trap code from this trap.
wasm_trap_t * wasmtime_trap_new(const char *msg, size_t msg_len)
Creates a new trap.
const wasm_name_t * wasmtime_frame_func_name(const wasm_frame_t *)
Returns a human-readable name for this frame's function.
uint8_t wasmtime_trap_code_t
Code of an instruction trap.
Definition: trap.h:21
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.
void wasm_trap_delete(wasm_trap_t *)
Deletes a trap.
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...