mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-04-01 18:51:04 +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],
|
params: vec![elements::ValueType::I32],
|
||||||
result: Some(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 {
|
interpreter::UserFunction {
|
||||||
name: "gas".to_owned(),
|
name: "gas".to_owned(),
|
||||||
params: vec![elements::ValueType::I32],
|
params: vec![elements::ValueType::I32],
|
||||||
@ -93,7 +98,6 @@ fn main() {
|
|||||||
.add_argument(interpreter::RuntimeValue::I32(descriptor));
|
.add_argument(interpreter::RuntimeValue::I32(descriptor));
|
||||||
|
|
||||||
module_instance.execute_export("_call", params)
|
module_instance.execute_export("_call", params)
|
||||||
.expect("_call to execute successfully")
|
.expect("_call to execute successfully");
|
||||||
.expect("_call function to return result ptr");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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)
|
fn user_trap(&mut self, _context: interpreter::CallerContext)
|
||||||
-> Result<Option<interpreter::RuntimeValue>, interpreter::Error>
|
-> Result<Option<interpreter::RuntimeValue>, interpreter::Error>
|
||||||
{
|
{
|
||||||
@ -157,6 +169,9 @@ impl interpreter::UserFunctionExecutor for Runtime {
|
|||||||
"gas" => {
|
"gas" => {
|
||||||
self.gas(context)
|
self.gas(context)
|
||||||
},
|
},
|
||||||
|
"_debug" => {
|
||||||
|
self.debug(context)
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
self.user_trap(context)
|
self.user_trap(context)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user