diff --git a/language/move-stdlib/src/natives/debug.rs b/language/move-stdlib/src/natives/debug.rs index b2c4701854..9f92758e14 100644 --- a/language/move-stdlib/src/natives/debug.rs +++ b/language/move-stdlib/src/natives/debug.rs @@ -6,6 +6,8 @@ use move_binary_format::errors::PartialVMResult; use move_core_types::gas_schedule::ONE_GAS_UNIT; use move_vm_runtime::native_functions::NativeContext; #[allow(unused_imports)] +use move_vm_types::values::debug::print_reference_with_type; +#[allow(unused_imports)] use move_vm_types::values::{values_impl::debug::print_reference, Reference}; #[allow(unused_imports)] use move_vm_types::{ @@ -30,8 +32,9 @@ pub fn native_print( let ty = ty_args.pop().unwrap(); let r = pop_arg!(args, Reference); + let type_tag = context.type_to_type_tag(&ty)?; let mut buf = String::new(); - print_reference(&mut buf, &r)?; + print_reference_with_type(&mut buf, &type_tag, &r)?; println!("[debug] {}", buf); } diff --git a/language/move-vm/types/src/values/values_impl.rs b/language/move-vm/types/src/values/values_impl.rs index 1398c75136..55570ad516 100644 --- a/language/move-vm/types/src/values/values_impl.rs +++ b/language/move-vm/types/src/values/values_impl.rs @@ -2180,6 +2180,8 @@ impl Display for Locals { #[allow(dead_code)] pub mod debug { + use move_core_types::language_storage::TypeTag; + use super::*; use std::fmt::Write; @@ -2305,6 +2307,22 @@ pub mod debug { } } + /// Prints a [Reference] with the given [TypeTag]. + pub fn print_reference_with_type( + buf: &mut B, + type_tag: &TypeTag, + r: &Reference, + ) -> PartialVMResult<()> { + write!(buf, "[{}] ", &type_tag).map_err(|_| { + PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) + .with_message("debug print - could not print type tag".to_string()) + })?; + match &r.0 { + ReferenceImpl::ContainerRef(r) => print_container_ref(buf, r), + ReferenceImpl::IndexedRef(r) => print_indexed_ref(buf, r), + } + } + pub fn print_reference(buf: &mut B, r: &Reference) -> PartialVMResult<()> { match &r.0 { ReferenceImpl::ContainerRef(r) => print_container_ref(buf, r),