From f895e466f5f0384ea26b463a534c6d3056e4f2a0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 27 May 2019 22:27:20 +0100 Subject: [PATCH] Properly expose the debug API --- src/debug.rs | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index bb26520..5c20b9f 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,10 +1,37 @@ -/// The native debug interface exposed to the ewasm contract. These functions are for testing -/// purposes only. On a live VM, any bytecode trying to import these symbols will be rejected. -extern "C" { - pub fn debug_print32(value: u32); - pub fn debug_print64(value: u64); - pub fn debug_printMem(offset: *const u32, len: u32); - pub fn debug_printMemHex(offset: *const u32, len: u32); - pub fn debug_printStorage(pathOffset: *const u32); - pub fn debug_printStorageHex(pathOffset: *const u32); +//! The native debug interface exposed to the ewasm contract. These functions are for testing +//! purposes only. On a live VM, any bytecode trying to import these symbols will be rejected. + +mod native { + extern "C" { + pub fn debug_print32(value: u32); + pub fn debug_print64(value: u64); + pub fn debug_printMem(offset: *const u32, len: u32); + pub fn debug_printMemHex(offset: *const u32, len: u32); + pub fn debug_printStorage(pathOffset: *const u32); + pub fn debug_printStorageHex(pathOffset: *const u32); + } +} + +pub fn print32(value: u32) { + unsafe { native::debug_print32(value) } +} + +pub fn print64(value: u32) { + unsafe { native::debug_print64(value) } +} + +pub fn printMem(slice: &[u8]) { + unsafe { native::debug_printMem(slice.bytes.as_ptr() as *const u32, slice.len()) } +} + +pub fn printMemHex(slice: &[u8]) { + unsafe { native::debug_printMem(slice.bytes.as_ptr() as *const u32, slice.len()) } +} + +pub fn printStorage(key: &StorageKey) { + unsafe { native::debug_printStorage(key.bytes.as_ptr() as *const u32) } +} + +pub fn printStorageHex(key: &StorageKey) { + unsafe { native::debug_printStorageHex(key.bytes.as_ptr() as *const u32) } }