authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-18 22:51:52-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:16-04:00
log6d87bb370a6d9075b2b6628f5f8c09171f25e4e9
tree31c2c2e894f0ad2de17b68b8e58bc73d49e043c9
parent253e6971ad77a9665348fd6a2085b2ffd8c84219

debug: disable the new unwinder on aarch64-macos


2 files changed, 17 insertions(+), 11 deletions(-)

lib/std/debug.zig+15-9
......@@ -521,13 +521,19 @@ pub const StackIterator = struct {
521521 }
522522
523523 pub fn initWithContext(first_address: ?usize, debug_info: *DebugInfo, context: *const os.ucontext_t) !StackIterator {
524 var iterator = init(first_address, null);
525 iterator.unwind_state = .{
526 .debug_info = debug_info,
527 .dwarf_context = try DW.UnwindContext.init(debug_info.allocator, context, &isValidMemory),
528 };
524 // The implementation of DWARF unwinding on aarch64-macos is not complete. However, Apple mandates that
525 // the frame pointer register is always used, so on this platform we can safely use the FP-based unwinder.
526 if (comptime builtin.target.isDarwin() and native_arch == .aarch64) {
527 return init(first_address, context.mcontext.ss.fp);
528 } else {
529 var iterator = init(first_address, null);
530 iterator.unwind_state = .{
531 .debug_info = debug_info,
532 .dwarf_context = try DW.UnwindContext.init(debug_info.allocator, context, &isValidMemory),
533 };
529534
530 return iterator;
535 return iterator;
536 }
531537 }
532538
533539 pub fn deinit(self: *StackIterator) void {
......@@ -663,15 +669,15 @@ pub const StackIterator = struct {
663669 if (!unwind_state.failed) {
664670 if (unwind_state.dwarf_context.pc == 0) return null;
665671 if (self.next_unwind()) |return_address| {
672 self.fp = unwind_state.dwarf_context.getFp() catch 0;
666673 return return_address;
667674 } else |err| {
668675 unwind_state.last_error = err;
669676 unwind_state.failed = true;
670677
671678 // Fall back to fp-based unwinding on the first failure.
672 // We can't attempt it for other modules later in the
673 // stack because the full register state won't be unwound.
674 self.fp = unwind_state.dwarf_context.getFp() catch 0;
679 // We can't attempt it again for other modules higher in the
680 // stack because the full register state won't have been unwound.
675681 }
676682 }
677683 }
lib/std/dwarf.zig+2-2
......@@ -1782,7 +1782,7 @@ pub const DwarfInfo = struct {
17821782 };
17831783
17841784 var update_tail: ?*RegisterUpdate = null;
1785 var has_return_address= true;
1785 var has_return_address = true;
17861786 for (context.vm.rowColumns(row)) |column| {
17871787 if (column.register) |register| {
17881788 if (register == cie.return_address_register) {
......@@ -1871,7 +1871,7 @@ pub const UnwindContext = struct {
18711871 }
18721872
18731873 pub fn getFp(self: *const UnwindContext) !usize {
1874 return mem.readIntSliceNative(usize, try abi.regBytes(self.thread_context, abi.fpRegNum(self.reg_context), self.reg_context));
1874 return (try abi.regValueNative(usize, self.thread_context, abi.fpRegNum(self.reg_context), self.reg_context)).*;
18751875 }
18761876};
18771877