mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
wasm_interp: dump a stack trace on error
This commit is contained in:
parent
5bdd1b5628
commit
6d43763ab7
4 changed files with 194 additions and 20 deletions
|
@ -7,7 +7,7 @@ pub mod wasi;
|
|||
// Main external interface
|
||||
pub use instance::Instance;
|
||||
|
||||
use roc_wasm_module::{Value, ValueType};
|
||||
use roc_wasm_module::{Value, ValueType, WasmModule};
|
||||
use value_stack::ValueStack;
|
||||
use wasi::WasiDispatcher;
|
||||
|
||||
|
@ -74,3 +74,18 @@ impl Error {
|
|||
Error::ValueStackType(expected, ty)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which function the program counter is in
|
||||
pub(crate) fn pc_to_fn_index(program_counter: usize, module: &WasmModule<'_>) -> usize {
|
||||
if module.code.function_offsets.is_empty() {
|
||||
0
|
||||
} else {
|
||||
let next_code_section_index = module
|
||||
.code
|
||||
.function_offsets
|
||||
.iter()
|
||||
.position(|o| *o as usize > program_counter)
|
||||
.unwrap_or(module.code.function_offsets.len());
|
||||
module.import.imports.len() + next_code_section_index - 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue