debug logging in runtime

This commit is contained in:
NikVolf 2017-05-25 22:16:13 +03:00
parent a2922a6fb0
commit 080d9e6b7f
2 changed files with 21 additions and 2 deletions

View File

@ -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");
}
}

View File

@ -124,6 +124,18 @@ impl Runtime {
}
}
fn debug(&mut self, context: interpreter::CallerContext)
-> Result<Option<interpreter::RuntimeValue>, interpreter::Error>
{
let msg_len = context.value_stack.pop_as::<i32>()? as u32;
let msg_ptr = context.value_stack.pop_as::<i32>()? 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<Option<interpreter::RuntimeValue>, interpreter::Error>
{
@ -157,6 +169,9 @@ impl interpreter::UserFunctionExecutor for Runtime {
"gas" => {
self.gas(context)
},
"_debug" => {
self.debug(context)
},
_ => {
self.user_trap(context)
}