Skip to content

Commit cc3c0e2

Browse files
committed
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 parent 8e1141b commit cc3c0e2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/std/debug.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Wri
728728
}
729729
// `ret_addr` is the return address, which is *after* the function call.
730730
// 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);
732732
printed_any_frame = true;
733733
},
734734
};
@@ -777,7 +777,7 @@ pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_c
777777
for (st.instruction_addresses[0..captured_frames]) |ret_addr| {
778778
// `ret_addr` is the return address, which is *after* the function call.
779779
// 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);
781781
}
782782
if (n_frames > captured_frames) {
783783
tty_config.setColor(writer, .bold) catch {};
@@ -1011,6 +1011,13 @@ const StackIterator = union(enum) {
10111011
break :bias 0;
10121012
};
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+
10141021
fn applyOffset(addr: usize, comptime off: comptime_int) ?usize {
10151022
if (off >= 0) return math.add(usize, addr, off) catch return null;
10161023
return math.sub(usize, addr, -off) catch return null;

0 commit comments

Comments
 (0)