diff --git a/Cargo.lock b/Cargo.lock index 87a4fe31bd..05f2588269 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -723,6 +723,7 @@ dependencies = [ "wasm-smith", "wasmi 0.44.0", "wasmi_fuzz", + "wasmi_tracer", "wasmprinter 0.227.1", ] @@ -1765,6 +1766,7 @@ version = "0.44.0" dependencies = [ "wasmi 0.44.0", "wasmi_c_api_macros", + "wasmi_tracer", ] [[package]] @@ -1783,6 +1785,7 @@ dependencies = [ "assert_cmd", "clap", "wasmi 0.44.0", + "wasmi_tracer", "wasmi_wasi", ] @@ -1854,6 +1857,7 @@ version = "0.44.0" dependencies = [ "anyhow", "wasmi 0.44.0", + "wasmi_tracer", "wast 227.0.1", ] diff --git a/crates/c_api/Cargo.toml b/crates/c_api/Cargo.toml index 161ba417ad..c8a8f10cf5 100644 --- a/crates/c_api/Cargo.toml +++ b/crates/c_api/Cargo.toml @@ -17,6 +17,7 @@ links = "wasmi_c_api" [dependencies] wasmi = { workspace = true } wasmi_c_api_macros = { workspace = true } +wasmi_tracer = { workspace = true } [lib] name = "wasmi_c_api" diff --git a/crates/c_api/src/func.rs b/crates/c_api/src/func.rs index c4402786e5..8f3ac8a4a7 100644 --- a/crates/c_api/src/func.rs +++ b/crates/c_api/src/func.rs @@ -9,6 +9,7 @@ use crate::{ use alloc::{boxed::Box, string::String, vec, vec::Vec}; use core::{any::Any, ffi::c_void, hint, iter, ptr, str}; use wasmi::{Error, Extern, Func, FuncRef, Val}; +use wasmi_tracer::WasmTracer; #[cfg(feature = "std")] use core::panic::AssertUnwindSafe; @@ -210,7 +211,8 @@ pub unsafe extern "C" fn wasm_func_call( // can. As a result we catch panics here and transform them to traps to // allow the caller to have any insulation possible against Rust panics. std::panic::catch_unwind(AssertUnwindSafe(|| { - f.call(func.inner.store.context_mut(), wt_params, wt_results) + let mut tracer = WasmTracer::no_tracing(); + f.call(func.inner.store.context_mut(), wt_params, wt_results, &mut tracer) })) } #[cfg(not(feature = "std"))] diff --git a/crates/c_api/src/instance.rs b/crates/c_api/src/instance.rs index c5003b2043..1c74a5dfd6 100644 --- a/crates/c_api/src/instance.rs +++ b/crates/c_api/src/instance.rs @@ -8,6 +8,7 @@ use crate::{ }; use alloc::boxed::Box; use wasmi::Instance; +use wasmi_tracer::WasmTracer; /// A Wasm instance. /// @@ -56,7 +57,8 @@ pub unsafe extern "C" fn wasm_instance_new( .iter() .filter_map(|import| import.as_ref().map(|i| i.which)) .collect::>(); - match Instance::new(store.inner.context_mut(), &wasm_module.inner, &imports) { + let mut tracer = WasmTracer::no_tracing(); + match Instance::new(store.inner.context_mut(), &wasm_module.inner, &imports, &mut tracer) { Ok(instance) => Some(Box::new(wasm_instance_t::new( store.inner.clone(), instance, diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ebd876d8f7..ae448a1f6a 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -16,6 +16,7 @@ exclude.workspace = true [dependencies] wasmi = { workspace = true, features = ["wat"] } wasmi_wasi = { workspace = true } +wasmi_tracer = { workspace = true } anyhow = "1" clap = { version = "4", features = ["derive"] } diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 52fca2c689..b29f42e234 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -99,6 +99,12 @@ pub struct Args { /// Arguments given to the Wasm module or the invoked function. #[clap(value_name = "ARGS")] func_args: Vec, + + #[clap( + long = "trace", + default_value_t = false, + )] + tracing: bool, } /// The chosen Wasmi compilation mode. @@ -151,6 +157,11 @@ impl Args { self.verbose } + /// Returns `true` if tracing is enabled. + pub fn tracing(&self) -> bool { + self.tracing + } + /// Pre-opens all directories given in `--dir` and returns them for use by the [`WasiCtx`]. /// /// # Errors diff --git a/crates/cli/src/context.rs b/crates/cli/src/context.rs index 84f1b7e348..75c20a8692 100644 --- a/crates/cli/src/context.rs +++ b/crates/cli/src/context.rs @@ -2,6 +2,7 @@ use anyhow::{anyhow, Error}; use std::{fs, path::Path}; use wasmi::{CompilationMode, Config, ExternType, Func, FuncType, Instance, Module, Store}; use wasmi_wasi::WasiCtx; +use wasmi_tracer::WasmTracer; /// The [`Context`] for the Wasmi CLI application. /// @@ -13,6 +14,8 @@ pub struct Context { store: Store, /// The Wasm module instance to operate on. instance: Instance, + // Is the tracing enabled + // tracing: bool, } impl Context { @@ -27,6 +30,7 @@ impl Context { wasi_ctx: WasiCtx, fuel: Option, compilation_mode: CompilationMode, + tracer: &mut WasmTracer, ) -> Result { let mut config = Config::default(); if fuel.is_some() { @@ -52,7 +56,7 @@ impl Context { .map_err(|error| anyhow!("failed to add WASI definitions to the linker: {error}"))?; let instance = linker .instantiate(&mut store, &module) - .and_then(|pre| pre.start(&mut store)) + .and_then(|pre| pre.start(&mut store, tracer)) .map_err(|error| anyhow!("failed to instantiate and start the Wasm module: {error}"))?; Ok(Self { module, diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 57aa938773..7a1eab75cb 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -7,6 +7,7 @@ use clap::Parser; use context::Context; use std::{path::Path, process}; use wasmi::{Func, FuncType, Val}; +use wasmi_tracer::WasmTracer; mod args; mod context; @@ -20,7 +21,9 @@ fn main() -> Result<()> { let args = Args::parse(); let wasm_file = args.wasm_file(); let wasi_ctx = args.wasi_context()?; - let mut ctx = Context::new(wasm_file, wasi_ctx, args.fuel(), args.compilation_mode())?; + let wasm_file_full_path = std::fs::canonicalize(&wasm_file)?; + let mut tracer = WasmTracer::new(args.tracing(), &wasm_file_full_path); + let mut ctx = Context::new(wasm_file, wasi_ctx, args.fuel(), args.compilation_mode(), &mut tracer)?; let (func_name, func) = get_invoked_func(&args, &ctx)?; let ty = func.ty(ctx.store()); let func_args = utils::decode_func_args(&ty, args.func_args())?; @@ -39,7 +42,7 @@ fn main() -> Result<()> { ) } - match func.call(ctx.store_mut(), &func_args, &mut func_results) { + match func.call(ctx.store_mut(), &func_args, &mut func_results, &mut tracer) { Ok(()) => { print_remaining_fuel(&args, &ctx); print_pretty_results(&func_results); diff --git a/crates/tracer/src/lib.rs b/crates/tracer/src/lib.rs index ca02e3cbb8..5f2eda44ed 100644 --- a/crates/tracer/src/lib.rs +++ b/crates/tracer/src/lib.rs @@ -25,6 +25,7 @@ impl DebugInfo { #[derive(Debug, Clone)] pub struct WasmTracer { + pub tracing: bool, debug_info: DebugInfo, // TODO: tracer: runtime_tracing.Tracer, // etc @@ -33,12 +34,20 @@ pub struct WasmTracer { // just to make it build so we can branch-out impl WasmTracer { - pub fn new(wasm_exe_path: &Path) -> Self { + pub fn new(tracing: bool, wasm_exe_path: &Path) -> Self { WasmTracer { + tracing, debug_info: DebugInfo::new(wasm_exe_path), } } + pub fn no_tracing() -> Self { + WasmTracer { + tracing: false, + debug_info: DebugInfo::new(&Path::new("")), + } + } + pub fn load_local_variables(&mut self, address: usize) { // -> ??? println!("load_local_variables {address}"); // e.g. here we might call something like diff --git a/crates/wasmi/src/engine/config.rs b/crates/wasmi/src/engine/config.rs index 68a254e240..e5f08fc845 100644 --- a/crates/wasmi/src/engine/config.rs +++ b/crates/wasmi/src/engine/config.rs @@ -27,6 +27,7 @@ pub struct Config { compilation_mode: CompilationMode, /// Enforced limits for Wasm module parsing and compilation. limits: EnforcedLimits, + // tracing: bool, } /// Type storing all kinds of fuel costs of instructions. diff --git a/crates/wasmi/src/engine/executor/instrs.rs b/crates/wasmi/src/engine/executor/instrs.rs index e7a448f962..4eb29f45bf 100644 --- a/crates/wasmi/src/engine/executor/instrs.rs +++ b/crates/wasmi/src/engine/executor/instrs.rs @@ -71,10 +71,11 @@ pub fn execute_instrs<'engine, T>( store: &mut Store, stack: &'engine mut Stack, code_map: &'engine CodeMap, + tracer: &'engine mut WasmTracer, ) -> Result<(), Error> { let instance = stack.calls.instance_expect(); let cache = CachedInstance::new(&mut store.inner, instance); - Executor::new(stack, code_map, cache).execute(store) + Executor::new(stack, code_map, cache).execute(store, tracer) } /// An execution context for executing a Wasmi function frame. @@ -94,7 +95,8 @@ struct Executor<'engine> { code_map: &'engine CodeMap, // debug: - // TODO tracer: &'engine mut WasmTracer, + // tracer: &'engine mut WasmTracer, + // tracing: bool, } impl<'engine> Executor<'engine> { @@ -104,6 +106,7 @@ impl<'engine> Executor<'engine> { stack: &'engine mut Stack, code_map: &'engine CodeMap, cache: CachedInstance, + // tracer: &'engine mut WasmTracer, ) -> Self { let frame = stack .calls @@ -121,25 +124,26 @@ impl<'engine> Executor<'engine> { cache, stack, code_map, - // TODO tracer: &mut tracer, // probably were not gonna make it + // tracer, + // tracing, } } /// Executes the function frame until it returns or traps. #[inline(always)] - fn execute(mut self, store: &mut Store) -> Result<(), Error> { + fn execute(mut self, store: &mut Store, tracer: &mut WasmTracer) -> Result<(), Error> { use Instruction as Instr; loop { - // TODO: change that, just startting from somewehre - // Args: path : Path, instruction address(?) , step? - // TODO: good way to take address - //let address = usize::from(self.ip.get()); - let address = 0x000000010; // should be in the main subprogram >= low_pc - //std::println!("address of {:?}: {:?}", *self.ip.get(), address); - // TODO: make this be a field with correct lifetime - let mut tracer = WasmTracer::new(std::path::Path::new("/home/pesho/code/codetracer-wasmi-recorder/wasm_test.wasm")); // ": for now hardcoded TODO pass"); - tracer.load_local_variables(address); - + if tracer.tracing { + std::println!("{:?}", tracer); + // TODO: change that, just startting from somewehre + // Args: path : Path, instruction address(?) , step? + // TODO: good way to take address + //let address = usize::from(self.ip.get()); + let address = 0x000000010; // should be in the main subprogram >= low_pc + // TODO: make this be a field with correct lifetime + tracer.load_local_variables(address); + } // load debuginfo from gimli <- for this ip; // -> find out current scope and vars in it: // some kind of mapping between them and locations diff --git a/crates/wasmi/src/engine/executor/mod.rs b/crates/wasmi/src/engine/executor/mod.rs index d6858bf5ee..a08d9f7b74 100644 --- a/crates/wasmi/src/engine/executor/mod.rs +++ b/crates/wasmi/src/engine/executor/mod.rs @@ -22,6 +22,8 @@ use crate::engine::StackLimits; use super::code_map::CodeMap; +use wasmi_tracer::WasmTracer; + mod cache; mod instr_ptr; mod instrs; @@ -41,13 +43,14 @@ impl EngineInner { func: &Func, params: impl CallParams, results: Results, + tracer: &mut WasmTracer, ) -> Result<::Results, Error> where Results: CallResults, { let mut stack = self.stacks.lock().reuse_or_new(); let results = EngineExecutor::new(&self.code_map, &mut stack) - .execute_root_func(ctx.store, func, params, results) + .execute_root_func(ctx.store, func, params, results, tracer) .map_err(|error| match error.into_resumable() { Ok(error) => error.into_error(), Err(error) => error, @@ -69,6 +72,7 @@ impl EngineInner { func: &Func, params: impl CallParams, results: Results, + tracer: &mut WasmTracer, ) -> Result::Results>, Error> where Results: CallResults, @@ -76,7 +80,7 @@ impl EngineInner { let store = ctx.store; let mut stack = self.stacks.lock().reuse_or_new(); let results = EngineExecutor::new(&self.code_map, &mut stack) - .execute_root_func(store, func, params, results); + .execute_root_func(store, func, params, results, tracer); match results { Ok(results) => { self.stacks.lock().recycle(stack); @@ -117,6 +121,7 @@ impl EngineInner { mut invocation: ResumableInvocation, params: impl CallParams, results: Results, + tracer: &mut WasmTracer, ) -> Result::Results>, Error> where Results: CallResults, @@ -129,6 +134,7 @@ impl EngineInner { params, caller_results, results, + tracer, ); match results { Ok(results) => { @@ -158,6 +164,8 @@ pub struct EngineExecutor<'engine> { code_map: &'engine CodeMap, /// The value and call stacks. stack: &'engine mut Stack, + // wasm tracer + // tracer: &'engine mut WasmTracer, } /// Convenience function that does nothing to its `&mut` parameter. @@ -185,6 +193,7 @@ impl<'engine> EngineExecutor<'engine> { func: &Func, params: impl CallParams, results: Results, + tracer: &mut WasmTracer ) -> Result<::Results, Error> where Results: CallResults, @@ -217,7 +226,7 @@ impl<'engine> EngineExecutor<'engine> { Some(instance), )?; store.invoke_call_hook(CallHook::CallingWasm)?; - self.execute_func(store)?; + self.execute_func(store, tracer)?; store.invoke_call_hook(CallHook::ReturningFromWasm)?; } FuncEntity::Host(host_func) => { @@ -259,6 +268,7 @@ impl<'engine> EngineExecutor<'engine> { params: impl CallParams, caller_results: RegSpan, results: Results, + tracer: &mut WasmTracer ) -> Result<::Results, Error> where Results: CallResults, @@ -274,7 +284,7 @@ impl<'engine> EngineExecutor<'engine> { for (result, param) in caller_results.iter_sized(len_params).zip(call_params) { unsafe { caller_sp.set(result, param) }; } - self.execute_func(store)?; + self.execute_func(store, tracer)?; let results = self.write_results_back(results); Ok(results) } @@ -285,8 +295,8 @@ impl<'engine> EngineExecutor<'engine> { /// /// When encountering a Wasm or host trap during execution. #[inline(always)] - fn execute_func(&mut self, store: &mut Store) -> Result<(), Error> { - execute_instrs(store, self.stack, self.code_map) + fn execute_func(&mut self, store: &mut Store, tracer: &mut WasmTracer) -> Result<(), Error> { + execute_instrs(store, self.stack, self.code_map, tracer) } /// Convenience forwarder to [`dispatch_host_func`]. diff --git a/crates/wasmi/src/engine/mod.rs b/crates/wasmi/src/engine/mod.rs index 7036eaf4d9..eb552cac31 100644 --- a/crates/wasmi/src/engine/mod.rs +++ b/crates/wasmi/src/engine/mod.rs @@ -59,6 +59,7 @@ use alloc::{ use core::sync::atomic::{AtomicU32, Ordering}; use spin::{Mutex, RwLock}; use wasmparser::{FuncToValidate, FuncValidatorAllocations, ValidatorResources}; +use wasmi_tracer::WasmTracer; #[cfg(doc)] use crate::Store; @@ -295,11 +296,12 @@ impl Engine { func: &Func, params: impl CallParams, results: Results, + tracer: &mut WasmTracer ) -> Result<::Results, Error> where Results: CallResults, { - self.inner.execute_func(ctx, func, params, results) + self.inner.execute_func(ctx, func, params, results, tracer) } /// Executes the given [`Func`] resumably with parameters `params` and returns. @@ -331,12 +333,13 @@ impl Engine { func: &Func, params: impl CallParams, results: Results, + tracer: &mut WasmTracer ) -> Result::Results>, Error> where Results: CallResults, { self.inner - .execute_func_resumable(ctx, func, params, results) + .execute_func_resumable(ctx, func, params, results, tracer) } /// Resumes the given `invocation` given the `params`. @@ -368,11 +371,12 @@ impl Engine { invocation: ResumableInvocation, params: impl CallParams, results: Results, + tracer: &mut WasmTracer ) -> Result::Results>, Error> where Results: CallResults, { - self.inner.resume_func(ctx, invocation, params, results) + self.inner.resume_func(ctx, invocation, params, results, tracer) } /// Recycles the given [`Stack`] for reuse in the [`Engine`]. diff --git a/crates/wasmi/src/engine/resumable.rs b/crates/wasmi/src/engine/resumable.rs index d039b7b129..929b2f977a 100644 --- a/crates/wasmi/src/engine/resumable.rs +++ b/crates/wasmi/src/engine/resumable.rs @@ -10,6 +10,7 @@ use crate::{ WasmResults, }; use core::{fmt, marker::PhantomData, mem::replace, ops::Deref}; +use wasmi_tracer::WasmTracer; /// Returned by [`Engine`] methods for calling a function in a resumable way. /// @@ -212,6 +213,7 @@ impl ResumableInvocation { mut ctx: impl AsContextMut, inputs: &[Val], outputs: &mut [Val], + tracer: &mut WasmTracer, ) -> Result { self.engine .resolve_func_type(self.host_func().ty_dedup(ctx.as_context()), |func_type| { @@ -225,7 +227,7 @@ impl ResumableInvocation { })?; self.engine .clone() - .resume_func(ctx.as_context_mut(), self, inputs, outputs) + .resume_func(ctx.as_context_mut(), self, inputs, outputs, tracer) .map(ResumableCall::new) } } @@ -288,6 +290,7 @@ impl TypedResumableInvocation { self, mut ctx: impl AsContextMut, inputs: &[Val], + tracer: &mut WasmTracer, ) -> Result, Error> where Results: WasmResults, @@ -303,6 +306,7 @@ impl TypedResumableInvocation { self.invocation, inputs, >::default(), + tracer, ) .map(TypedResumableCall::new) } diff --git a/crates/wasmi/src/func/mod.rs b/crates/wasmi/src/func/mod.rs index 86528d7c53..a924cc93c9 100644 --- a/crates/wasmi/src/func/mod.rs +++ b/crates/wasmi/src/func/mod.rs @@ -25,6 +25,7 @@ use super::{ use crate::{collections::arena::ArenaIndex, engine::ResumableCall, Engine, Error, Val}; use alloc::{boxed::Box, sync::Arc}; use core::{fmt, fmt::Debug, num::NonZeroU32}; +use wasmi_tracer::WasmTracer; /// A raw index to a function entity. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -415,6 +416,7 @@ impl Func { mut ctx: impl AsContextMut, inputs: &[Val], outputs: &mut [Val], + tracer: &mut WasmTracer, ) -> Result<(), Error> { self.verify_and_prepare_inputs_outputs(ctx.as_context(), inputs, outputs)?; // Note: Cloning an [`Engine`] is intentionally a cheap operation. @@ -423,6 +425,7 @@ impl Func { self, inputs, outputs, + tracer, )?; Ok(()) } @@ -455,6 +458,7 @@ impl Func { mut ctx: impl AsContextMut, inputs: &[Val], outputs: &mut [Val], + tracer: &mut WasmTracer, ) -> Result { self.verify_and_prepare_inputs_outputs(ctx.as_context(), inputs, outputs)?; // Note: Cloning an [`Engine`] is intentionally a cheap operation. @@ -462,7 +466,7 @@ impl Func { .store .engine() .clone() - .execute_func_resumable(ctx.as_context_mut(), self, inputs, outputs) + .execute_func_resumable(ctx.as_context_mut(), self, inputs, outputs, tracer) .map(ResumableCall::new) } diff --git a/crates/wasmi/src/func/typed_func.rs b/crates/wasmi/src/func/typed_func.rs index cad323039e..0263063ad0 100644 --- a/crates/wasmi/src/func/typed_func.rs +++ b/crates/wasmi/src/func/typed_func.rs @@ -8,6 +8,7 @@ use crate::{ TypedResumableCall, }; use core::{fmt, fmt::Debug, marker::PhantomData}; +use wasmi_tracer::WasmTracer; /// A typed [`Func`] instance. /// @@ -93,13 +94,14 @@ where /// # Errors /// /// If the execution of the called Wasm function traps. - pub fn call(&self, mut ctx: impl AsContextMut, params: Params) -> Result { + pub fn call(&self, mut ctx: impl AsContextMut, params: Params, tracer: &mut WasmTracer) -> Result { // Note: Cloning an [`Engine`] is intentionally a cheap operation. ctx.as_context().store.engine().clone().execute_func( ctx.as_context_mut(), &self.func, params, >::default(), + tracer, ) } @@ -122,6 +124,7 @@ where &self, mut ctx: impl AsContextMut, params: Params, + tracer: &mut WasmTracer, ) -> Result, Error> { // Note: Cloning an [`Engine`] is intentionally a cheap operation. ctx.as_context() @@ -133,6 +136,7 @@ where &self.func, params, >::default(), + tracer, ) .map(TypedResumableCall::new) } diff --git a/crates/wasmi/src/instance/mod.rs b/crates/wasmi/src/instance/mod.rs index c078b3e95e..3326715f77 100644 --- a/crates/wasmi/src/instance/mod.rs +++ b/crates/wasmi/src/instance/mod.rs @@ -23,6 +23,7 @@ use crate::{ WasmResults, }; use alloc::{boxed::Box, sync::Arc}; +use wasmi_tracer::WasmTracer; mod builder; mod exports; @@ -186,9 +187,10 @@ impl Instance { mut store: impl AsContextMut, module: &Module, imports: &[Extern], + tracer: &mut WasmTracer, ) -> Result { let instance_pre = Module::instantiate(module, &mut store, imports.iter().cloned())?; - let instance = instance_pre.start(&mut store)?; + let instance = instance_pre.start(&mut store, tracer)?; Ok(instance) } diff --git a/crates/wasmi/src/module/instantiate/pre.rs b/crates/wasmi/src/module/instantiate/pre.rs index bde2bf127f..e8d20d7d33 100644 --- a/crates/wasmi/src/module/instantiate/pre.rs +++ b/crates/wasmi/src/module/instantiate/pre.rs @@ -1,5 +1,6 @@ use super::InstantiationError; use crate::{module::FuncIdx, AsContextMut, Error, Instance, InstanceEntityBuilder}; +use wasmi_tracer::WasmTracer; /// A partially instantiated [`Instance`] where the `start` function has not yet been executed. /// @@ -40,7 +41,7 @@ impl InstancePre { /// # Panics /// /// If the `start` function is invalid albeit successful validation. - pub fn start(self, mut context: impl AsContextMut) -> Result { + pub fn start(self, mut context: impl AsContextMut, tracer: &mut WasmTracer) -> Result { let opt_start_index = self.start_fn(); context .as_context_mut() @@ -54,7 +55,7 @@ impl InstancePre { .unwrap_or_else(|| { panic!("encountered invalid start function after validation: {start_index}") }); - start_func.call(context.as_context_mut(), &[], &mut [])? + start_func.call(context.as_context_mut(), &[], &mut [], tracer)? } Ok(self.handle) } diff --git a/crates/wast/Cargo.toml b/crates/wast/Cargo.toml index 52b280f389..5a2437e405 100644 --- a/crates/wast/Cargo.toml +++ b/crates/wast/Cargo.toml @@ -16,4 +16,5 @@ exclude.workspace = true [dependencies] wasmi = { workspace = true, features = ["std", "simd"] } wast = { workspace = true, features = ["wasm-module"] } +wasmi_tracer = { workspace = true } anyhow = "1.0" diff --git a/crates/wast/src/lib.rs b/crates/wast/src/lib.rs index 2a501d3d3b..783dd34167 100644 --- a/crates/wast/src/lib.rs +++ b/crates/wast/src/lib.rs @@ -30,6 +30,7 @@ use wast::{ WastRet, Wat, }; +use wasmi_tracer::WasmTracer; /// The configuration for the test runner. #[derive(Debug, Copy, Clone)] @@ -321,8 +322,9 @@ impl WastRunner { /// /// Also sets the `current` instance to the `module` instance. fn module(&mut self, name: Option<&str>, module: &Module) -> Result<()> { + let mut tracer = WasmTracer::no_tracing(); let instance = match self.linker.instantiate(&mut self.store, module) { - Ok(pre_instance) => pre_instance.start(&mut self.store)?, + Ok(pre_instance) => pre_instance.start(&mut self.store, &mut tracer)?, Err(error) => bail!("failed to instantiate module: {error}"), }; if let Some(name) = name { @@ -440,7 +442,8 @@ impl WastRunner { WastExecute::Wat(Wat::Module(module)) => { let (_name, module) = self.module_definition(QuoteWat::Wat(Wat::Module(module)))?; let instance_pre = self.linker.instantiate(&mut self.store, &module)?; - instance_pre.start(&mut self.store)?; + let mut tracer = WasmTracer::no_tracing(); + instance_pre.start(&mut self.store, &mut tracer)?; Ok(()) } WastExecute::Get { @@ -541,7 +544,8 @@ impl WastRunner { let len_results = func.ty(&self.store).results().len(); self.results.clear(); self.results.resize(len_results, Val::I32(0)); - func.call(&mut self.store, &self.params, &mut self.results[..])?; + let mut tracer = WasmTracer::no_tracing(); + func.call(&mut self.store, &self.params, &mut self.results[..], &mut tracer)?; Ok(()) } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 93446ccb41..caf786b0c0 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -14,6 +14,7 @@ cargo-fuzz = true wasmi_fuzz = { workspace = true } wasmi = { workspace = true, features = ["std", "simd"] } wasm-smith = { workspace = true } +wasmi_tracer = { workspace = true } libfuzzer-sys = "0.4.7" arbitrary = "1.3.2" wasmprinter = { workspace = true, optional = true } diff --git a/fuzz/fuzz_targets/execute.rs b/fuzz/fuzz_targets/execute.rs index a382aa32dc..65c45a4690 100644 --- a/fuzz/fuzz_targets/execute.rs +++ b/fuzz/fuzz_targets/execute.rs @@ -21,6 +21,7 @@ use wasmi_fuzz::{ FuzzValType, FuzzWasmiConfig, }; +use wasmi_tracer::WasmTracer; #[derive(Debug)] pub struct FuzzInput<'a> { @@ -111,7 +112,8 @@ fuzz_target!(|input: FuzzInput| { let func_ty = func.ty(&store); fill_values(&mut params, func_ty.params(), &mut u); fill_values(&mut results, func_ty.results(), &mut u); - _ = func.call(&mut store, ¶ms, &mut results); + let mut tracer = WasmTracer::no_tracing(); + _ = func.call(&mut store, ¶ms, &mut results, &mut tracer); } });