Skip to content

Commit

Permalink
add debug impl for wasmcoredump
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrainy committed Jul 7, 2023
1 parent 55fa2d2 commit 3fdef61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 11 additions & 11 deletions crates/wasmtime/src/coredump.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;

use crate::{store::StoreOpaque, FrameInfo, Global, Instance, Memory, WasmBacktrace};
use crate::{store::StoreOpaque, FrameInfo, Global, Instance, Memory, Module, WasmBacktrace};

/// Representation of a core dump of a WebAssembly module
///
Expand All @@ -24,10 +24,9 @@ use crate::{store::StoreOpaque, FrameInfo, Global, Instance, Memory, WasmBacktra
///
/// [`Func::call`]: crate::Func::call
/// [`Instance::new`]: crate::Instance::new
#[derive(Debug)]
pub struct WasmCoreDump {
name: String,
modules: Vec<String>,
modules: Vec<Module>,
instances: Vec<Instance>,
store_memories: Vec<Memory>,
store_globals: Vec<Global>,
Expand All @@ -36,12 +35,7 @@ pub struct WasmCoreDump {

impl WasmCoreDump {
pub(crate) fn new(store: &StoreOpaque, backtrace: WasmBacktrace) -> WasmCoreDump {
let modules: Vec<_> = store
.modules()
.all_modules()
.cloned()
.map(|m| String::from(m.name().unwrap_or_default()))
.collect();
let modules: Vec<_> = store.modules().all_modules().cloned().collect();
let instances: Vec<Instance> = store.all_instances().collect();
let store_memories: Vec<Memory> = store.all_memories().collect();
let store_globals: Vec<Global> = store.all_globals().collect();
Expand All @@ -62,7 +56,7 @@ impl WasmCoreDump {
}

/// The names of the modules involved in the CoreDump
pub fn modules(&self) -> &[String] {
pub fn modules(&self) -> &[Module] {
self.modules.as_ref()
}

Expand All @@ -89,7 +83,7 @@ impl fmt::Display for WasmCoreDump {
writeln!(f, "wasm coredump generated while executing {}:", self.name)?;
writeln!(f, "modules:")?;
for module in self.modules.iter() {
writeln!(f, " {}", module)?;
writeln!(f, " {}", module.name().unwrap_or("<module>"))?;
}

writeln!(f, "instances:")?;
Expand All @@ -113,3 +107,9 @@ impl fmt::Display for WasmCoreDump {
Ok(())
}
}

impl fmt::Debug for WasmCoreDump {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<wasm core dump>")
}
}
2 changes: 0 additions & 2 deletions tests/all/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ fn test_coredump_has_modules_and_instances() -> Result<()> {
let e = a_func.call(&mut store, ()).unwrap_err();
let cd = e.downcast_ref::<WasmCoreDump>().unwrap();
assert_eq!(cd.modules().len(), 2);
assert!(cd.modules().contains(&String::from("foo")));
assert!(cd.modules().contains(&String::from("bar")));
assert_eq!(cd.instances().len(), 2);
Ok(())
}
Expand Down

0 comments on commit 3fdef61

Please sign in to comment.