From a63586142572ee741bf51f68f08562a89737f553 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 6 Dec 2018 23:56:45 -0500 Subject: [PATCH] Report traps in functions invoked from the command line. --- src/wasmtime.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wasmtime.rs b/src/wasmtime.rs index 4c23f0a06f..e9d57fb003 100644 --- a/src/wasmtime.rs +++ b/src/wasmtime.rs @@ -56,7 +56,7 @@ use std::io::stdout; use std::path::Path; use std::path::PathBuf; use std::process::exit; -use wasmtime_execute::{Code, InstanceWorld, NullResolver}; +use wasmtime_execute::{ActionOutcome, Code, InstanceWorld, NullResolver}; static LOG_FILENAME_PREFIX: &str = "cranelift.dbg."; @@ -151,7 +151,12 @@ fn handle_module(args: &Args, path: &Path, isa: &TargetIsa) -> Result<(), String let mut world = InstanceWorld::new(&mut code, isa, &data, &mut resolver)?; if let Some(ref f) = args.flag_function { - world.invoke(&mut code, isa, &f, &[])?; + match world.invoke(&mut code, isa, &f, &[])? { + ActionOutcome::Returned { .. } => {} + ActionOutcome::Trapped { message } => { + return Err(format!("Trap from within function {}: {}", f, message)); + } + } } if args.flag_memory {