| ... | ... | @@ -728,7 +728,7 @@ pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Wri |
| 728 | 728 | } |
| 729 | 729 | // `ret_addr` is the return address, which is *after* the function call. |
| 730 | 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 | 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 | 777 | for (st.instruction_addresses[0..captured_frames]) |ret_addr| { |
| 778 | 778 | // `ret_addr` is the return address, which is *after* the function call. |
| 779 | 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 | 782 | if (n_frames > captured_frames) { |
| 783 | 783 | tty_config.setColor(writer, .bold) catch {}; |
| ... | ... | @@ -1011,6 +1011,13 @@ const StackIterator = union(enum) { |
| 1011 | 1011 | break :bias 0; |
| 1012 | 1012 | }; |
| 1013 | 1013 | |
| 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 | 1021 | fn applyOffset(addr: usize, comptime off: comptime_int) ?usize { |
| 1015 | 1022 | if (off >= 0) return math.add(usize, addr, off) catch return null; |
| 1016 | 1023 | return math.sub(usize, addr, -off) catch return null; |