File: examples-coredump.md

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 48,504 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (62 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Using Wasm coredump

The following steps describe how to debug using Wasm coredump in Wasmtime:

1. Compile your WebAssembly with debug info enabled; for example:

    ```sh
    $ rustc foo.rs --target=wasm32-wasip1 -C debuginfo=2
    ```

<details>
    <summary>foo.rs</summary>

    fn c(v: usize) {
        a(v - 3);
    }

    fn b(v: usize) {
        c(v - 3);
    }

    fn a(v: usize) {
        b(v - 3);
    }

    pub fn main() {
        a(10);
    }
</details>

2. Run with Wasmtime and Wasm coredump enabled:

    ```sh
    $ wasmtime -D coredump=/tmp/coredump foo.wasm

    thread 'main' panicked at 'attempt to subtract with overflow', foo.rs:10:7
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    Error: failed to run main module `foo.wasm`

    Caused by:
        0: Core dumped at /tmp/coredump
        1: failed to invoke command default
        2: error while executing at wasm backtrace:
                    ...
    ```

3. Use [wasmgdb] to debug:
    ```sh
    $ wasmgdb foo.wasm /tmp/coredump

    wasmgdb> bt
    ...
    #13     000175 as panic () at library/core/src/panicking.rs
    #12     000010 as a (v=???) at /path/to/foo.rs
    #11     000009 as c (v=???) at /path/to/foo.rs
    #10     000011 as b (v=???) at /path/to/foo.rs
    #9      000010 as a (v=???) at /path/to/foo.rs
    #8      000012 as main () at /path/to/foo.rs
    ...
    ```

[wasmgdb]: https://crates.io/crates/wasmgdb