#wasm-module #coredump #rewrite

bin+lib wasm-coredump-rewriter

Rewrite Wasm binaries to add coredump support

21 releases

0.2.2 Dec 31, 2024
0.2.1 Nov 25, 2024
0.1.24 Nov 14, 2024
0.1.22 Aug 7, 2023
0.1.12 Mar 6, 2023

#1067 in WebAssembly

Download history 1/week @ 2024-09-18 8/week @ 2024-09-25 3/week @ 2024-10-02 237/week @ 2024-11-13 141/week @ 2024-11-20 38/week @ 2024-11-27 42/week @ 2024-12-04 12/week @ 2024-12-11 75/week @ 2024-12-25 47/week @ 2025-01-01

141 downloads per month
Used in wasmgdb

MIT license

175KB
4K SLoC

wasm-coredump-rewriter

wasm-coredump-rewriter is used to add Coredump generation to a compiled Wasm module.

Installation

cargo install wasm-coredump-rewriter

Usage

Rewrite Wasm binaries to add coredump support

Usage: wasm-coredump-rewriter [OPTIONS]

Options:
      --check-memory-operations    Wraps each memory operation. This will likely reduce significantly your program's performance
      --debug                      Enable debugging, mostly useful for developing this tooling
      --instance-id <INSTANCE_ID>  Specify the instance index to use in stack frames. MUST match the order in which instances are instantiated at runtime [default: 0]
  -h, --help                       Print help
  -V, --version                    Print version

Step 1: rewrite the Wasm module

Rewrite the source Wasm module to inject the Coredump runtime code. The runtime will catch traps (excluding traps in host functions or memory violations) and generate a coredump.

Use the following command:

wasm-coredump-rewriter < source.wasm > output.wasm

The Coredump runtime has a performance cost.

Step 2: Wasm execution trapped

Your program entered a trap and a Coredump was generated.

To extract the Coredump write the Wasm instance memory to a file, for instance in JavaScript:

const instance = await WebAssembly.instantiate(...);

try {
    wasi.start(instance);
} catch(err) {
    const image = new Uint8Array(instance.exports.memory.buffer);
    writeFile("coredump." + Date.now(), image);
}

Step 3: analyzing / debugging the coredump

See wasmgdb for analyzing / debugging the coredump.

Dependencies

~6–15MB
~181K SLoC