| ... | ... | @@ -493,6 +493,7 @@ pub const StackIterator = struct { |
| 493 | 493 | debug_info: *DebugInfo, |
| 494 | 494 | dwarf_context: DW.UnwindContext, |
| 495 | 495 | last_error: ?UnwindError = null, |
| 496 | failed: bool = false, |
| 496 | 497 | } else void = if (have_ucontext) null else {}, |
| 497 | 498 | |
| 498 | 499 | pub fn init(first_address: ?usize, fp: ?usize) StackIterator { |
| ... | ... | @@ -530,6 +531,7 @@ pub const StackIterator = struct { |
| 530 | 531 | if (!have_ucontext) return null; |
| 531 | 532 | if (self.unwind_state) |*unwind_state| { |
| 532 | 533 | if (unwind_state.last_error) |err| { |
| 534 | unwind_state.last_error = null; |
| 533 | 535 | return .{ |
| 534 | 536 | .err = err, |
| 535 | 537 | .address = unwind_state.dwarf_context.pc, |
| ... | ... | @@ -648,15 +650,20 @@ pub const StackIterator = struct { |
| 648 | 650 | fn next_internal(self: *StackIterator) ?usize { |
| 649 | 651 | if (have_ucontext) { |
| 650 | 652 | if (self.unwind_state) |*unwind_state| { |
| 651 | | if (unwind_state.dwarf_context.pc == 0) return null; |
| 652 | | if (unwind_state.last_error == null) { |
| 653 | | if (self.next_unwind()) |return_address| { |
| 654 | | return return_address; |
| 655 | | } else |err| { |
| 656 | | unwind_state.last_error = err; |
| 657 | | |
| 658 | | // Fall back to fp-based unwinding on the first failure |
| 659 | | self.fp = unwind_state.dwarf_context.getFp() catch 0; |
| 653 | if (!unwind_state.failed) { |
| 654 | if (unwind_state.dwarf_context.pc == 0) return null; |
| 655 | if (unwind_state.last_error == null) { |
| 656 | if (self.next_unwind()) |return_address| { |
| 657 | return return_address; |
| 658 | } else |err| { |
| 659 | unwind_state.last_error = err; |
| 660 | unwind_state.failed = true; |
| 661 | |
| 662 | // Fall back to fp-based unwinding on the first failure. |
| 663 | // We can't attempt it for other modules later in the |
| 664 | // stack because the full register state won't be unwound. |
| 665 | self.fp = unwind_state.dwarf_context.getFp() catch 0; |
| 666 | } |
| 660 | 667 | } |
| 661 | 668 | } |
| 662 | 669 | } |