Skip to main content

EntriesCursor

Struct EntriesCursor 

Source
pub struct EntriesCursor<'abbrev, R>
where R: Reader,
{ /* private fields */ }
Expand description

A cursor into the Debugging Information Entries tree for a compilation unit.

The EntriesCursor can traverse the DIE tree in DFS order using Self::next_dfs, or skip to the next sibling of the entry the cursor is currently pointing to using Self::next_sibling.

Self::next_dfs will skip over the null DIEs that delimit lists of children. Use Self::next_entry if you wish to stop at null DIEs. This may be useful if you want to read entries at a specific depth, such as moving to the first child prior to using Self::next_sibling.

Implementations§

Source§

impl<'abbrev, R: Reader> EntriesCursor<'abbrev, R>

Source

pub fn current(&self) -> Option<&DebuggingInformationEntry<R>>

Get a reference to the entry that the cursor is currently pointing to.

If the cursor is not pointing at an entry, or if the current entry is a null entry, then None is returned.

Source

pub fn offset(&self) -> UnitOffset<R::Offset>

The unit offset of the current DIE.

This works even if the cursor is positioned at a null DIE.

Source

pub fn depth(&self) -> isize

The tree depth of the current DIE.

This works even if the cursor is positioned at a null DIE.

Source

pub fn next_offset(&self) -> UnitOffset<R::Offset>

The unit offset of the next DIE that Self::next_entry will read.

Source

pub fn next_depth(&self) -> isize

The tree depth of the next DIE that Self::next_entry will read.

Source

pub fn next_entry(&mut self) -> Result<bool>

Move the cursor to the next DIE in the tree.

Returns true if there is a next entry, even if this entry is null. If there is no next entry, then false is returned.

Source

pub fn next_dfs(&mut self) -> Result<Option<&DebuggingInformationEntry<R>>>

Move the cursor to the next DIE in the tree in DFS order.

Upon successful movement of the cursor, returns the entry, which may be:

  • The first child of the previous current entry, if any.

  • The sibling of the previous current entry, if any.

  • The sibling of the previous entry’s parent, if any, and so on.

If there is no next entry, then None is returned.

Here is an example that prints the offset and depth of all entries in a compilation unit.


let unit = get_some_unit();
let abbrevs = get_abbrevs_for_unit(&unit);
let mut cursor = unit.entries(&abbrevs);

// Traverse the DIE tree in depth-first search order.
while let Some(current) = cursor.next_dfs().expect("Should parse next dfs") {
    println!(
        "Offset: {:x} Depth: {} Tag: {}",
        current.offset().0,
        current.depth(),
        current.tag()
    );
}
Source

pub fn next_sibling(&mut self) -> Result<Option<&DebuggingInformationEntry<R>>>

Move the cursor to the next sibling DIE of the current one.

Returns Ok(Some(entry)) when the cursor has been moved to the next sibling, Ok(None) when there is no next sibling.

The depth of the cursor is never changed if this method returns Ok. Once Ok(None) is returned, this method will continue to return Ok(None) until either Self::next_entry or Self::next_dfs is called.

This method is useful for reading only the children of a DIE. However, you must first move the cursor to the first child. Self::next_entry is usually the easiest way to do this. You should also use either Self::next_depth or DebuggingInformationEntry::has_children to determine if the DIE can have children.

Here is an example that iterates over all of the direct children of the root entry:


let unit = get_some_unit();
let abbrevs = get_abbrevs_for_unit(&unit);

let mut cursor = unit.entries(&abbrevs);

// Move the cursor to the root.
assert!(cursor.next_entry().unwrap());

// Move the cursor to the root's first child, if any.
assert!(cursor.current().unwrap().has_children());
assert!(cursor.next_entry().unwrap());

// Iterate the root's children.
while let Some(current) = cursor.current() {
    println!("{:?} is a child of the root", current);
    cursor.next_sibling().expect("Should parse next sibling");
}

Trait Implementations§

Source§

impl<'abbrev, R> Clone for EntriesCursor<'abbrev, R>
where R: Reader + Clone,

Source§

fn clone(&self) -> EntriesCursor<'abbrev, R>

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

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

Performs copy-assignment from source. Read more
Source§

impl<'abbrev, R> Debug for EntriesCursor<'abbrev, R>
where R: Reader + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'abbrev, R> Freeze for EntriesCursor<'abbrev, R>
where R: Freeze, <R as Reader>::Offset: Freeze,

§

impl<'abbrev, R> RefUnwindSafe for EntriesCursor<'abbrev, R>

§

impl<'abbrev, R> Send for EntriesCursor<'abbrev, R>
where R: Send, <R as Reader>::Offset: Send,

§

impl<'abbrev, R> Sync for EntriesCursor<'abbrev, R>
where R: Sync, <R as Reader>::Offset: Sync,

§

impl<'abbrev, R> Unpin for EntriesCursor<'abbrev, R>
where R: Unpin, <R as Reader>::Offset: Unpin,

§

impl<'abbrev, R> UnsafeUnpin for EntriesCursor<'abbrev, R>
where R: UnsafeUnpin, <R as Reader>::Offset: UnsafeUnpin,

§

impl<'abbrev, R> UnwindSafe for EntriesCursor<'abbrev, R>
where R: UnwindSafe, <R as Reader>::Offset: UnwindSafe,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.