authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2021-02-04 20:51:41+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2021-02-04 20:51:41+07:00
log1eb2e4801448aca29471bf6f7582135ddafb15fe
tree63bdd5c92fe67a3bbac31cf01d2c9df66904ede1
parent2d447b57ccfd1a65383bf7ca9f882c7e69e94f2b

std.debug.StackIterator: account for SPARC %fp quirk

On SPARC, previous %fp is saved with a 14 slots offset from current %fp+bias. Also account for the bias constant at the new_fp calculation.

1 files changed, 11 insertions(+), 1 deletions(-)

lib/std/debug.zig+11-1
......@@ -366,8 +366,18 @@ pub const StackIterator = struct {
366366 // area, on pretty much every other architecture it points to the stack
367367 // slot where the previous frame pointer is saved.
368368 2 * @sizeOf(usize)
369 else if (builtin.arch.isSPARC())
370 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
371 14 * @sizeOf(usize)
369372 else
370373 0;
374
375 const fp_bias = if (builtin.arch.isSPARC())
376 // On SPARC frame pointers are biased by a constant.
377 2047
378 else
379 0;
380
371381 // Positive offset of the saved PC wrt the frame pointer.
372382 const pc_offset = if (builtin.arch == .powerpc64le)
373383 2 * @sizeOf(usize)
......@@ -394,7 +404,7 @@ pub const StackIterator = struct {
394404 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)))
395405 return null;
396406
397 const new_fp = @intToPtr(*const usize, fp).*;
407 const new_fp = math.add(usize, @intToPtr(*const usize, fp).*, fp_bias) catch return null;
398408
399409 // Sanity check: the stack grows down thus all the parent frames must be
400410 // be at addresses that are greater (or equal) than the previous one.