From 080d9e6b7f9753abd6e5c216d70f09f1abab427c Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 25 May 2017 22:16:13 +0300 Subject: [PATCH] debug logging in runtime --- rust-runner/src/main.rs | 8 ++++++-- rust-runner/src/runtime.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/rust-runner/src/main.rs b/rust-runner/src/main.rs index 4bb561e..dd432f2 100644 --- a/rust-runner/src/main.rs +++ b/rust-runner/src/main.rs @@ -74,6 +74,11 @@ fn main() { params: vec![elements::ValueType::I32], result: Some(elements::ValueType::I32), }, + interpreter::UserFunction { + name: "_debug".to_owned(), + params: vec![elements::ValueType::I32, elements::ValueType::I32], + result: None, + }, interpreter::UserFunction { name: "gas".to_owned(), params: vec![elements::ValueType::I32], @@ -93,7 +98,6 @@ fn main() { .add_argument(interpreter::RuntimeValue::I32(descriptor)); module_instance.execute_export("_call", params) - .expect("_call to execute successfully") - .expect("_call function to return result ptr"); + .expect("_call to execute successfully"); } } \ No newline at end of file diff --git a/rust-runner/src/runtime.rs b/rust-runner/src/runtime.rs index 4cdc84b..58ffa79 100644 --- a/rust-runner/src/runtime.rs +++ b/rust-runner/src/runtime.rs @@ -124,6 +124,18 @@ impl Runtime { } } + fn debug(&mut self, context: interpreter::CallerContext) + -> Result, interpreter::Error> + { + let msg_len = context.value_stack.pop_as::()? as u32; + let msg_ptr = context.value_stack.pop_as::()? as u32; + + let msg = unsafe { String::from_utf8_unchecked(self.memory.get(msg_ptr, msg_len as usize)?) }; + println!("DEBUG: {}", msg); + + Ok(None) + } + fn user_trap(&mut self, _context: interpreter::CallerContext) -> Result, interpreter::Error> { @@ -157,6 +169,9 @@ impl interpreter::UserFunctionExecutor for Runtime { "gas" => { self.gas(context) }, + "_debug" => { + self.debug(context) + }, _ => { self.user_trap(context) }