Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion language/move-stdlib/src/natives/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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);
}

Expand Down
18 changes: 18 additions & 0 deletions language/move-vm/types/src/values/values_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2305,6 +2307,22 @@ pub mod debug {
}
}

/// Prints a [Reference] with the given [TypeTag].
pub fn print_reference_with_type<B: Write>(
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<B: Write>(buf: &mut B, r: &Reference) -> PartialVMResult<()> {
match &r.0 {
ReferenceImpl::ContainerRef(r) => print_container_ref(buf, r),
Expand Down