-
Notifications
You must be signed in to change notification settings - Fork 0
Trap Handling #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Rust Code#[no_mangle]
pub fn _start() {
panic!("Hello, world!");
} Resultswasmtime
wasmer
wavm
wasm3
wasmi
|
The panic trace is stored in the name section, which is listed in the appendix of WebAssembly Specification. parity-wasm
This function can generate the target name section but need to be filtered. wasmer
struct RuntimeErrorInner {
/// The source error (this can be a custom user `Error` or a [`TrapCode`])
source: RuntimeErrorSource,
/// The reconstructed Wasm trace (from the native trace and the `GlobalFrameInfo`).
wasm_trace: Vec<FrameInfo>,
/// The native backtrace
native_trace: Backtrace,
}
impl RuntimeErrorInner {
fn from_trap(trap: Tap) -> Self {
// ...
}
}
enum Trap {
// ...
/// A trap raised from machine code generated from Wasm
Wasm {
/// The program counter in generated code where this trap happened.
pc: usize,
/// Native stack backtrace at the time the trap occurred
backtrace: Backtrace,
/// Optional trapcode associated to the signal that caused the trap
signal_trap: Option<TrapCode>,
},
} wasmtimeFor /// Information about trap.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct TrapInformation {
/// The offset of the trapping instruction in native code.
/// It is relative to the beginning of the function.
pub code_offset: binemit::CodeOffset,
/// Code of the trap.
pub trap_code: ir::TrapCode,
}
struct TrapInner {
reason: TrapReason,
wasm_trace: Vec<FrameInfo>,
native_trace: Backtrace,
}
/// Creates a new `Trap`.
///
/// * `store` - this is optionally provided, if available. If `None` we'll
/// look up the last store, if available, used to call wasm code on the
/// stack.
///
/// * `trap_pc` - this is the precise program counter, if available, that
/// wasm trapped at. This is used when learning about the wasm stack trace
/// to ensure we assign the correct source to every frame.
///
/// * `reason` - this is the wasmtime-internal reason for why this trap is
/// being created.
///
/// * `native_trace` - this is a captured backtrace from when the trap
/// occurred, and this will iterate over the frames to find frames that
/// lie in wasm jit code.
fn new_with_trace(
store: Option<&Store>,
trap_pc: Option<usize>,
reason: TrapReason,
native_trace: Backtrace,
) -> Self {} |
So what is the program counter? How to get it? /// The inner `u32` points to what?
struct Func(u32); Function Namelet fn_name = module.function_names.get(&fn_index); |
Prints functions in Call Stack (wasmi) [
FuncRef(
Internal { signature=Signature { params: [], return_type: None } },
),
FuncRef(
Internal { signature=Signature { params: [I32, I32, I32], return_type: None } },
),
FuncRef(
Internal { signature=Signature { params: [I32], return_type: None } },
),
FuncRef(
Internal { signature=Signature { params: [I32], return_type: None } },
),
FuncRef(
Internal { signature=Signature { params: [I32, I32, I32, I32], return_type: None } },
),
FuncRef(
Internal { signature=Signature { params: [I32, I32], return_type: None } },
),
] Comparing to the ideal outputs
It's fine. [
"rust_panic",
"_ZN3std9panicking20rust_panic_with_hook17hc5713da015ebaa19E",
"_ZN3std9panicking11begin_panic28_$u7b$$u7b$closure$u7d$$u7d$17he51f9abd5f6c28d2E",
"_ZN3std10sys_common9backtrace26__rust_end_short_backtrace17hc867af7cfda96dafE",
"_ZN3std9panicking11begin_panic17h0a859a469eb06beaE",
"_ZN5panic23panic_in_wasm_backtrace17ha67ca05cd299040fE",
"_start",
] Try to decode with https://github.com/alexcrichton/rustc-demangle |
Done, patractlabs/wasmi@80bb84b. |
Traps
Under some conditions, certain instructions may produce a trap, which immediately aborts execution. Traps cannot be handled by WebAssembly code, but are reported to the outside environment, where they typically can be caught.
#Traps concept in WebAssembly Overview
Administrative Instructions in WebAssembly Execution
In order to express the reduction of traps, calls, and control instructions, the syntax of instructions is extended to include the following administrative instructions:
The trap instruction represents the occurrence of a trap. Traps are bubbled up through nested instruction sequences, ultimately reducing the entire program to a single 𝗍𝗋𝖺𝗉 instruction, signaling abrupt termination.
#Administrative Instructions
Runtime Result
A result is the outcome of a computation. It is either a sequence of values or a trap.
#Trap as results in runtime
The text was updated successfully, but these errors were encountered: