Skip to content

Commit e10bd43

Browse files
cfallinfitzgen
andauthored
Debugging: add docs to describe how to perform guest debugging. (#13097)
* Debugging: add docs to describe how to perform guest debugging. * Update docs/examples-debugging-guest.md Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com> --------- Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
1 parent bc82e7a commit e10bd43

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

docs/examples-debugging-guest.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Guest (Wasm-only) Debugging with `lldb`
2+
3+
The following steps describe how to use `lldb` to debug the Wasm guest
4+
on its own -- as if it were running on a virtual Wasm-instruction-set
5+
computer with hostcalls as single-step indivisible actions. This
6+
functionality, called "guest debugging", allows for disassembly and
7+
single instruction stepping at the Wasm bytecode level.
8+
9+
1. Compile your WebAssembly with debug info enabled, usually `-g`; for
10+
example:
11+
12+
```console
13+
clang foo.c -g -o foo.wasm
14+
```
15+
16+
2. Ensure that you have a build of Wasmtime that has the `gdbstub`
17+
feature enabled, which is off by default:
18+
19+
- Published CLI binary releases already have this feature.
20+
- If building from source, use `cargo build --features gdbstub`.
21+
22+
3. Run Wasmtime, enabling the gdbstub server:
23+
24+
```console
25+
wasmtime run -g 1234 foo.wasm
26+
27+
Debugger: Debugger listening on 127.0.0.1:1234
28+
Debugger: In LLDB, attach with: process connect --plugin wasm connect://127.0.0.1:1234
29+
```
30+
31+
This will start a "debug server" waiting on local TCP port 1234 for
32+
a debugger to connect. Execution will not start until the debugger
33+
connects and issues a "continue" command.
34+
35+
4. Run LLDB, connect and debug.
36+
37+
You'll need a recent version of LLDB (v32 or later) with Wasm
38+
support enabled. The [wasi-sdk] distribution provides such a
39+
build.
40+
41+
```console
42+
/opt/wasi-sdk/bin/lldb
43+
(lldb) process connect --plugin wasm connect://0:1234
44+
Process 1 stopped
45+
* thread #1, stop reason = signal SIGTRAP
46+
frame #0: 0x00000000
47+
error: memory read failed for 0x0
48+
(lldb) b my_function
49+
(lldb) continue
50+
```
51+
52+
and use LLDB like normal, setting breakpoints, continuing and
53+
stepping, examining memory and variable state, etc.
54+
55+
This functionality should work on any platform that Wasmtime runs on:
56+
debugging is based on code instrumentation, so does not depend on any
57+
native system debugging interfaces or introspection capabilities; and
58+
is supported on all native-compilation ISAs and on Pulley, Wasmtime's
59+
bytecode platform that runs everywhere.
60+
61+
[wasi-sdk]: https://github.com/WebAssembly/wasi-sdk/

docs/examples-debugging-native-debugger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Debugging with `gdb` and `lldb`
1+
# Native (Wasm + runtime) Debugging with `gdb` and `lldb`
22

33
The following steps describe how to use `gdb` or `lldb` to debug both the Wasm
44
guest and the host (i.e. the Wasmtime CLI or your Wasmtime-embedding program) at

docs/examples-debugging.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Wasmtime currently provides the following support for debugging misbehaving
44
WebAssembly:
55

6+
* We can [live debug and step through the guest Wasm on its
7+
own.](./examples-debugging-guest.md)
8+
69
* We can [live debug and step through the guest Wasm and the host at the same
710
time with `gdb` or `lldb`.](./examples-debugging-native-debugger.md)
811

0 commit comments

Comments
 (0)