authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 09:37:51+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-15 13:59:17+02:00
log3d3aff0da9ef2af703a81097b9ca73de9b89adae
treef280c510738d150a9797b52eb95ce86d6cf5c956
parentf21a78b5a31b13d5b6bb84c23c4a35e64402d0e0
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: flush SPARC register windows from a new window

flushw and ta 3 flush all windows *except* the current one. So we need to do this in a new register window to get all of the ones we care about.

1 files changed, 10 insertions(+), 8 deletions(-)

lib/std/debug.zig+10-8
......@@ -807,14 +807,7 @@ const StackIterator = union(enum) {
807807 /// `@frameAddress` and `cpu_context.Native.current` as the caller's stack frame and
808808 /// our own are one and the same.
809809 inline fn init(opt_context_ptr: ?CpuContextPtr) error{CannotUnwindFromContext}!StackIterator {
810 if (builtin.cpu.arch.isSPARC()) {
811 // Flush all the register windows on stack.
812 if (builtin.cpu.has(.sparc, .v9)) {
813 asm volatile ("flushw" ::: .{ .memory = true });
814 } else {
815 asm volatile ("ta 3" ::: .{ .memory = true }); // ST_FLUSH_WINDOWS
816 }
817 }
810 flushSparcWindows();
818811 if (opt_context_ptr) |context_ptr| {
819812 if (SelfInfo == void or !SelfInfo.can_unwind) return error.CannotUnwindFromContext;
820813 // Use `di_first` here so we report the PC in the context before unwinding any further.
......@@ -842,6 +835,15 @@ const StackIterator = union(enum) {
842835 }
843836 }
844837
838 noinline fn flushSparcWindows() void {
839 // Flush all register windows except the current one (hence `noinline`). This ensures that
840 // we actually see meaningful data on the stack when we walk the frame chain.
841 if (comptime builtin.target.cpu.has(.sparc, .v9))
842 asm volatile ("flushw" ::: .{ .memory = true })
843 else
844 asm volatile ("ta 3" ::: .{ .memory = true }); // ST_FLUSH_WINDOWS
845 }
846
845847 const FpUsability = enum {
846848 /// FP unwinding is impractical on this target. For example, due to its very silly ABI
847849 /// design decisions, it's not possible to do generic FP unwinding on MIPS without a