Finished middleware impl and made a CallTrace middleware

This commit is contained in:
losfair
2019-04-27 16:31:47 +08:00
parent eca8ccdbd4
commit 2262c8a6da
11 changed files with 266 additions and 109 deletions

View File

@ -0,0 +1,27 @@
use wasmer_runtime_core::{
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
module::ModuleInfo,
};
pub struct CallTrace;
impl FunctionMiddleware for CallTrace {
type Error = String;
fn feed_event<'a, 'b: 'a>(
&mut self,
op: Event<'a, 'b>,
module_info: &ModuleInfo,
sink: &mut EventSink<'a, 'b>,
) -> Result<(), Self::Error> {
match op {
Event::Internal(InternalEvent::FunctionBegin(id)) => {
sink.push(Event::Internal(InternalEvent::Bkpt(Box::new(move |_| {
println!("func ({})", id);
}))))
}
_ => {}
}
sink.push(op);
Ok(())
}
}

View File

@ -0,0 +1,9 @@
pub mod call_trace;
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}