Skip to content

Commit

Permalink
Merge pull request #53 from ewasm/debug
Browse files Browse the repository at this point in the history
Properly expose the debug API
  • Loading branch information
axic authored May 28, 2019
2 parents 664a8f3 + f895e46 commit 083b5b8
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -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) }
}

0 comments on commit 083b5b8

Please sign in to comment.