Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read/cfi: add example to UnwindExpression #722

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,8 +2827,7 @@ pub enum CfaRule<T: ReaderOffset> {
/// The offset from the register's base value.
offset: i64,
},
/// The CFA is obtained by evaluating this `Reader` as a DWARF expression
/// program.
/// The CFA is obtained by evaluating a DWARF expression program.
Expression(UnwindExpression<T>),
}

Expand Down Expand Up @@ -3459,6 +3458,28 @@ impl<'a, R: Reader> fallible_iterator::FallibleIterator for CallFrameInstruction
///
/// This is stored as an offset and length within the section instead of as a
/// `Reader` to avoid lifetime issues when reusing [`UnwindContext`].
///
/// # Example
/// ```
/// # use gimli::{EhFrame, EndianSlice, NativeEndian, Error, FrameDescriptionEntry, UnwindExpression, EvaluationResult};
/// # fn foo() -> Result<(), Error> {
/// # let eh_frame: EhFrame<EndianSlice<NativeEndian>> = unreachable!();
/// # let fde: FrameDescriptionEntry<EndianSlice<NativeEndian>> = unimplemented!();
/// # let unwind_expression: UnwindExpression<_> = unimplemented!();
/// let expression = unwind_expression.get(&eh_frame)?;
/// let mut evaluation = expression.evaluation(fde.cie().encoding());
/// let mut result = evaluation.evaluate()?;
Comment on lines +3469 to +3471

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// loop {
/// match result {
/// EvaluationResult::Complete => break,
/// // Provide information to the evaluation.
/// _ => { unimplemented!()}
/// }
/// }
/// let value = evaluation.value_result();
/// # Ok(())
/// # }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnwindExpression<T: ReaderOffset> {
/// The offset of the expression within the section.
Expand Down
Loading