aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-10-13 11:07:39 -0400
committerGitHub <noreply@github.com>2019-10-13 11:07:39 -0400
commit9439bf3809de68a30a73451cc7648a266aba0a36 (patch)
tree254924500bbeae4756df98d67b54eb454030c391 /lib/std/debug.zig
parentae0628b30cdde8068dbefcbe6827f3339a9da088 (diff)
parent22e60df68024f3fd72c91ec7b17dbf7abc71c86c (diff)
downloadzig-9439bf3809de68a30a73451cc7648a266aba0a36.tar.gz
zig-9439bf3809de68a30a73451cc7648a266aba0a36.zip
Merge pull request #3446 from LemonBoy/riscv-things-x
More RISC-V stuff
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index a6bc0fedf3..41270bcd82 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -280,14 +280,23 @@ pub const StackIterator = struct {
};
}
+ // On some architectures such as x86 the frame pointer is the address where
+ // the previous fp is stored, while on some other architectures such as
+ // RISC-V it points to the "top" of the frame, just above where the previous
+ // fp and the return address are stored.
+ const fp_adjust_factor = if (builtin.arch == .riscv32 or builtin.arch == .riscv64)
+ 2 * @sizeOf(usize)
+ else
+ 0;
+
fn next(self: *StackIterator) ?usize {
- if (self.fp == 0) return null;
- self.fp = @intToPtr(*const usize, self.fp).*;
- if (self.fp == 0) return null;
+ if (self.fp < fp_adjust_factor) return null;
+ self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*;
+ if (self.fp < fp_adjust_factor) return null;
if (self.first_addr) |addr| {
- while (self.fp != 0) : (self.fp = @intToPtr(*const usize, self.fp).*) {
- const return_address = @intToPtr(*const usize, self.fp + @sizeOf(usize)).*;
+ while (self.fp >= fp_adjust_factor) : (self.fp = @intToPtr(*const usize, self.fp - fp_adjust_factor).*) {
+ const return_address = @intToPtr(*const usize, self.fp - fp_adjust_factor + @sizeOf(usize)).*;
if (addr == return_address) {
self.first_addr = null;
return return_address;
@@ -295,7 +304,7 @@ pub const StackIterator = struct {
}
}
- const return_address = @intToPtr(*const usize, self.fp + @sizeOf(usize)).*;
+ const return_address = @intToPtr(*const usize, self.fp - fp_adjust_factor + @sizeOf(usize)).*;
return return_address;
}
};