wasmtime_internal_core/error/backtrace.rs
1use std::backtrace::Backtrace;
2use std::sync::atomic::{AtomicBool, Ordering};
3
4static ENABLED: AtomicBool = AtomicBool::new(true);
5
6fn enabled() -> bool {
7 ENABLED.load(Ordering::Relaxed)
8}
9
10/// Forcibly disable capturing backtraces dynamically.
11///
12/// XXX: This is only exposed for internal testing, to work around cargo
13/// workspaces and feature resolution. This method may disappear or change
14/// at any time. Instead of using this method, you should disable the
15/// `backtrace` cargo feature.
16#[doc(hidden)]
17pub fn disable_backtrace() {
18 ENABLED.store(false, Ordering::Relaxed)
19}
20
21#[track_caller]
22pub fn capture() -> Backtrace {
23 if enabled() {
24 Backtrace::capture()
25 } else {
26 Backtrace::disabled()
27 }
28}