diff --git a/core-backend/src/funcs.rs b/core-backend/src/funcs.rs index 8acd5529c52..df226376569 100644 --- a/core-backend/src/funcs.rs +++ b/core-backend/src/funcs.rs @@ -30,7 +30,7 @@ use crate::{ }; use alloc::string::{String, ToString}; use blake2_rfc::blake2b::blake2b; -use core::marker::PhantomData; +use core::{fmt, marker::PhantomData}; use gear_core::{ buffer::{RuntimeBuffer, RuntimeBufferSizeError}, costs::RuntimeCosts, @@ -51,41 +51,44 @@ use gsys::{ HashWithValue, TwoHashesWithValue, }; -#[macro_export(local_inner_macros)] -macro_rules! syscall_args_trace { - ($val:expr) => { - { - let s = ::core::stringify!($val); - if s.ends_with("_ptr") { - alloc::format!(", {} = {:#x?}", s, $val) - } else { - alloc::format!(", {} = {:?}", s, $val) - } - } - }; - ($val:expr, $($rest:expr),+) => { - { - let mut s = syscall_args_trace!($val); - s.push_str(&syscall_args_trace!($($rest),+)); - s +const PTR_SPECIAL: u32 = u32::MAX; + +struct ValueFormatter<'a>(&'a Value); + +impl fmt::Display for ValueFormatter<'_> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self.0 { + Value::I32(i32) => fmt::Display::fmt(i32, f), + Value::I64(i64) => fmt::Display::fmt(i64, f), + Value::F32(f32) => fmt::Display::fmt(f32, f), + Value::F64(f64) => fmt::Display::fmt(f64, f), } - }; + } } -macro_rules! syscall_trace { - ($name:expr, $($args:expr),+) => { - { - ::log::trace!(target: "syscalls", "{}{}", $name, syscall_args_trace!($($args),+)); +struct ArgsFormatter<'a>(&'a [Value]); + +impl fmt::Display for ArgsFormatter<'_> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut iter = self.0.iter(); + + if let Some(value) = iter.next() { + write!(f, "{}", ValueFormatter(value))?; } - }; - ($name:expr) => { - { - ::log::trace!(target: "syscalls", "{}", $name); + + for value in iter { + write!(f, ", {}", ValueFormatter(value))?; } + + Ok(()) } } -const PTR_SPECIAL: u32 = u32::MAX; +fn function_name() -> &'static str { + let s = core::any::type_name::(); + let pos = s.rfind("::").unwrap(); + &s[pos + 2..] +} /// Actually just wrapper around [`Value`] to implement conversions. #[derive(Clone, Copy)] @@ -345,6 +348,8 @@ where S: SysCall, R: Into, { + log::trace!(target: "syscalls", "{}({})", function_name::(), ArgsFormatter(args)); + let (ctx, args) = S::Context::from_args(args)?; let sys_call = SysCallBuilder::build(handler, args)?; let (gas, value) = sys_call.execute(caller, ctx)?;