mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
find and print the error message on panic
This commit is contained in:
parent
3ce8527ec1
commit
cc4f88b0e4
2 changed files with 17 additions and 19 deletions
|
@ -203,7 +203,6 @@ where
|
||||||
|
|
||||||
let wasm_bytes = crate::helpers::wasm::compile_to_wasm_bytes(&arena, src, phantom);
|
let wasm_bytes = crate::helpers::wasm::compile_to_wasm_bytes(&arena, src, phantom);
|
||||||
|
|
||||||
use wasm3::error::Trap;
|
|
||||||
use wasm3::Environment;
|
use wasm3::Environment;
|
||||||
use wasm3::Module;
|
use wasm3::Module;
|
||||||
|
|
||||||
|
@ -244,7 +243,8 @@ where
|
||||||
let (_, memory_size) = std::mem::transmute::<_, (usize, usize)>(memory_ptr);
|
let (_, memory_size) = std::mem::transmute::<_, (usize, usize)>(memory_ptr);
|
||||||
std::slice::from_raw_parts(memory_ptr as _, memory_size)
|
std::slice::from_raw_parts(memory_ptr as _, memory_size)
|
||||||
};
|
};
|
||||||
let msg_bytes = &memory[msg_ptr as usize..][msg_len as usize..];
|
|
||||||
|
let msg_bytes = &memory[msg_ptr as usize..][..msg_len as usize];
|
||||||
let msg = std::str::from_utf8(msg_bytes).unwrap();
|
let msg = std::str::from_utf8(msg_bytes).unwrap();
|
||||||
|
|
||||||
Err(format!("Roc failed with message: \"{}\"", msg))
|
Err(format!("Roc failed with message: \"{}\"", msg))
|
||||||
|
@ -253,21 +253,21 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(address) => {
|
Ok(address) => {
|
||||||
// if false {
|
|
||||||
// println!("test_wrapper returned 0x{:x}", address);
|
|
||||||
// println!("Stack:");
|
|
||||||
// crate::helpers::wasm::debug_memory_hex(memory, address, std::mem::size_of::<T>());
|
|
||||||
// }
|
|
||||||
// if false {
|
|
||||||
// println!("Heap:");
|
|
||||||
// // Manually provide address and size based on printf in wasm_test_platform.c
|
|
||||||
// crate::helpers::wasm::debug_memory_hex(memory, 0x11440, 24);
|
|
||||||
// }
|
|
||||||
|
|
||||||
let (_, memory_size) = unsafe { std::mem::transmute::<_, (usize, usize)>(rt.memory()) };
|
let (_, memory_size) = unsafe { std::mem::transmute::<_, (usize, usize)>(rt.memory()) };
|
||||||
let memory: &[u8] =
|
let memory: &[u8] =
|
||||||
unsafe { std::slice::from_raw_parts(rt.memory() as _, memory_size) };
|
unsafe { std::slice::from_raw_parts(rt.memory() as _, memory_size) };
|
||||||
|
|
||||||
|
if false {
|
||||||
|
println!("test_wrapper returned 0x{:x}", address);
|
||||||
|
println!("Stack:");
|
||||||
|
crate::helpers::wasm::debug_memory_hex(memory, address, std::mem::size_of::<T>());
|
||||||
|
}
|
||||||
|
if false {
|
||||||
|
println!("Heap:");
|
||||||
|
// Manually provide address and size based on printf in wasm_test_platform.c
|
||||||
|
crate::helpers::wasm::debug_memory_hex(memory, 0x11440, 24);
|
||||||
|
}
|
||||||
|
|
||||||
let output = <T as FromWasm32Memory>::decode(memory, address as u32);
|
let output = <T as FromWasm32Memory>::decode(memory, address as u32);
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
@ -366,11 +366,9 @@ where
|
||||||
|
|
||||||
/// Print out hex bytes of the test result, and a few words on either side
|
/// Print out hex bytes of the test result, and a few words on either side
|
||||||
/// Can be handy for debugging misalignment issues etc.
|
/// Can be handy for debugging misalignment issues etc.
|
||||||
pub fn debug_memory_hex(memory: &Memory, address: i32, size: usize) {
|
pub fn debug_memory_hex(memory_bytes: &[u8], address: i32, size: usize) {
|
||||||
let memory_words: &[u32] = unsafe {
|
let memory_words: &[u32] =
|
||||||
let memory_bytes = memory.data_unchecked();
|
unsafe { std::slice::from_raw_parts(memory_bytes.as_ptr().cast(), memory_bytes.len() / 4) };
|
||||||
std::mem::transmute(memory_bytes)
|
|
||||||
};
|
|
||||||
|
|
||||||
let extra_words = 2;
|
let extra_words = 2;
|
||||||
let result_start = (address as usize) / 4;
|
let result_start = (address as usize) / 4;
|
||||||
|
|
|
@ -123,7 +123,7 @@ void roc_dealloc(void *ptr, unsigned int alignment)
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
|
||||||
extern void send_panic_msg_to_rust(char* msg, int len) {
|
extern void send_panic_msg_to_rust(char* msg, int len);
|
||||||
|
|
||||||
void roc_panic(char *msg, unsigned int tag_id)
|
void roc_panic(char *msg, unsigned int tag_id)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue