wasmtime/runtime/vm/traphandlers/
coredump_enabled.rs

1use super::CallThreadState;
2use crate::prelude::*;
3use crate::runtime::vm::{Backtrace, VMStoreContext};
4use wasm_encoder::CoreDumpValue;
5
6/// A WebAssembly Coredump
7#[derive(Debug)]
8pub struct CoreDumpStack {
9    /// The backtrace containing the stack frames for the CoreDump
10    pub bt: Backtrace,
11
12    /// The locals for each frame in the backtrace.
13    ///
14    /// This is not currently implemented.
15    #[allow(dead_code)]
16    pub locals: Vec<Vec<CoreDumpValue>>,
17
18    /// The operands for each stack frame
19    ///
20    /// This is not currently implemented.
21    #[allow(dead_code)]
22    pub operand_stack: Vec<Vec<CoreDumpValue>>,
23}
24
25impl CallThreadState {
26    pub(super) fn capture_coredump(
27        &self,
28        vm_store_context: *const VMStoreContext,
29        trap_pc_and_fp: Option<(usize, usize)>,
30    ) -> Option<CoreDumpStack> {
31        if !self.capture_coredump {
32            return None;
33        }
34        let bt = unsafe {
35            Backtrace::new_with_trap_state(vm_store_context, self.unwinder, self, trap_pc_and_fp)
36        };
37
38        Some(CoreDumpStack {
39            bt,
40            locals: vec![],
41            operand_stack: vec![],
42        })
43    }
44}