Struct Backtrace

Source
pub struct Backtrace<const N: usize> {
    pub frames: ArrayVec<usize, N>,
    pub frames_omitted: bool,
}
Expand description

A backtrace consisting of a list of instruction pointer addresses.

The backtrace does not allocate any memory, which allows it to be used in environments where dynamic allocation cannot be used such as signal handlers or interrupt handlers.

The N generic constant controls the maximum number of entries that should be included in the backtrace. Usually 16 frames are enough to get sufficient context from a crash.

Fields§

§frames: ArrayVec<usize, N>

List of instruction pointer addresses in each frame, from most recent to oldest.

These are not precise return address: the addresses are adjusted so that they point within the bounds of the caller function. This avoids issues when a call instruction is the last instruction in a function, which would otherwise result in a return address pointing at the start of the next function.

§frames_omitted: bool

Whether any frames have been omitted due to exceeding the capacity of the ArrayVec.

Implementations§

Source§

impl<const N: usize> Backtrace<N>

Source

pub fn capture() -> Self

Captures a backtrace from the current call point.

The first frame of the backtrace is the caller of Backtrace::capture.

Examples found in repository?
examples/backtrace.rs (line 4)
3fn main() {
4    let bt = Backtrace::<16>::capture();
5    println!("Backtrace:");
6    for frame in bt.frames {
7        println!("  {:#x}", adjust_for_pic(frame));
8    }
9    if bt.frames_omitted {
10        println!(" ... <frames omitted>");
11    }
12}

Trait Implementations§

Source§

impl<const N: usize> Clone for Backtrace<N>

Source§

fn clone(&self) -> Backtrace<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Backtrace<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Backtrace<N>

Source§

fn default() -> Backtrace<N>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Backtrace<N>

§

impl<const N: usize> RefUnwindSafe for Backtrace<N>

§

impl<const N: usize> Send for Backtrace<N>

§

impl<const N: usize> Sync for Backtrace<N>

§

impl<const N: usize> Unpin for Backtrace<N>

§

impl<const N: usize> UnwindSafe for Backtrace<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.