Skip to content

Commit dbaaa92

Browse files
authored
Debugging: add builtin gdbstub component. (#12771)
* Debugging: add builtin gdbstub component. This adds a debug component that makes use of the debug-main world defined in #12756 and serves the gdbstub protocol, with Wasm extensions, compatible with LLDB. This component is built and included inside the Wasmtime binary, and is loaded using the lower-level `-D debugger=...` debug-main option; the user doesn't need to specify the `.wasm` adapter component. Instead, the user simply runs `wasmtime run -g <PORT> program.wasm ...` and Wasmtime will load and prepare to run `program.wasm` as the debuggee, waiting for a gdbstub connection on the given TCP port before continuing. The workflow is: ``` $ wasmtime run -g 1234 program.wasm [ wasmtime starts and waits for connection ] $ /opt/wasi-sdk/bin/lldb # use LLDB from wasi-sdk release 32 or later (lldb) process connect --plugin wasm connect://localhost:1234 Process 1 stopped * thread #1, stop reason = signal SIGTRAP frame #0: 0x40000000000001cc -> 0x40000000000001cc: unreachable 0x40000000000001cd: end 0x40000000000001ce: local.get 0 0x40000000000001d0: call 13 (lldb) si Process 1 stopped * thread #1, stop reason = instruction step into frame #0: 0x4000000000000184 -> 0x4000000000000184: block 0x4000000000000186: block 0x4000000000000188: global.get 1 0x400000000000018e: i32.const 3664 [ ... ] ``` This makes use of the `gdbstub` third-party crate, into which I've upstreamed support for the Wasm extensions in daniel5151/gdbstub#188, daniel5151/gdbstub#189, daniel5151/gdbstub#190, and daniel5151/gdbstub#192. (I'll add vets as part of this PR.) * cargo vets. * Handle Trap events as well as breakpoints. * Review feedback. * Fix gdbstub artifact build to make it publishable (by disabling it when isolated crates are used). * Review feedback. * fix published-crates list * For now, empty gdbstub data but no compile error when artifact crate is published. * add some more Cargo metadata: version for artifact crate dep
1 parent 0ed1171 commit dbaaa92

19 files changed

Lines changed: 1503 additions & 46 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ jobs:
387387
-p wasmtime-cli --no-default-features --features compile,cranelift,component-model
388388
-p wasmtime-cli --no-default-features --features objdump
389389
-p wasmtime-cli --no-default-features --features wizer
390+
-p wasmtime-cli --no-default-features --features gdbstub
390391
-p wasmtime-cli --all-features
391392
-p wasmtime-cli --features component-model
392393

Cargo.lock

Lines changed: 132 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ wasmtime-wasi-http = { workspace = true, optional = true }
6161
wasmtime-unwinder = { workspace = true }
6262
wasmtime-wizer = { workspace = true, optional = true, features = ['clap', 'wasmtime'] }
6363
wasmtime-debugger = { workspace = true, optional = true }
64+
gdbstub-component-artifact = { workspace = true, optional = true }
6465
clap = { workspace = true }
6566
clap_complete = { workspace = true, optional = true }
6667
target-lexicon = { workspace = true }
@@ -166,6 +167,8 @@ members = [
166167
"crates/wasi-preview1-component-adapter",
167168
"crates/wasi-preview1-component-adapter/verify",
168169
"crates/debugger",
170+
"crates/gdbstub-component",
171+
"crates/gdbstub-component/artifact",
169172
"crates/wizer/fuzz",
170173
"crates/wizer/tests/regex-test",
171174
"crates/wizer/benches/regex-bench",
@@ -276,6 +279,7 @@ wasmtime-jit-icache-coherence = { path = "crates/jit-icache-coherence", version
276279
wasmtime-wit-bindgen = { path = "crates/wit-bindgen", version = "=44.0.0", package = 'wasmtime-internal-wit-bindgen' }
277280
wasmtime-unwinder = { path = "crates/unwinder", version = "=44.0.0", package = 'wasmtime-internal-unwinder' }
278281
wasmtime-debugger = { path = "crates/debugger", version = "=44.0.0", package = "wasmtime-internal-debugger" }
282+
gdbstub-component-artifact = { path = "crates/gdbstub-component/artifact", version = "=44.0.0", package = "wasmtime-internal-gdbstub-component-artifact" }
279283
wasmtime-wizer = { path = "crates/wizer", version = "44.0.0" }
280284

281285
# Miscellaneous crates without a `wasmtime-*` prefix in their name but still
@@ -354,6 +358,9 @@ wasm-wave = "0.245.0"
354358
wasm-compose = "0.245.0"
355359
json-from-wast = "0.245.0"
356360

361+
wstd = "0.6.5"
362+
wasip2 = "1.0"
363+
357364
# Non-Bytecode Alliance maintained dependencies:
358365
# --------------------------
359366
arbitrary = "1.4.2"
@@ -437,6 +444,8 @@ rayon = "1.5.3"
437444
regex = "1.9.1"
438445
pin-project-lite = "0.2.14"
439446
sha2 = { version = "0.10.2", default-features = false }
447+
gdbstub = "0.7.10"
448+
gdbstub_arch = "0.3.3"
440449

441450
# =============================================================================
442451
#
@@ -523,6 +532,11 @@ component-model-async = [
523532
]
524533
rr = ["wasmtime/rr", "component-model", "wasmtime-cli-flags/rr", "run"]
525534

535+
# Enabled in release builds. We cannot enable the built-in gdbstub component in
536+
# the default build because the published-to-crates.io crates cannot build the
537+
# artifact (a limitation caused by lack of artifact dependencies).
538+
gdbstub = ["debug", "dep:gdbstub-component-artifact"]
539+
526540
# This feature, when enabled, will statically compile out all logging statements
527541
# throughout Wasmtime and its dependencies.
528542
disable-logging = ["log/max_level_off", "tracing/max_level_off"]

ci/build-release-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if [[ "$build" = *-min ]]; then
5959
else
6060
# For release builds the CLI is built a bit more feature-ful than the Cargo
6161
# defaults to provide artifacts that can do as much as possible.
62-
bin_flags="--features all-arch,component-model"
62+
bin_flags="--features all-arch,component-model,gdbstub"
6363
fi
6464

6565
if [[ "$target" = "x86_64-pc-windows-msvc" ]]; then
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "wasmtime-internal-gdbstub-component"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license = "Apache-2.0 WITH LLVM-exception"
7+
description = "gdbstub debug-component adapter"
8+
publish = false
9+
10+
[lib]
11+
crate-type = ["cdylib"]
12+
13+
[dependencies]
14+
wit-bindgen = { workspace = true, features = ["macros"] }
15+
anyhow = { workspace = true }
16+
clap = { workspace = true }
17+
wstd = { workspace = true }
18+
wasip2 = { workspace = true }
19+
futures = { workspace = true, default-features = true }
20+
gdbstub = { workspace = true }
21+
gdbstub_arch = { workspace = true }
22+
log = { workspace = true }
23+
env_logger = { workspace = true }
24+
25+
[lints]
26+
workspace = true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "wasmtime-internal-gdbstub-component-artifact"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license = "Apache-2.0 WITH LLVM-exception"
7+
description = "gdbstub debug-component adapter"
8+
9+
[lints]
10+
workspace = true

0 commit comments

Comments
 (0)