MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / standalone_backtrace

Function standalone_backtrace

tests/all/traps.rs:1126–1155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1124
1125#[test]
1126fn standalone_backtrace() -> Result<()> {
1127 let engine = Engine::default();
1128 let mut store = Store::new(&engine, ());
1129 let trace = WasmBacktrace::capture(&store);
1130 assert!(trace.frames().is_empty());
1131 let module = Module::new(
1132 &engine,
1133 r#"
1134 (module
1135 (import "" "" (func $host))
1136 (func $foo (export "f") call $bar)
1137 (func $bar call $host)
1138 )
1139 "#,
1140 )?;
1141 let func = Func::wrap(&mut store, |cx: Caller<'_, ()>| {
1142 let trace = WasmBacktrace::capture(&cx);
1143 assert_eq!(trace.frames().len(), 2);
1144 let frame1 = &trace.frames()[0];
1145 let frame2 = &trace.frames()[1];
1146 assert_eq!(frame1.func_index(), 2);
1147 assert_eq!(frame1.func_name(), Some("bar"));
1148 assert_eq!(frame2.func_index(), 1);
1149 assert_eq!(frame2.func_name(), Some("foo"));
1150 });
1151 let instance = Instance::new(&mut store, &module, &[func.into()])?;
1152 let f = instance.get_typed_func::<(), ()>(&mut store, "f")?;
1153 f.call(&mut store, ())?;
1154 Ok(())
1155}
1156
1157#[test]
1158fn standalone_backtrace_disabled() -> Result<()> {

Callers

nothing calls this directly

Calls 5

captureFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
framesMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected