Skip to content

Commit

Permalink
Address some PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrainy committed Jun 21, 2023
1 parent 61f67b3 commit e486f55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
5 changes: 1 addition & 4 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,7 @@ impl Config {
}

/// Configures whether or not a coredump should be generated and attached to
/// the anyhow::Error when a trap is raised. Because a coredump is a
/// superset of a backtrace, setting this to true will override the setting
/// for `wasm_backtrace`, resulting in a WasmCoreDump being attached to the
/// raised error rather than a WasmBacktrace.
/// the anyhow::Error when a trap is raised.
///
/// This option is disabled by default.
pub fn coredump_on_trap(&mut self, enable: bool) -> &mut Self {
Expand Down
19 changes: 10 additions & 9 deletions crates/wasmtime/src/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use crate::{store::StoreOpaque, Global, Instance, Memory, Module, WasmBacktrace}

/// Representation of a core dump of a WebAssembly module
///
/// This structure is attached to the [`anyhow::Error`] returned from many
/// Wasmtime functions that execute WebAssembly such as [`Instance::new`] or
/// [`Func::call`]. This can be acquired with the [`anyhow::Error::downcast`]
/// family of methods to programmatically inspect the coredump. Otherwise since
/// it's part of the error returned this will get printed along with the rest of
/// the error when the error is logged.
/// When the Config::coredump_on_trap option is enabled this structure is
/// attached to the [`anyhow::Error`] returned from many Wasmtime functions that
/// execute WebAssembly such as [`Instance::new`] or [`Func::call`]. This can be
/// acquired with the [`anyhow::Error::downcast`] family of methods to
/// programmatically inspect the coredump. Otherwise since it's part of the
/// error returned this will get printed along with the rest of the error when
/// the error is logged.
///
/// TODO: Notably absent from this structure at the moment are any locals or
/// operand values for the stack frames. More work is needed to be able to
/// recover those when a trap occurs, at which point they will be added here.
/// Note that some state, such as Wasm locals or values on the operand stack,
/// may be optimized away by the compiler or otherwise not recovered in the
/// coredump.
///
/// Capturing of wasm coredumps can be configured through the
/// [`Config::coredump_on_trap`](crate::Config::coredump_on_trap) method.
Expand Down
27 changes: 12 additions & 15 deletions crates/wasmtime/src/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(crate) fn from_runtime_box(
backtrace,
coredumpstack,
} = *runtime_trap;
let (error, pc) = match reason {
let (mut error, pc) = match reason {
// For user-defined errors they're already an `anyhow::Error` so no
// conversion is really necessary here, but a `backtrace` may have
// been captured so it's attempted to get inserted here.
Expand Down Expand Up @@ -127,22 +127,19 @@ pub(crate) fn from_runtime_box(
wasmtime_runtime::TrapReason::Wasm(trap_code) => (trap_code.into(), None),
};

match (coredumpstack, backtrace) {
(None, None) => error,
(None, Some(bt)) => {
let bt = WasmBacktrace::from_captured(store, bt, pc);
if !bt.wasm_trace.is_empty() {
error.context(bt)
} else {
error
}
}
(Some(coredump), _) => {
let bt = WasmBacktrace::from_captured(store, coredump.bt, pc);
let cd = WasmCoreDump::new(store, bt);
error.context(cd)
if let Some(bt) = backtrace {
let bt = WasmBacktrace::from_captured(store, bt, pc);
if !bt.wasm_trace.is_empty() {
error = error.context(bt);
}
}

if let Some(coredump) = coredumpstack {
let bt = WasmBacktrace::from_captured(store, coredump.bt, pc);
let cd = WasmCoreDump::new(store, bt);
error = error.context(cd);
}
error
}

/// Representation of a backtrace of function frames in a WebAssembly module for
Expand Down

0 comments on commit e486f55

Please sign in to comment.