| 1124 | |
| 1125 | #[test] |
| 1126 | fn 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] |
| 1158 | fn standalone_backtrace_disabled() -> Result<()> { |