-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn the debug feature into a macro.
- Loading branch information
Showing
4 changed files
with
176 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,93 @@ | ||
//! 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. | ||
|
||
use crate::types::StorageKey; | ||
|
||
/// The native interface for debugging functions. | ||
mod native { | ||
#[cfg(debug_assertions)] | ||
pub 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 debug_printStorage(path_offset: *const u32); | ||
pub fn debug_printStorageHex(path_offset: *const u32); | ||
} | ||
} | ||
|
||
#[macro_export] | ||
/// Prints an unsigned 32-bit int. | ||
pub fn print32(value: u32) { | ||
unsafe { native::debug_print32(value) } | ||
macro_rules! print32 { | ||
($value:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { $crate::debug::native::debug_print32($value) } | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
/// Prints an unsigned 64-bit int. | ||
pub fn print64(value: u64) { | ||
unsafe { native::debug_print64(value) } | ||
macro_rules! print64 { | ||
($value:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { $crate::debug::native::debug_print64($value) } | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
/// Prints the contents of a slice. | ||
pub fn print_mem(slice: &[u8]) { | ||
unsafe { native::debug_printMem(slice.as_ptr() as *const u32, slice.len() as u32) } | ||
macro_rules! print_mem { | ||
($slice:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { | ||
$crate::debug::native::debug_printMem( | ||
$slice.as_ptr() as *const u32, | ||
$slice.len() as u32, | ||
) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
/// Prints the contents of a slice in hexadecimal format. | ||
pub fn print_mem_hex(slice: &[u8]) { | ||
unsafe { native::debug_printMemHex(slice.as_ptr() as *const u32, slice.len() as u32) } | ||
macro_rules! print_mem_hex { | ||
($slice:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { | ||
$crate::debug::native::debug_printMemHex( | ||
$slice.as_ptr() as *const u32, | ||
$slice.len() as u32, | ||
) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
/// Prints the value of a storage key. | ||
pub fn print_storage(key: &StorageKey) { | ||
unsafe { native::debug_printStorage(key.bytes.as_ptr() as *const u32) } | ||
macro_rules! print_storage { | ||
($key:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { $crate::debug::native::debug_printStorage($key.bytes.as_ptr() as *const u32) } | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
/// Prints the value of a storage key in hexadecimal format. | ||
pub fn print_storage_hex(key: &StorageKey) { | ||
unsafe { native::debug_printStorageHex(key.bytes.as_ptr() as *const u32) } | ||
macro_rules! print_storage_hex { | ||
($key:expr) => { | ||
#[cfg(debug_assertions)] | ||
{ | ||
unsafe { | ||
$crate::debug::native::debug_printStorageHex($key.bytes.as_ptr() as *const u32) | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters