1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::{error::UnwinderError, FrameAddress};
/// Why framehop used frame-pointer unwinding for a frame.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FramePointerFallbackReason {
/// No registered module contains the instruction address.
NoModule,
/// The module's unwind information could not produce an unwind rule.
UnwindInfo(UnwinderError),
}
/// Result of unwinding one frame, including any frame-pointer fallback.
///
/// A fallback reason is diagnostic information. If `return_address` is
/// present, frame-pointer unwinding recovered the caller successfully.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnwindFrameOutcome {
return_address: Option<u64>,
fallback_reason: Option<FramePointerFallbackReason>,
}
impl UnwindFrameOutcome {
/// Create an outcome for a return address and its optional fallback reason.
pub const fn new(
return_address: Option<u64>,
fallback_reason: Option<FramePointerFallbackReason>,
) -> Self {
Self {
return_address,
fallback_reason,
}
}
/// Return the caller's return address, or `None` at the end of the stack.
pub const fn return_address(self) -> Option<u64> {
self.return_address
}
/// Return why this step used frame-pointer unwinding, if it did.
pub const fn fallback_reason(self) -> Option<FramePointerFallbackReason> {
self.fallback_reason
}
}
/// A frame yielded by detailed stack iteration.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnwindFrame {
address: FrameAddress,
fallback_reason: Option<FramePointerFallbackReason>,
}
impl UnwindFrame {
pub(crate) const fn new(
address: FrameAddress,
fallback_reason: Option<FramePointerFallbackReason>,
) -> Self {
Self {
address,
fallback_reason,
}
}
/// Return this frame's instruction or return address.
pub const fn address(self) -> FrameAddress {
self.address
}
/// Return why this frame was recovered with frame pointers, if applicable.
pub const fn fallback_reason(self) -> Option<FramePointerFallbackReason> {
self.fallback_reason
}
}