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 {...@@ -366,8 +366,18 @@ pub const StackIterator = struct {
366 // area, on pretty much every other architecture it points to the stack366 // area, on pretty much every other architecture it points to the stack
367 // slot where the previous frame pointer is saved.367 // slot where the previous frame pointer is saved.
368 2 * @sizeOf(usize)368 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)
369 else372 else
370 0;373 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
371 // Positive offset of the saved PC wrt the frame pointer.381 // Positive offset of the saved PC wrt the frame pointer.
372 const pc_offset = if (builtin.arch == .powerpc64le)382 const pc_offset = if (builtin.arch == .powerpc64le)
373 2 * @sizeOf(usize)383 2 * @sizeOf(usize)
...@@ -394,7 +404,7 @@ pub const StackIterator = struct {...@@ -394,7 +404,7 @@ pub const StackIterator = struct {
394 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)))404 if (fp == 0 or !mem.isAligned(fp, @alignOf(usize)))
395 return null;405 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
399 // Sanity check: the stack grows down thus all the parent frames must be409 // Sanity check: the stack grows down thus all the parent frames must be
400 // be at addresses that are greater (or equal) than the previous one.410 // be at addresses that are greater (or equal) than the previous one.