1# Using Wasm coredump
2
3The following steps describe how to debug using Wasm coredump in Wasmtime:
4
51. Compile your WebAssembly with debug info enabled; for example:
6
7    ```console
8    rustc foo.rs --target=wasm32-wasip1 -C debuginfo=2
9    ```
10
11<details>
12    <summary>foo.rs</summary>
13
14    fn c(v: usize) {
15        a(v - 3);
16    }
17
18    fn b(v: usize) {
19        c(v - 3);
20    }
21
22    fn a(v: usize) {
23        b(v - 3);
24    }
25
26    pub fn main() {
27        a(10);
28    }
29</details>
30
312. Run with Wasmtime and Wasm coredump enabled:
32
33    ```shell-session
34    $ wasmtime -D coredump=/tmp/coredump foo.wasm
35
36    thread 'main' panicked at 'attempt to subtract with overflow', foo.rs:10:7
37    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
38    Error: failed to run main module `foo.wasm`
39
40    Caused by:
41        0: Core dumped at /tmp/coredump
42        1: failed to invoke command default
43        2: error while executing at wasm backtrace:
44                    ...
45    ```
46
473. Use [wasmgdb] to debug:
48    ```shell-session
49    $ wasmgdb foo.wasm /tmp/coredump
50
51    wasmgdb> bt
52    ...
53    #13     000175 as panic () at library/core/src/panicking.rs
54    #12     000010 as a (v=???) at /path/to/foo.rs
55    #11     000009 as c (v=???) at /path/to/foo.rs
56    #10     000011 as b (v=???) at /path/to/foo.rs
57    #9      000010 as a (v=???) at /path/to/foo.rs
58    #8      000012 as main () at /path/to/foo.rs
59    ...
60    ```
61
62[wasmgdb]: https://crates.io/crates/wasmgdb
63