mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Add an optional Wasm debug feature - hex memory dump
This commit is contained in:
parent
1ba654c5b2
commit
760f4c0ed4
1 changed files with 29 additions and 0 deletions
|
@ -4,6 +4,7 @@ use std::cell::Cell;
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use tempfile::{tempdir, TempDir};
|
use tempfile::{tempdir, TempDir};
|
||||||
|
use wasmer::Memory;
|
||||||
|
|
||||||
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
|
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
|
||||||
use crate::helpers::wasm32_test_result::Wasm32TestResult;
|
use crate::helpers::wasm32_test_result::Wasm32TestResult;
|
||||||
|
@ -244,6 +245,10 @@ where
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if false {
|
||||||
|
crate::helpers::wasm::debug_memory_hex(memory, address, std::mem::size_of::<T>());
|
||||||
|
}
|
||||||
|
|
||||||
let output = <T as FromWasm32Memory>::decode(memory, address as u32);
|
let output = <T as FromWasm32Memory>::decode(memory, address as u32);
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
@ -251,6 +256,30 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print out hex bytes of the test result, and a few words on either side
|
||||||
|
/// Can be handy for debugging misalignment issues etc.
|
||||||
|
pub fn debug_memory_hex(memory: &Memory, address: i32, size: usize) {
|
||||||
|
let memory_words: &[u32] = unsafe {
|
||||||
|
let memory_bytes = memory.data_unchecked();
|
||||||
|
std::mem::transmute(memory_bytes)
|
||||||
|
};
|
||||||
|
|
||||||
|
let extra_words = 2;
|
||||||
|
let offset = (address as usize) / 4;
|
||||||
|
let start = offset - extra_words;
|
||||||
|
let end = offset + (size / 4) + extra_words;
|
||||||
|
|
||||||
|
for index in start..end {
|
||||||
|
let result_marker = if index == offset { "*" } else { " " };
|
||||||
|
println!(
|
||||||
|
"{:x} {} {:08x}",
|
||||||
|
index * 4,
|
||||||
|
result_marker,
|
||||||
|
memory_words[index]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! assert_wasm_evals_to {
|
macro_rules! assert_wasm_evals_to {
|
||||||
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue