Skip to content

Commit f7b45a0

Browse files
authored
Add -Dmax-backtrace=N to the CLI (#13218)
This enables customizing the number of frames captured in a backtrace should it exceed 20. Setting this to 0 additionally enables a mechanism to disable backtraces.
1 parent b6fb64b commit f7b45a0

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

crates/cli-flags/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
33
use clap::Parser;
44
use serde::Deserialize;
5+
use std::num::NonZeroUsize;
56
use std::{
67
fmt, fs,
78
num::NonZeroU32,
89
path::{Path, PathBuf},
910
time::Duration,
1011
};
11-
use wasmtime::{Config, Result, bail, error::Context as _};
12+
use wasmtime::{Config, Result, WasmBacktraceDetails, bail, error::Context as _};
1213

1314
pub mod opt;
1415

@@ -307,6 +308,8 @@ wasmtime_option_group! {
307308
/// Allow the debugger component to inherit stderr. Off by
308309
/// default.
309310
pub inherit_stderr: Option<bool>,
311+
/// Maximum number of frames to capture in backtraces.
312+
pub max_backtrace: Option<usize>,
310313
}
311314

312315
enum Debug {
@@ -945,6 +948,16 @@ impl CommonOptions {
945948
if let Some(enable) = self.debug.address_map {
946949
config.generate_address_map(enable);
947950
}
951+
if let Some(frames) = self.debug.max_backtrace {
952+
match NonZeroUsize::new(frames) {
953+
None => {
954+
config.wasm_backtrace_details(WasmBacktraceDetails::Disable);
955+
}
956+
Some(amt) => {
957+
config.wasm_backtrace_max_frames(Some(amt));
958+
}
959+
}
960+
}
948961
if let Some(enable) = self.opts.memory_init_cow {
949962
config.memory_init_cow(enable);
950963
}

0 commit comments

Comments
 (0)