MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / from_captured

Method from_captured

crates/wasmtime/src/runtime/trap.rs:304–406  ·  view source on GitHub ↗
(
        store: &StoreOpaque,
        runtime_trace: crate::runtime::vm::Backtrace,
        trap_pc: Option<usize>,
        max_frames: Option<NonZeroUsize>,
    )

Source from the content-addressed store, hash-verified

302 }
303
304 fn from_captured(
305 store: &StoreOpaque,
306 runtime_trace: crate::runtime::vm::Backtrace,
307 trap_pc: Option<usize>,
308 max_frames: Option<NonZeroUsize>,
309 ) -> Self {
310 let Some(max_frames) = max_frames else {
311 return WasmBacktrace {
312 wasm_trace: Vec::new(),
313 hint_wasm_backtrace_details_env: false,
314 _runtime_trace: crate::runtime::vm::Backtrace::empty(),
315 };
316 };
317 let mut wasm_trace = match TryVec::with_capacity(max_frames.get()) {
318 Ok(v) => v,
319 Err(_) => {
320 return Self {
321 wasm_trace: Vec::new(),
322 hint_wasm_backtrace_details_env: false,
323 _runtime_trace: crate::runtime::vm::Backtrace::empty(),
324 };
325 }
326 };
327 let mut hint_wasm_backtrace_details_env = false;
328 let wasm_backtrace_details_env_used =
329 store.engine().config().wasm_backtrace_details_env_used;
330
331 for frame in runtime_trace.frames() {
332 if wasm_trace.len() >= max_frames.get() {
333 break;
334 }
335
336 debug_assert!(frame.pc() != 0);
337
338 // Note that we need to be careful about the pc we pass in
339 // here to lookup frame information. This program counter is
340 // used to translate back to an original source location in
341 // the origin wasm module. If this pc is the exact pc that
342 // the trap happened at, then we look up that pc precisely.
343 // Otherwise backtrace information typically points at the
344 // pc *after* the call instruction (because otherwise it's
345 // likely a call instruction on the stack). In that case we
346 // want to lookup information for the previous instruction
347 // (the call instruction) so we subtract one as the lookup.
348 let pc_to_lookup = if Some(frame.pc()) == trap_pc {
349 frame.pc()
350 } else {
351 frame.pc() - 1
352 };
353
354 // NB: The PC we are looking up _must_ be a Wasm PC since
355 // `crate::runtime::vm::Backtrace` only contains Wasm frames.
356 //
357 // However, consider the case where we have multiple, nested calls
358 // across stores (with host code in between, by necessity, since
359 // only things in the same store can be linked directly together):
360 //
361 // | ... |

Callers

nothing calls this directly

Calls 14

pcMethod · 0.80
lookup_frame_infoMethod · 0.80
compiled_moduleMethod · 0.80
newFunction · 0.50
emptyFunction · 0.50
getMethod · 0.45
configMethod · 0.45
engineMethod · 0.45
framesMethod · 0.45
lenMethod · 0.45
modulesMethod · 0.45

Tested by

no test coverage detected