wasm_interp: dump a stack trace on error

This commit is contained in:
Brian Carroll 2022-12-04 23:26:45 +00:00
parent 5bdd1b5628
commit 6d43763ab7
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
4 changed files with 194 additions and 20 deletions

View file

@ -199,6 +199,14 @@ impl<'a> ValueStack<'a> {
pub(crate) fn get_slice<'b>(&'b self, index: usize) -> ValueStackSlice<'a, 'b> {
ValueStackSlice { stack: self, index }
}
pub(crate) fn iter<'b>(&'b self) -> ValueStackIter<'a, 'b> {
ValueStackIter {
stack: self,
index: 0,
bytes_index: 0,
}
}
}
impl Debug for ValueStack<'_> {
@ -218,6 +226,29 @@ impl Debug for ValueStackSlice<'_, '_> {
}
}
pub struct ValueStackIter<'a, 'b> {
stack: &'b ValueStack<'a>,
index: usize,
bytes_index: usize,
}
impl Iterator for ValueStackIter<'_, '_> {
type Item = Value;
fn next(&mut self) -> Option<Self::Item> {
if self.index >= self.stack.is_64.len() {
None
} else {
let is_64 = self.stack.is_64[self.index];
let is_float = self.stack.is_float[self.index];
let value = self.stack.get(is_64, is_float, self.bytes_index);
self.index += 1;
self.bytes_index += if is_64 { 8 } else { 4 };
Some(value)
}
}
}
#[cfg(test)]
mod tests {
use super::*;