| ... | ... | @@ -440,7 +440,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext, stderr: *Writer) void { |
| 440 | 440 | return; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | | var it = StackIterator.initWithContext(null, debug_info, context) catch return; |
| 443 | var it = StackIterator.initWithContext(null, debug_info, context, @frameAddress()) catch return; |
| 444 | 444 | defer it.deinit(); |
| 445 | 445 | |
| 446 | 446 | // DWARF unwinding on aarch64-macos is not complete so we need to get pc address from mcontext |
| ... | ... | @@ -499,12 +499,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT |
| 499 | 499 | // TODO: This should use the DWARF unwinder if .eh_frame_hdr is available (so that full debug info parsing isn't required). |
| 500 | 500 | // A new path for loading SelfInfo needs to be created which will only attempt to parse in-memory sections, because |
| 501 | 501 | // stopping to load other debug info (ie. source line info) from disk here is not required for unwinding. |
| 502 | | if (builtin.cpu.arch == .powerpc64) { |
| 503 | | // https://github.com/ziglang/zig/issues/24970 |
| 504 | | stack_trace.index = 0; |
| 505 | | return; |
| 506 | | } |
| 507 | | var it = StackIterator.init(first_address, null); |
| 502 | var it = StackIterator.init(first_address, @frameAddress()); |
| 508 | 503 | defer it.deinit(); |
| 509 | 504 | for (stack_trace.instruction_addresses, 0..) |*addr, i| { |
| 510 | 505 | addr.* = it.next() orelse { |
| ... | ... | @@ -787,7 +782,7 @@ pub const StackIterator = struct { |
| 787 | 782 | failed: bool = false, |
| 788 | 783 | } else void = if (have_ucontext) null else {}, |
| 789 | 784 | |
| 790 | | pub fn init(first_address: ?usize, fp: ?usize) StackIterator { |
| 785 | pub fn init(first_address: ?usize, fp: usize) StackIterator { |
| 791 | 786 | if (native_arch.isSPARC()) { |
| 792 | 787 | // Flush all the register windows on stack. |
| 793 | 788 | asm volatile (if (builtin.cpu.has(.sparc, .v9)) |
| ... | ... | @@ -799,23 +794,18 @@ pub const StackIterator = struct { |
| 799 | 794 | |
| 800 | 795 | return .{ |
| 801 | 796 | .first_address = first_address, |
| 802 | | // TODO: this is a workaround for #16876 |
| 803 | | //.fp = fp orelse @frameAddress(), |
| 804 | | .fp = fp orelse blk: { |
| 805 | | const fa = @frameAddress(); |
| 806 | | break :blk fa; |
| 807 | | }, |
| 797 | .fp = fp, |
| 808 | 798 | }; |
| 809 | 799 | } |
| 810 | 800 | |
| 811 | | pub fn initWithContext(first_address: ?usize, debug_info: *SelfInfo, context: *posix.ucontext_t) !StackIterator { |
| 801 | pub fn initWithContext(first_address: ?usize, debug_info: *SelfInfo, context: *posix.ucontext_t, fp: usize) !StackIterator { |
| 812 | 802 | // The implementation of DWARF unwinding on aarch64-macos is not complete. However, Apple mandates that |
| 813 | 803 | // the frame pointer register is always used, so on this platform we can safely use the FP-based unwinder. |
| 814 | 804 | if (builtin.target.os.tag.isDarwin() and native_arch == .aarch64) |
| 815 | 805 | return init(first_address, @truncate(context.mcontext.ss.fp)); |
| 816 | 806 | |
| 817 | 807 | if (SelfInfo.supports_unwinding) { |
| 818 | | var iterator = init(first_address, null); |
| 808 | var iterator = init(first_address, fp); |
| 819 | 809 | iterator.unwind_state = .{ |
| 820 | 810 | .debug_info = debug_info, |
| 821 | 811 | .dwarf_context = try SelfInfo.UnwindContext.init(debug_info.allocator, context), |
| ... | ... | @@ -823,7 +813,7 @@ pub const StackIterator = struct { |
| 823 | 813 | return iterator; |
| 824 | 814 | } |
| 825 | 815 | |
| 826 | | return init(first_address, null); |
| 816 | return init(first_address, fp); |
| 827 | 817 | } |
| 828 | 818 | |
| 829 | 819 | pub fn deinit(it: *StackIterator) void { |
| ... | ... | @@ -981,8 +971,8 @@ pub fn writeCurrentStackTrace( |
| 981 | 971 | const has_context = getContext(&context); |
| 982 | 972 | |
| 983 | 973 | var it = (if (has_context) blk: { |
| 984 | | break :blk StackIterator.initWithContext(start_addr, debug_info, &context) catch null; |
| 985 | | } else null) orelse StackIterator.init(start_addr, null); |
| 974 | break :blk StackIterator.initWithContext(start_addr, debug_info, &context, @frameAddress()) catch null; |
| 975 | } else null) orelse StackIterator.init(start_addr, @frameAddress()); |
| 986 | 976 | defer it.deinit(); |
| 987 | 977 | |
| 988 | 978 | while (it.next()) |return_address| { |