Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

gdbstub artifact: handle empty artifact more gracefully. (#14544)

Chris Fallin174922ffc023
diff --git a/Cargo.lock b/Cargo.lock
index f46e75aef6..1c28eaeefc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4998,6 +4998,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-gdbstub-component-artifact"
version = "51.0.0-dev"
+dependencies = [
+ "wasmtime-internal-core",
+]
[[package]]
name = "wasmtime-internal-jit-debug"
diff --git a/crates/gdbstub-component/artifact/Cargo.toml b/crates/gdbstub-component/artifact/Cargo.toml
index b1db95f1d0..2b9a1a6725 100644
--- a/crates/gdbstub-component/artifact/Cargo.toml
+++ b/crates/gdbstub-component/artifact/Cargo.toml
@@ -8,3 +8,6 @@ description = "gdbstub debug-component adapter"
[lints]
workspace = true
+
+[dependencies]
+wasmtime-core = { workspace = true }
diff --git a/crates/gdbstub-component/artifact/build.rs b/crates/gdbstub-component/artifact/build.rs
index c39b43f116..ff1b67d298 100644
--- a/crates/gdbstub-component/artifact/build.rs
+++ b/crates/gdbstub-component/artifact/build.rs
@@ -13,7 +13,7 @@ fn main() {
if !PathBuf::from("../Cargo.toml").exists() {
std::fs::write(
out_dir.join("gen.rs"),
- "pub const GDBSTUB_COMPONENT: &[u8] = &[];\n",
+ "pub const GDBSTUB_COMPONENT: Option<&[u8]> = None;\n",
)
.unwrap();
return;
@@ -57,7 +57,8 @@ fn main() {
}
}
- let generated = format!("pub const GDBSTUB_COMPONENT: &[u8] = include_bytes!({wasm:?});\n");
+ let generated =
+ format!("pub const GDBSTUB_COMPONENT: Option<&[u8]> = Some(include_bytes!({wasm:?}));\n");
std::fs::write(out_dir.join("gen.rs"), generated).unwrap();
}
diff --git a/crates/gdbstub-component/artifact/src/lib.rs b/crates/gdbstub-component/artifact/src/lib.rs
index 26a930a60e..b98efa0ab0 100644
--- a/crates/gdbstub-component/artifact/src/lib.rs
+++ b/crates/gdbstub-component/artifact/src/lib.rs
@@ -1 +1,14 @@
+use wasmtime_core::{error::Result, format_err};
+
include!(concat!(env!("OUT_DIR"), "/gen.rs"));
+
+/// Get the included gdbstub-adapter component artifact, or an error
+/// if it is not included in this build.
+pub fn gdbstub() -> Result<&'static [u8]> {
+ crate::GDBSTUB_COMPONENT.ok_or_else(|| {
+ format_err!(concat!(
+ "gdbstub component not included in this build. Please build ",
+ "in-tree with `--features gdbstub` or use release binaries.",
+ ))
+ })
+}
diff --git a/docs/cli-install.md b/docs/cli-install.md
index 2b5dc89915..0831f55894 100644
--- a/docs/cli-install.md
+++ b/docs/cli-install.md
@@ -80,11 +80,12 @@ You can also use [`binstall`](https://github.com/cargo-bins/cargo-binstall) to a
cargo binstall wasmtime-cli
```
-Note that while the above binaries are *almost* identical, the release binaries
-installed by `binstall` include the `gdbstub` debugging feature while the
-default feature set in the `wasmtime-cli` crate, used by `cargo install`, does
-not. This is due to a Cargo limitation when building from published crates
-rather than the Wasmtime source tree.
+*Important note on Wasm debugging*: Note that while the above binaries are
+*almost* identical, the release binaries installed by `binstall` include the
+`gdbstub` debugging feature while the default feature set in the `wasmtime-cli`
+crate, used by `cargo install`, does not. Due to technical Cargo limitations,
+`cargo install` cannot work with `--features gdbstub` when building from
+published crates. If you need debugging support, we recommend using `binstall`.
## Compiling from Source
diff --git a/docs/examples-debugging-guest.md b/docs/examples-debugging-guest.md
index 7a6fdb8299..d70b2b0675 100644
--- a/docs/examples-debugging-guest.md
+++ b/docs/examples-debugging-guest.md
@@ -16,8 +16,11 @@ single instruction stepping at the Wasm bytecode level.
2. Ensure that you have a build of Wasmtime that has the `gdbstub`
feature enabled, which is off by default:
- - Published CLI binary releases already have this feature.
- - If building from source, use `cargo build --features gdbstub`.
+ - Published CLI binary releases (downloaded manually, via our install
+ script, or `cargo binstall`) already have this feature.
+ - If building from source *in-tree*, use `cargo build --features gdbstub`.
+ (Note that this feature flag does not work when building from published
+ crates with `cargo install`.)
3. Run Wasmtime, enabling the gdbstub server:
diff --git a/src/commands/run.rs b/src/commands/run.rs
index 501374b52c..8dfb6c93b3 100644
--- a/src/commands/run.rs
+++ b/src/commands/run.rs
@@ -131,7 +131,7 @@ impl RunCommand {
};
self.run.common.debug.debugger = Some("<built-in gdbstub>".into());
self.run.common.debug.arg.push(addr);
- Some(gdbstub_component_artifact::GDBSTUB_COMPONENT)
+ Some(gdbstub_component_artifact::gdbstub()?)
} else {
None
};
diff --git a/src/commands/serve.rs b/src/commands/serve.rs
index 519729810c..6c74477a05 100644
--- a/src/commands/serve.rs
+++ b/src/commands/serve.rs
@@ -269,7 +269,7 @@ impl ServeCommand {
};
self.run.common.debug.debugger = Some("<built-in gdbstub>".into());
self.run.common.debug.arg.push(addr);
- Some(gdbstub_component_artifact::GDBSTUB_COMPONENT)
+ Some(gdbstub_component_artifact::gdbstub()?)
} else {
None
};