Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ anyhow = { workspace = true }
paste = "1.0.3"
encoding_rs = { version = "0.8.31", optional = true }
sptr = "0.3.2"
wasm-encoder = { workspace = true }
wasm-encoder = { workspace = true, optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
memfd = "0.6.2"
Expand Down Expand Up @@ -65,9 +65,10 @@ cc = "1.0"
wasmtime-versioned-export-macros = { workspace = true }

[features]
async = ["wasmtime-fiber"]
async = ["dep:wasmtime-fiber"]
pooling-allocator = []
component-model = ["wasmtime-environ/component-model", "dep:encoding_rs"]
wmemcheck = ['dep:wasmtime-wmemcheck']
debug-builtins = ['wasmtime-jit-debug']
debug-builtins = ['dep:wasmtime-jit-debug']
gc = ["wasmtime-environ/gc"]
coredump = ["dep:wasm-encoder"]
21 changes: 10 additions & 11 deletions crates/runtime/src/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
//! signalhandling mechanisms.

mod backtrace;

#[cfg(feature = "coredump")]
#[path = "traphandlers/coredump_enabled.rs"]
mod coredump;
#[cfg(not(feature = "coredump"))]
#[path = "traphandlers/coredump_disabled.rs"]
mod coredump;

use crate::sys::traphandlers;
Expand Down Expand Up @@ -277,6 +283,7 @@ mod call_thread_state {
pub(super) jmp_buf: Cell<*const u8>,
pub(super) signal_handler: Option<*const SignalHandler<'static>>,
pub(super) capture_backtrace: bool,
#[cfg(feature = "coredump")]
pub(super) capture_coredump: bool,

pub(crate) limits: *const VMRuntimeLimits,
Expand Down Expand Up @@ -314,11 +321,14 @@ mod call_thread_state {
capture_coredump: bool,
limits: *const VMRuntimeLimits,
) -> CallThreadState {
let _ = capture_coredump;

CallThreadState {
unwind: UnsafeCell::new(MaybeUninit::uninit()),
jmp_buf: Cell::new(ptr::null()),
signal_handler,
capture_backtrace,
#[cfg(feature = "coredump")]
capture_coredump,
limits,
prev: Cell::new(ptr::null()),
Expand Down Expand Up @@ -500,17 +510,6 @@ impl CallThreadState {
Some(unsafe { Backtrace::new_with_trap_state(limits, self, trap_pc_and_fp) })
}

fn capture_coredump(
&self,
limits: *const VMRuntimeLimits,
trap_pc_and_fp: Option<(usize, usize)>,
) -> Option<CoreDumpStack> {
if !self.capture_coredump {
return None;
}
Some(CoreDumpStack::new(&self, limits, trap_pc_and_fp))
}

pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = &Self> + 'a {
let mut state = Some(self);
std::iter::from_fn(move || {
Expand Down
16 changes: 16 additions & 0 deletions crates/runtime/src/traphandlers/coredump_disabled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::traphandlers::CallThreadState;
use crate::VMRuntimeLimits;

/// A WebAssembly Coredump
#[derive(Debug)]
pub enum CoreDumpStack {}

impl CallThreadState {
pub(super) fn capture_coredump(
&self,
_limits: *const VMRuntimeLimits,
_trap_pc_and_fp: Option<(usize, usize)>,
) -> Option<CoreDumpStack> {
None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ pub struct CoreDumpStack {
pub operand_stack: Vec<Vec<CoreDumpValue>>,
}

impl CoreDumpStack {
/// Capture a core dump of the current wasm state
pub fn new(
cts: &CallThreadState,
impl CallThreadState {
pub(super) fn capture_coredump(
&self,
limits: *const VMRuntimeLimits,
trap_pc_and_fp: Option<(usize, usize)>,
) -> Self {
let bt = unsafe { Backtrace::new_with_trap_state(limits, cts, trap_pc_and_fp) };
) -> Option<CoreDumpStack> {
if !self.capture_coredump {
return None;
}
let bt = unsafe { Backtrace::new_with_trap_state(limits, self, trap_pc_and_fp) };

Self {
Some(CoreDumpStack {
bt,
locals: vec![],
operand_stack: vec![],
}
})
}
}
2 changes: 1 addition & 1 deletion crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ wmemcheck = ["wasmtime-runtime?/wmemcheck", "wasmtime-cranelift?/wmemcheck"]
demangle = ["wasmtime-environ/demangle"]

# Enable support for generating core dumps on traps.
coredump = ["dep:wasm-encoder", "runtime"]
coredump = ["dep:wasm-encoder", "runtime", "wasmtime-runtime/coredump"]

# Export some symbols from the final binary to assist in debugging
# Cranelift-generated code with native debuggers like GDB and LLDB.
Expand Down