mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-16 03:20:50 +00:00
debug logging in runtime
This commit is contained in:
parent
a2922a6fb0
commit
080d9e6b7f
@ -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");
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user