Skip to content

Commit c264266

Browse files
AimeedeerLucasSte
authored andcommitted
[SOL] Enable the std backtrace API
1 parent 8df4b4e commit c264266

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

library/std/src/backtrace.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ mod tests;
8888
// `Backtrace`, but that's a relatively small price to pay relative to capturing
8989
// a backtrace or actually symbolizing it.
9090

91+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
9192
use crate::backtrace_rs::{self, BytesOrWideString};
9293
use crate::env;
9394
use crate::ffi::c_void;
9495
use crate::fmt;
9596
use crate::panic::UnwindSafe;
9697
use crate::sync::atomic::{AtomicU8, Ordering::Relaxed};
9798
use crate::sync::LazyLock;
99+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
98100
use crate::sys_common::backtrace::{lock, output_filename, set_image_base};
99101

100102
/// A captured OS thread stack backtrace.
@@ -154,6 +156,7 @@ pub struct BacktraceFrame {
154156

155157
#[derive(Debug)]
156158
enum RawFrame {
159+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
157160
Actual(backtrace_rs::Frame),
158161
#[cfg(test)]
159162
Fake,
@@ -173,6 +176,7 @@ enum BytesOrWide {
173176

174177
#[stable(feature = "backtrace", since = "1.65.0")]
175178
impl fmt::Debug for Backtrace {
179+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
176180
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
177181
let capture = match &self.inner {
178182
Inner::Unsupported => return fmt.write_str("<unsupported>"),
@@ -196,17 +200,29 @@ impl fmt::Debug for Backtrace {
196200

197201
dbg.finish()
198202
}
203+
204+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
205+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
206+
write!(fmt, "<unsupported>")
207+
}
199208
}
200209

201210
#[unstable(feature = "backtrace_frames", issue = "79676")]
202211
impl fmt::Debug for BacktraceFrame {
212+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
203213
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
204214
let mut dbg = fmt.debug_list();
205215
dbg.entries(&self.symbols);
206216
dbg.finish()
207217
}
218+
219+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
220+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
221+
write!(fmt, "<unsupported>")
222+
}
208223
}
209224

225+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
210226
impl fmt::Debug for BacktraceSymbol {
211227
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
212228
// FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280
@@ -233,6 +249,7 @@ impl fmt::Debug for BacktraceSymbol {
233249
}
234250
}
235251

252+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
236253
impl fmt::Debug for BytesOrWide {
237254
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
238255
output_filename(
@@ -250,6 +267,7 @@ impl fmt::Debug for BytesOrWide {
250267
impl Backtrace {
251268
/// Returns whether backtrace captures are enabled through environment
252269
/// variables.
270+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
253271
fn enabled() -> bool {
254272
// Cache the result of reading the environment variables to make
255273
// backtrace captures speedy, because otherwise reading environment
@@ -271,6 +289,11 @@ impl Backtrace {
271289
enabled
272290
}
273291

292+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
293+
fn enabled() -> bool {
294+
false
295+
}
296+
274297
/// Capture a stack backtrace of the current thread.
275298
///
276299
/// This function will capture a stack backtrace of the current OS thread of
@@ -322,6 +345,7 @@ impl Backtrace {
322345

323346
// Capture a backtrace which start just before the function addressed by
324347
// `ip`
348+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
325349
fn create(ip: usize) -> Backtrace {
326350
let _lock = lock();
327351
let mut frames = Vec::new();
@@ -355,6 +379,13 @@ impl Backtrace {
355379
Backtrace { inner }
356380
}
357381

382+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
383+
fn create(ip: usize) -> Backtrace {
384+
Backtrace {
385+
inner: Inner::Unsupported
386+
}
387+
}
388+
358389
/// Returns the status of this backtrace, indicating whether this backtrace
359390
/// request was unsupported, disabled, or a stack trace was actually
360391
/// captured.
@@ -380,6 +411,7 @@ impl<'a> Backtrace {
380411

381412
#[stable(feature = "backtrace", since = "1.65.0")]
382413
impl fmt::Display for Backtrace {
414+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
383415
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
384416
let capture = match &self.inner {
385417
Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
@@ -426,6 +458,11 @@ impl fmt::Display for Backtrace {
426458
f.finish()?;
427459
Ok(())
428460
}
461+
462+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
463+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
464+
write!(fmt, "<unsupported>")
465+
}
429466
}
430467

431468
type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
@@ -460,8 +497,18 @@ fn lazy_resolve(mut capture: Capture) -> LazyResolve {
460497

461498
capture
462499
}
500+
501+
#[cfg(any(target_arch = "bpf", target_arch = "sbf"))]
502+
fn resolve(&mut self) {
503+
// If we're already resolved, nothing to do!
504+
if self.resolved {
505+
return;
506+
}
507+
self.resolved = true;
508+
}
463509
}
464510

511+
#[cfg(not(any(target_arch = "bpf", target_arch = "sbf")))]
465512
impl RawFrame {
466513
fn ip(&self) -> *mut c_void {
467514
match self {

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ pub mod f64;
579579
#[macro_use]
580580
pub mod thread;
581581
pub mod ascii;
582-
#[cfg(all(not(target_arch = "bpf"), not(target_arch = "sbf")))]
583582
pub mod backtrace;
584583
pub mod collections;
585584
pub mod env;

0 commit comments

Comments
 (0)