Skip to content

Commit

Permalink
Update memories and globals field to be store_
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrainy committed Jul 27, 2023
1 parent b357c69 commit 5866e4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
31 changes: 17 additions & 14 deletions crates/wasmtime/src/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct WasmCoreDump {
name: String,
modules: Vec<String>,
instances: Vec<Instance>,
memories: Vec<Memory>,
globals: Vec<Global>,
store_memories: Vec<Memory>,
store_globals: Vec<Global>,
backtrace: WasmBacktrace,
}

Expand All @@ -43,14 +43,15 @@ impl WasmCoreDump {
.map(|m| String::from(m.name().unwrap_or_default()))
.collect();
let instances: Vec<Instance> = store.all_instances().collect();
let memories: Vec<Memory> = store.all_memories().collect();
let globals: Vec<Global> = store.all_globals().collect();
let store_memories: Vec<Memory> = store.all_memories().collect();
let store_globals: Vec<Global> = store.all_globals().collect();

WasmCoreDump {
name: String::from("store_name"),
modules,
instances,
memories,
globals,
store_memories,
store_globals,
backtrace,
}
}
Expand All @@ -70,14 +71,16 @@ impl WasmCoreDump {
self.instances.as_ref()
}

/// The globals involved in the CoreDump
pub fn globals(&self) -> &[Global] {
self.globals.as_ref()
/// The imported globals that belong to the store, rather than a specific
/// instance
pub fn store_globals(&self) -> &[Global] {
self.store_globals.as_ref()
}

/// The memories involve din the CoreDump
pub fn memories(&self) -> &[Memory] {
self.memories.as_ref()
/// The imported memories that belong to the store, rather than a specific
/// instance.
pub fn store_memories(&self) -> &[Memory] {
self.store_memories.as_ref()
}
}

Expand All @@ -95,12 +98,12 @@ impl fmt::Display for WasmCoreDump {
}

writeln!(f, "memories:")?;
for memory in self.memories.iter() {
for memory in self.store_memories.iter() {
writeln!(f, " {:?}", memory)?;
}

writeln!(f, "globals:")?;
for global in self.globals.iter() {
for global in self.store_globals.iter() {
writeln!(f, " {:?}", global)?;
}

Expand Down
21 changes: 15 additions & 6 deletions tests/all/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,38 @@ fn test_coredump_has_modules_and_instances() -> Result<()> {
}

#[test]
fn test_coredump_has_globals_and_memory() -> Result<()> {
fn test_coredump_has_import_globals_and_memory() -> Result<()> {
let mut config = Config::default();
config.coredump_on_trap(true);
let engine = Engine::new(&config).unwrap();
let mut store = Store::<()>::new(&engine, ());
let mut linker = Linker::new(&engine);

let wat = r#"
(module
(memory (export "memory") 2)
(global (export "myglobal") i32 (i32.const 65536))
(import "memory" "memory" (memory 1))
(global $myglobal (import "js" "global") (mut i32))
(func (export "a") (result i32)
unreachable
)
)
"#;

let module = Module::new(store.engine(), wat)?;
let instance = Instance::new(&mut store, &module, &[])?;
let m = wasmtime::Memory::new(&mut store, MemoryType::new(1, None))?;
linker.define(&mut store, "memory", "memory", m)?;
let g = wasmtime::Global::new(
&mut store,
GlobalType::new(ValType::I32, Mutability::Var),
Val::I32(0),
)?;
linker.define(&mut store, "js", "global", g)?;
let instance = linker.instantiate(&mut store, &module)?;
let a_func = instance.get_typed_func::<(), i32>(&mut store, "a")?;
let e = a_func.call(&mut store, ()).unwrap_err();
let cd = e.downcast_ref::<WasmCoreDump>().unwrap();
assert_eq!(cd.globals().len(), 1);
assert_eq!(cd.memories().len(), 1);
assert_eq!(cd.store_globals().len(), 1);
assert_eq!(cd.store_memories().len(), 1);

Ok(())
}

0 comments on commit 5866e4d

Please sign in to comment.