Add a WasmBacktrace::new() constructor (#5341)

* Add a `WasmBacktrace::new()` constructor

This commit adds a method of manually capturing a backtrace of
WebAssembly frames within a `Store`. The new constructor can be called
with any `AsContext` values, primarily `&Store` and `&Caller`, during
host functions to inspect the calling state.

For now this does not respect the `Config::wasm_backtrace` option and
instead unconditionally captures the backtrace. It's hoped that this can
continue to adapt to needs of embedders by making it more configurable
int he future if necessary.

Closes #5339

* Split `new` into `capture` and `force_capture`
This commit is contained in:
Alex Crichton
2022-12-01 16:19:07 -06:00
committed by GitHub
parent e0b9663e44
commit ed6769084b
3 changed files with 141 additions and 3 deletions

View File

@@ -74,6 +74,11 @@ impl Frame {
}
impl Backtrace {
/// Returns an empty backtrace
pub fn empty() -> Backtrace {
Backtrace(Vec::new())
}
/// Capture the current Wasm stack in a backtrace.
pub fn new() -> Backtrace {
tls::with(|state| match state {