diff options
| author | Sean Chen <seanchen11235@gmail.com> | 2021-01-13 17:54:24 -0600 |
|---|---|---|
| committer | Sean Chen <seanchen11235@gmail.com> | 2021-01-23 11:56:33 -0600 |
| commit | 050643a9606c279d9b959976c3718ad3d7bdb84a (patch) | |
| tree | 60fe0d57333c78cd5db19033ca42723d43646a54 /library/std/src/backtrace.rs | |
| parent | a62a76047ea24aad7639f14eb3ce0e620b77bdb7 (diff) | |
| download | rust-050643a9606c279d9b959976c3718ad3d7bdb84a.tar.gz rust-050643a9606c279d9b959976c3718ad3d7bdb84a.zip | |
Add Frames iterator for Backtrace
Diffstat (limited to 'library/std/src/backtrace.rs')
| -rw-r--r-- | library/std/src/backtrace.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 95e18ef2a65..0aae4674b29 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -147,11 +147,14 @@ fn _assert_send_sync() { _assert::<Backtrace>(); } -struct BacktraceFrame { +/// A single frame of a backtrace. +#[unstable(feature = "backtrace_frames", issue = "79676")] +pub struct BacktraceFrame { frame: RawFrame, symbols: Vec<BacktraceSymbol>, } +#[derive(Debug)] enum RawFrame { Actual(backtrace_rs::Frame), #[cfg(test)] @@ -196,6 +199,14 @@ impl fmt::Debug for Backtrace { } } +impl fmt::Debug for BacktraceFrame { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut dbg = fmt.debug_list(); + dbg.entries(&self.symbols); + dbg.finish() + } +} + impl fmt::Debug for BacktraceSymbol { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { // FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280 @@ -353,6 +364,14 @@ impl Backtrace { } } +impl<'a> Backtrace { + /// Returns an iterator over the backtrace frames. + #[unstable(feature = "backtrace_frames", issue = "79676")] + pub fn frames(&'a self) -> &'a [BacktraceFrame] { + if let Inner::Captured(c) = &self.inner { &c.force().frames } else { &[] } + } +} + impl fmt::Display for Backtrace { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let capture = match &self.inner { |
