Skip to content

Commit 1d2301e

Browse files
committed
Add experimental backtrace-trace-only std feature
1 parent 56835d7 commit 1d2301e

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

library/std/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ backtrace = [
9292
'object/rustc-dep-of-std',
9393
'miniz_oxide/rustc-dep-of-std',
9494
]
95+
backtrace-trace-only = []
9596

9697
panic-unwind = ["dep:panic_unwind"]
9798
compiler-builtins-c = ["alloc/compiler-builtins-c"]

library/std/src/sys/backtrace.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,45 +69,47 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
6969
}
7070

7171
let mut hit = false;
72-
backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
73-
hit = true;
74-
75-
// `__rust_end_short_backtrace` means we are done hiding symbols
76-
// for now. Print until we see `__rust_begin_short_backtrace`.
77-
if print_fmt == PrintFmt::Short {
78-
if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
79-
if sym.contains("__rust_end_short_backtrace") {
80-
print = true;
81-
return;
82-
}
83-
if print && sym.contains("__rust_begin_short_backtrace") {
84-
print = false;
85-
return;
86-
}
87-
if !print {
88-
omitted_count += 1;
72+
if cfg!(not(feature = "backtrace-trace-only")) {
73+
backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
74+
hit = true;
75+
76+
// `__rust_end_short_backtrace` means we are done hiding symbols
77+
// for now. Print until we see `__rust_begin_short_backtrace`.
78+
if print_fmt == PrintFmt::Short {
79+
if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
80+
if sym.contains("__rust_end_short_backtrace") {
81+
print = true;
82+
return;
83+
}
84+
if print && sym.contains("__rust_begin_short_backtrace") {
85+
print = false;
86+
return;
87+
}
88+
if !print {
89+
omitted_count += 1;
90+
}
8991
}
9092
}
91-
}
9293

93-
if print {
94-
if omitted_count > 0 {
95-
debug_assert!(print_fmt == PrintFmt::Short);
96-
// only print the message between the middle of frames
97-
if !first_omit {
98-
let _ = writeln!(
99-
bt_fmt.formatter(),
100-
" [... omitted {} frame{} ...]",
101-
omitted_count,
102-
if omitted_count > 1 { "s" } else { "" }
103-
);
94+
if print {
95+
if omitted_count > 0 {
96+
debug_assert!(print_fmt == PrintFmt::Short);
97+
// only print the message between the middle of frames
98+
if !first_omit {
99+
let _ = writeln!(
100+
bt_fmt.formatter(),
101+
" [... omitted {} frame{} ...]",
102+
omitted_count,
103+
if omitted_count > 1 { "s" } else { "" }
104+
);
105+
}
106+
first_omit = false;
107+
omitted_count = 0;
104108
}
105-
first_omit = false;
106-
omitted_count = 0;
109+
res = bt_fmt.frame().symbol(frame, symbol);
107110
}
108-
res = bt_fmt.frame().symbol(frame, symbol);
109-
}
110-
});
111+
});
112+
}
111113
#[cfg(target_os = "nto")]
112114
if libc::__my_thread_exit as *mut libc::c_void == frame.ip() {
113115
if !hit && print {

library/sysroot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test = { path = "../test", public = true }
2020
[features]
2121
default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
2222
backtrace = ["std/backtrace"]
23+
backtrace-trace-only = ["std/backtrace-trace-only"]
2324
compiler-builtins-c = ["std/compiler-builtins-c"]
2425
compiler-builtins-mem = ["std/compiler-builtins-mem"]
2526
compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]

0 commit comments

Comments
 (0)