diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2025-10-14 09:39:15 +0200 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2025-10-15 13:59:17 +0200 |
| commit | b8dd40fde8aed212ffa8a98b45821ccdf0c2e17d (patch) | |
| tree | 83eb99de3c864c8e555210db3f7ee5ee4136c16b /lib/std/debug | |
| parent | 12b1d57df1e0efed6e5a3eb3933de7f08d42d6d5 (diff) | |
| download | zig-b8dd40fde8aed212ffa8a98b45821ccdf0c2e17d.tar.gz zig-b8dd40fde8aed212ffa8a98b45821ccdf0c2e17d.zip | |
std.debug.cpu_context.Sparc: flush register windows in current()
It's better to do this here than in StackIterator.init() so that
std.debug.cpu_context.Native.current() isn't a footgun on SPARC.
Diffstat (limited to 'lib/std/debug')
| -rw-r--r-- | lib/std/debug/cpu_context.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/std/debug/cpu_context.zig b/lib/std/debug/cpu_context.zig index 3450debba0..5dd2e283ed 100644 --- a/lib/std/debug/cpu_context.zig +++ b/lib/std/debug/cpu_context.zig @@ -870,6 +870,8 @@ const Sparc = extern struct { pub const Gpr = if (native_arch == .sparc64) u64 else u32; pub inline fn current() Sparc { + flushWindows(); + var ctx: Sparc = undefined; asm volatile (if (Gpr == u64) \\ stx %g0, [%l0 + 0] @@ -933,6 +935,15 @@ const Sparc = extern struct { return ctx; } + noinline fn flushWindows() void { + // Flush all register windows except the current one (hence `noinline`). This ensures that + // we actually see meaningful data on the stack when we walk the frame chain. + if (comptime builtin.target.cpu.has(.sparc, .v9)) + asm volatile ("flushw" ::: .{ .memory = true }) + else + asm volatile ("ta 3" ::: .{ .memory = true }); // ST_FLUSH_WINDOWS + } + pub fn dwarfRegisterBytes(ctx: *Sparc, register_num: u16) DwarfRegisterError![]u8 { switch (register_num) { 0...7 => return @ptrCast(&ctx.g[register_num]), |
