authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 09:57:36+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-15 13:59:17+02:00
logdd7819220af9f4eead99bc8fbd969c98323b8258
tree43bb1d12fc8f592d01ec241e798060a08e20fc2f
parent912fed338019487ec025ecbe3cd27134d75fe6e4
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: fix return addresses being off on SPARC

The return address points to the call instruction on SPARC, so the actual return address is 8 bytes after. This means that we shouldn't do the return address adjustment that we normally do.

1 files changed, 9 insertions(+), 2 deletions(-)

lib/std/debug.zig+9-2
...@@ -728,7 +728,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Wri...@@ -728,7 +728,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Wri
728 }728 }
729 // `ret_addr` is the return address, which is *after* the function call.729 // `ret_addr` is the return address, which is *after* the function call.
730 // Subtract 1 to get an address *in* the function call for a better source location.730 // Subtract 1 to get an address *in* the function call for a better source location.
731 try printSourceAtAddress(di_gpa, di, writer, ret_addr -| 1, tty_config);731 try printSourceAtAddress(di_gpa, di, writer, ret_addr -| StackIterator.ra_call_offset, tty_config);
732 printed_any_frame = true;732 printed_any_frame = true;
733 },733 },
734 };734 };
...@@ -777,7 +777,7 @@ pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_c...@@ -777,7 +777,7 @@ pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_c
777 for (st.instruction_addresses[0..captured_frames]) |ret_addr| {777 for (st.instruction_addresses[0..captured_frames]) |ret_addr| {
778 // `ret_addr` is the return address, which is *after* the function call.778 // `ret_addr` is the return address, which is *after* the function call.
779 // Subtract 1 to get an address *in* the function call for a better source location.779 // Subtract 1 to get an address *in* the function call for a better source location.
780 try printSourceAtAddress(di_gpa, di, writer, ret_addr -| 1, tty_config);780 try printSourceAtAddress(di_gpa, di, writer, ret_addr -| StackIterator.ra_call_offset, tty_config);
781 }781 }
782 if (n_frames > captured_frames) {782 if (n_frames > captured_frames) {
783 tty_config.setColor(writer, .bold) catch {};783 tty_config.setColor(writer, .bold) catch {};
...@@ -1011,6 +1011,13 @@ const StackIterator = union(enum) {...@@ -1011,6 +1011,13 @@ const StackIterator = union(enum) {
1011 break :bias 0;1011 break :bias 0;
1012 };1012 };
10131013
1014 /// On some oddball architectures, a return address points to the call instruction rather than
1015 /// the instruction following it.
1016 const ra_call_offset = off: {
1017 if (native_arch.isSPARC()) break :off 0;
1018 break :off 1;
1019 };
1020
1014 fn applyOffset(addr: usize, comptime off: comptime_int) ?usize {1021 fn applyOffset(addr: usize, comptime off: comptime_int) ?usize {
1015 if (off >= 0) return math.add(usize, addr, off) catch return null;1022 if (off >= 0) return math.add(usize, addr, off) catch return null;
1016 return math.sub(usize, addr, -off) catch return null;1023 return math.sub(usize, addr, -off) catch return null;