| author | |
| committer | |
| log | b8dd40fde8aed212ffa8a98b45821ccdf0c2e17d |
| tree | 83eb99de3c864c8e555210db3f7ee5ee4136c16b |
| parent | 12b1d57df1e0efed6e5a3eb3933de7f08d42d6d5 |
| signature |
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.2 files changed, 12 insertions(+), 1 deletions(-)
lib/std/debug.zig+1-1| ... | ... | @@ -807,7 +807,6 @@ const StackIterator = union(enum) { |
| 807 | 807 | /// `@frameAddress` and `cpu_context.Native.current` as the caller's stack frame and |
| 808 | 808 | /// our own are one and the same. |
| 809 | 809 | inline fn init(opt_context_ptr: ?CpuContextPtr) error{CannotUnwindFromContext}!StackIterator { |
| 810 | flushSparcWindows(); | |
| 811 | 810 | if (opt_context_ptr) |context_ptr| { |
| 812 | 811 | if (SelfInfo == void or !SelfInfo.can_unwind) return error.CannotUnwindFromContext; |
| 813 | 812 | // Use `di_first` here so we report the PC in the context before unwinding any further. |
| ... | ... | @@ -826,6 +825,7 @@ const StackIterator = union(enum) { |
| 826 | 825 | // in our caller's frame and above. |
| 827 | 826 | return .{ .di = .init(&.current()) }; |
| 828 | 827 | } |
| 828 | flushSparcWindows(); | |
| 829 | 829 | return .{ .fp = @frameAddress() }; |
| 830 | 830 | } |
| 831 | 831 | fn deinit(si: *StackIterator) void { |
lib/std/debug/cpu_context.zig+11| ... | ... | @@ -870,6 +870,8 @@ const Sparc = extern struct { |
| 870 | 870 | pub const Gpr = if (native_arch == .sparc64) u64 else u32; |
| 871 | 871 | |
| 872 | 872 | pub inline fn current() Sparc { |
| 873 | flushWindows(); | |
| 874 | ||
| 873 | 875 | var ctx: Sparc = undefined; |
| 874 | 876 | asm volatile (if (Gpr == u64) |
| 875 | 877 | \\ stx %g0, [%l0 + 0] |
| ... | ... | @@ -933,6 +935,15 @@ const Sparc = extern struct { |
| 933 | 935 | return ctx; |
| 934 | 936 | } |
| 935 | 937 | |
| 938 | noinline fn flushWindows() void { | |
| 939 | // Flush all register windows except the current one (hence `noinline`). This ensures that | |
| 940 | // we actually see meaningful data on the stack when we walk the frame chain. | |
| 941 | if (comptime builtin.target.cpu.has(.sparc, .v9)) | |
| 942 | asm volatile ("flushw" ::: .{ .memory = true }) | |
| 943 | else | |
| 944 | asm volatile ("ta 3" ::: .{ .memory = true }); // ST_FLUSH_WINDOWS | |
| 945 | } | |
| 946 | ||
| 936 | 947 | pub fn dwarfRegisterBytes(ctx: *Sparc, register_num: u16) DwarfRegisterError![]u8 { |
| 937 | 948 | switch (register_num) { |
| 938 | 949 | 0...7 => return @ptrCast(&ctx.g[register_num]), |