Skip to content

Commit 4c7c01d

Browse files
authored
Debugging: add debugger support for wasmtime serve. (#12859)
This adopts a simple solution to #12776: it takes the "instance reuse" paradigm to the extreme, instantiating exactly one instance and serializing all requests into that one instance. This allows the debugger component to operate on one `Store`, setting breakpoint state and presenting its execution to the attached debugger as a single program execution and minimizing impedance mismatches. This also adds an integration test that runs an existing wasi-http test component under the debugger.
1 parent da36d99 commit 4c7c01d

5 files changed

Lines changed: 498 additions & 10 deletions

File tree

crates/wasmtime/src/runtime/debug.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ impl<'a> BreakpointEdit<'a> {
11021102
*refcount += 1;
11031103
if *refcount == 1 {
11041104
// First reference: actually patch the code.
1105-
log::trace!("patching in breakpoint {actual_key:?}");
11061105
let mem =
11071106
Self::get_code_memory(self.state, self.registry, &mut self.dirty_modules, module)?;
11081107
let patches = frame_table.lookup_breakpoint_patches_by_pc(actual_pc);

crates/wasmtime/src/runtime/vm/libcalls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,6 @@ fn throw_ref(
17551755
fn breakpoint(store: &mut dyn VMStore, _instance: InstanceId) -> Result<()> {
17561756
#[cfg(feature = "debug")]
17571757
{
1758-
log::trace!("hit breakpoint");
17591758
store.block_on_debug_handler(crate::DebugEvent::Breakpoint)?;
17601759
}
17611760
// Avoid unused-argument warning in no-debugger builds.

src/commands/run.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,10 @@ impl RunCommand {
396396
}
397397

398398
#[cfg(feature = "debug")]
399-
fn add_debugger_api(&mut self, linker: &mut wasmtime::component::Linker<Host>) -> Result<()> {
399+
pub(crate) fn add_debugger_api(
400+
&mut self,
401+
linker: &mut wasmtime::component::Linker<Host>,
402+
) -> Result<()> {
400403
wasmtime_debugger::add_to_linker(linker, |x| x.ctx().table)?;
401404
Ok(())
402405
}
@@ -510,7 +513,7 @@ impl RunCommand {
510513
Ok(instance)
511514
}
512515

513-
fn compute_argv(&self) -> Result<Vec<String>> {
516+
pub(crate) fn compute_argv(&self) -> Result<Vec<String>> {
514517
let mut result = Vec::new();
515518

516519
for (i, arg) in self.module_and_args.iter().enumerate() {
@@ -898,10 +901,15 @@ impl RunCommand {
898901
}
899902
}
900903

904+
/// Invoke a debugger component with a debuggee.
905+
///
906+
/// The debugger runs in `store` (using run's `Host`), while the
907+
/// debuggee wraps an arbitrary store type `T` and body closure.
901908
#[cfg(feature = "debug")]
902-
async fn invoke_debugger<
909+
pub(crate) async fn invoke_debugger<
910+
T: Send + 'static,
903911
F: for<'a> FnOnce(
904-
&'a mut Store<Host>,
912+
&'a mut Store<T>,
905913
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>
906914
+ Send
907915
+ 'static,
@@ -910,7 +918,7 @@ impl RunCommand {
910918
store: &mut Store<Host>,
911919
component: &wasmtime::component::Component,
912920
linker: &mut wasmtime::component::Linker<Host>,
913-
debuggee_host: Store<Host>,
921+
debuggee_host: Store<T>,
914922
body: F,
915923
) -> Result<()> {
916924
let instance = linker.instantiate_async(&mut *store, component).await?;

0 commit comments

Comments
 (0)