Symbolize start trap traces (#1437)

Make sure we've registered the frame info early enough so traps during
instantiation give frames as well.
This commit is contained in:
Alex Crichton
2020-03-30 17:02:01 -05:00
committed by GitHub
parent bc462404b3
commit bc5568f4b3
2 changed files with 34 additions and 1 deletions

View File

@@ -123,6 +123,7 @@ impl Instance {
}
}
module.register_frame_info();
let config = store.engine().config();
let instance_handle = instantiate(
config,
@@ -141,7 +142,6 @@ impl Instance {
export,
));
}
module.register_frame_info();
Ok(Instance {
instance_handle,
module: module.clone(),

View File

@@ -361,3 +361,36 @@ fn call_signature_mismatch() -> Result<()> {
);
Ok(())
}
#[test]
fn start_trap_pretty() -> Result<()> {
let store = Store::default();
let wat = r#"
(module $m
(func $die unreachable)
(func call $die)
(func $foo call 1)
(func $start call $foo)
(start $start)
)
"#;
let module = Module::new(&store, wat)?;
let e = match Instance::new(&module, &[]) {
Ok(_) => panic!("expected failure"),
Err(e) => e.downcast::<Trap>()?,
};
assert_eq!(
e.to_string(),
"\
wasm trap: unreachable, source location: @001d
wasm backtrace:
0: m!die
1: m!<wasm function 1>
2: m!foo
3: m!start
"
);
Ok(())
}