authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-28 14:07:24+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-28 14:16:50+02:00
logfb1e767ff8a6f4c32865020e36df4038434ecc65
tree08d90a2612e1fa7daded4c739e707ee41eb483fa
parent9ae517714efba1017e5d0ee76f71c6beda015697
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: apply stack bias to the frame pointer fetched from the CPU context

Unbreaks segfault stack tracing on SPARC.

1 files changed, 7 insertions(+), 5 deletions(-)

lib/std/debug.zig+7-5
...@@ -1086,10 +1086,12 @@ const StackIterator = union(enum) {...@@ -1086,10 +1086,12 @@ const StackIterator = union(enum) {
1086 switch (it.*) {1086 switch (it.*) {
1087 .ctx_first => |context_ptr| {1087 .ctx_first => |context_ptr| {
1088 // After the first frame, start actually unwinding.1088 // After the first frame, start actually unwinding.
1089 it.* = if (SelfInfo != void and SelfInfo.can_unwind and fp_usability != .ideal)1089 if (SelfInfo != void and SelfInfo.can_unwind and fp_usability != .ideal) {
1090 .{ .di = .init(context_ptr) }1090 it.* = .{ .di = .init(context_ptr) };
1091 else1091 } else {
1092 .{ .fp = context_ptr.getFp() };1092 const fp = applyOffset(context_ptr.getFp(), stack_bias) orelse return .end;
1093 it.* = .{ .fp = fp };
1094 }
10931095
1094 // The caller expects *return* addresses, where they will subtract 1 to find the address of the call.1096 // The caller expects *return* addresses, where they will subtract 1 to find the address of the call.
1095 // However, we have the actual current PC, which should not be adjusted. Compensate by adding 1.1097 // However, we have the actual current PC, which should not be adjusted. Compensate by adding 1.
...@@ -1099,7 +1101,7 @@ const StackIterator = union(enum) {...@@ -1099,7 +1101,7 @@ const StackIterator = union(enum) {
1099 const di = getSelfDebugInfo() catch unreachable;1101 const di = getSelfDebugInfo() catch unreachable;
1100 const ret_addr = di.unwindFrame(io, unwind_context) catch |err| {1102 const ret_addr = di.unwindFrame(io, unwind_context) catch |err| {
1101 const pc = unwind_context.pc;1103 const pc = unwind_context.pc;
1102 const fp = unwind_context.getFp();1104 const fp = applyOffset(unwind_context.getFp(), stack_bias) orelse return .end;
1103 unwind_context.deinit();1105 unwind_context.deinit();
1104 it.* = .{ .fp = fp };1106 it.* = .{ .fp = fp };
1105 return .{ .switch_to_fp = .{1107 return .{ .switch_to_fp = .{