A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Debugging: force hostcall-based-traps when guest-debugging is enabled. (#12052)
Chris Fallin1ab8603726c9
diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rsindex 252814466f..e9879e3cef 100644--- a/crates/wasmtime/src/config.rs+++ b/crates/wasmtime/src/config.rs@@ -2376,6 +2376,15 @@ impl Config {}}+ // If guest-debugging is enabled, we must disable+ // signals-based traps. Do this before we process the user's+ // provided tunables settings so we can detect a conflict with+ // an explicit request to use signals-based traps.+ #[cfg(feature = "debug")]+ if self.tunables.debug_guest == Some(true) {+ tunables.signals_based_traps = false;+ }+self.tunables.configure(&mut tunables);// If we're going to compile with winch, we must use the winch calling convention.@@ -2400,8 +2409,13 @@ impl Config {None};- if !cfg!(feature = "debug") && tunables.debug_guest {- bail!("debug instrumentation support was disabled at compile time");+ if tunables.debug_guest {+ if !cfg!(feature = "debug") {+ bail!("debug instrumentation support was disabled at compile time");+ }+ if tunables.signals_based_traps {+ bail!("cannot use signals-based traps with guest debugging enabled");+ }}Ok((tunables, features))diff --git a/tests/all/debug.rs b/tests/all/debug.rsindex 31096a4215..092da7fe5c 100644--- a/tests/all/debug.rs+++ b/tests/all/debug.rs@@ -7,6 +7,14 @@ use wasmtime::{Store, StoreContextMut,};+#[test]+fn debugging_does_not_work_with_signal_based_traps() {+ let mut config = Config::default();+ config.guest_debug(true).signals_based_traps(true);+ let err = Engine::new(&config).expect_err("invalid config should produce an error");+ assert!(format!("{err:?}").contains("cannot use signals-based traps"));+}+fn get_module_and_store<C: Fn(&mut Config)>(c: C,wat: &str,@@ -370,8 +378,6 @@ async fn hostcall_trap_events() -> anyhow::Result<()> {|config| {config.async_support(true);config.wasm_exceptions(true);- // Force hostcall-based traps.- config.signals_based_traps(false);},r#"(modulediff --git a/tests/disas/debug-exceptions.wat b/tests/disas/debug-exceptions.watindex 540226aba2..ad4a17cf6b 100644--- a/tests/disas/debug-exceptions.wat+++ b/tests/disas/debug-exceptions.wat@@ -16,12 +16,7 @@;; wasm[0]::function[1]:;; stp x29, x30, [sp, #-0x10]!;; mov x29, sp-;; ldur x16, [x2, #8]-;; ldur x16, [x16, #0x10]-;; add x16, x16, #0xc0-;; cmp sp, x16-;; b.lo #0x110-;; 1c: stp x27, x28, [sp, #-0x10]!+;; stp x27, x28, [sp, #-0x10]!;; stp x25, x26, [sp, #-0x10]!;; stp x23, x24, [sp, #-0x10]!;; stp x21, x22, [sp, #-0x10]!@@ -30,55 +25,79 @@;; stp d12, d13, [sp, #-0x10]!;; stp d10, d11, [sp, #-0x10]!;; stp d8, d9, [sp, #-0x10]!-;; sub sp, sp, #0x20-;; stur x2, [sp]+;; sub sp, sp, #0x30+;; ldr x3, [x2, #8]+;; ldr x3, [x3, #0x10]+;; mov x4, sp+;; cmp x4, x3+;; b.lo #0x15c+;; 44: stur x2, [sp];; stur x2, [sp, #0x10]-;; mov w27, #0x2a-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 61, slot at FP-0xb0, locals , stack-;; stur w27, [sp, #8]-;; stur w27, [sp, #8]-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 64, slot at FP-0xb0, locals , stack+;; mov w22, #0x2a+;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 61, slot at FP-0xc0, locals , stack+;; stur w22, [sp, #8]+;; stur w22, [sp, #8]+;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 64, slot at FP-0xc0, locals , stack;; ldur x2, [sp, #0x10]-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 66, slot at FP-0xb0, locals , stack I32 @ slot+0x8-;; bl #0x31c-;; 60: mov x21, x2+;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 66, slot at FP-0xc0, locals , stack I32 @ slot+0x8+;; bl #0x3f0+;; 60: mov x24, x2;; mov w3, #0x4000000;; mov w4, #2;; mov w5, #0x28;; mov w6, #8;; ldur x2, [sp, #0x10]-;; bl #0x2a8-;; 7c: ldur x11, [sp, #0x10]-;; ldr x0, [x11, #8]-;; ldr x5, [x0, #0x18]-;; add x0, x5, #0x20-;; str w27, [x0, w2, uxtw]-;; add x3, x5, #0x18-;; mov x4, x21-;; str w4, [x3, w2, uxtw]+;; bl #0x310+;; 7c: ldur x13, [sp, #0x10]+;; ldr x5, [x13, #8]+;; ldr x6, [x5, #0x18]+;; stur x5, [sp, #0x20]+;; add x15, x6, #0x20+;; str w22, [x15, w2, uxtw]+;; add x3, x6, #0x18+;; mov x7, x24+;; str w7, [x3, w2, uxtw];; mov w3, #0-;; add x4, x5, #0x1c-;; stur x5, [sp, #0x18]+;; add x4, x6, #0x1c+;; stur x6, [sp, #0x18];; str w3, [x4, w2, uxtw];; mov x3, x2;; ldur x2, [sp, #0x10]-;; bl #0x354-;; ├─╼ exception frame offset: SP = FP - 0xb0-;; ╰─╼ exception handler: tag=0, context at [SP+0x10], handler=0xbc-;; b8: .byte 0x1f, 0xc1, 0x00, 0x00-;; ldur x5, [sp, #0x18]-;; add x4, x5, #0x20-;; ldr w6, [x4, w0, uxtw]-;; stur w6, [sp, #8]+;; bl #0x428+;; ├─╼ exception frame offset: SP = FP - 0xc0+;; ╰─╼ exception handler: tag=0, context at [SP+0x10], handler=0xd4+;; bc: mov w3, #9;; ldur x2, [sp, #0x10]-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xb0, locals , stack I32 @ slot+0x8-;; ldr x8, [x2, #0x30]+;; bl #0x384+;; c8: ldur x2, [sp, #0x10]+;; bl #0x3bc+;; d0: .byte 0x1f, 0xc1, 0x00, 0x00+;; mov x15, x0+;; mov w6, w15+;; mov x7, #0x28+;; adds x5, x6, x7+;; cset x7, hs+;; uxtb w6, w7+;; cbnz x6, #0x174+;; f0: ldur x12, [sp, #0x20]+;; ldr x8, [x12, #0x20]+;; cmp x5, x8+;; cset x9, hi+;; uxtb w9, w9+;; cbnz x9, #0x178+;; 108: ldur x6, [sp, #0x18]+;; add x10, x6, #0x20+;; ldr w12, [x10, w15, uxtw]+;; stur w12, [sp, #8]+;; ldur x2, [sp, #0x10]+;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xc0, locals , stack I32 @ slot+0x8+;; ldr x14, [x2, #0x30];; ldr x2, [x2, #0x40];; ldur x3, [sp, #0x10]-;; blr x8-;; ╰─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xb0, locals , stack I32 @ slot+0x8-;; e0: add sp, sp, #0x20-;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 75, slot at FP-0xb0, locals , stack+;; blr x14+;; ╰─╼ debug frame state (after previous inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 72, slot at FP-0xc0, locals , stack I32 @ slot+0x8+;; 12c: add sp, sp, #0x30+;; ╰─╼ debug frame state (before next inst): func key DefinedWasmFunction(StaticModuleIndex(0), DefinedFuncIndex(0)), wasm PC 75, slot at FP-0xc0, locals , stack;; ldp d8, d9, [sp], #0x10;; ldp d10, d11, [sp], #0x10;; ldp d12, d13, [sp], #0x10@@ -90,4 +109,11 @@;; ldp x27, x28, [sp], #0x10;; ldp x29, x30, [sp], #0x10;; ret-;; 110: .byte 0x1f, 0xc1, 0x00, 0x00+;; 15c: stur x2, [sp, #0x10]+;; 160: mov w3, #0+;; 164: bl #0x384+;; 168: ldur x2, [sp, #0x10]+;; 16c: bl #0x3bc+;; 170: .byte 0x1f, 0xc1, 0x00, 0x00+;; 174: .byte 0x1f, 0xc1, 0x00, 0x00+;; 178: .byte 0x1f, 0xc1, 0x00, 0x00