mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.debug: rename some constants for clarity
This commit is contained in:
parent
62a8cfd5fe
commit
ebc0b90eb7
1 changed files with 19 additions and 13 deletions
|
|
@ -938,8 +938,8 @@ const StackIterator = union(enum) {
|
||||||
.fp => |fp| {
|
.fp => |fp| {
|
||||||
if (fp == 0) return .end; // we reached the "sentinel" base pointer
|
if (fp == 0) return .end; // we reached the "sentinel" base pointer
|
||||||
|
|
||||||
const bp_addr = applyOffset(fp, bp_offset) orelse return .end;
|
const bp_addr = applyOffset(fp, fp_to_bp_offset) orelse return .end;
|
||||||
const ra_addr = applyOffset(fp, ra_offset) orelse return .end;
|
const ra_addr = applyOffset(fp, fp_to_ra_offset) orelse return .end;
|
||||||
|
|
||||||
if (bp_addr == 0 or !mem.isAligned(bp_addr, @alignOf(usize)) or
|
if (bp_addr == 0 or !mem.isAligned(bp_addr, @alignOf(usize)) or
|
||||||
ra_addr == 0 or !mem.isAligned(ra_addr, @alignOf(usize)))
|
ra_addr == 0 or !mem.isAligned(ra_addr, @alignOf(usize)))
|
||||||
|
|
@ -950,7 +950,7 @@ const StackIterator = union(enum) {
|
||||||
|
|
||||||
const bp_ptr: *const usize = @ptrFromInt(bp_addr);
|
const bp_ptr: *const usize = @ptrFromInt(bp_addr);
|
||||||
const ra_ptr: *const usize = @ptrFromInt(ra_addr);
|
const ra_ptr: *const usize = @ptrFromInt(ra_addr);
|
||||||
const bp = applyOffset(bp_ptr.*, bp_bias) orelse return .end;
|
const bp = applyOffset(bp_ptr.*, stack_bias) orelse return .end;
|
||||||
|
|
||||||
// The stack grows downards, so `bp > fp` should always hold. If it doesn't, this
|
// The stack grows downards, so `bp > fp` should always hold. If it doesn't, this
|
||||||
// frame is invalid, so we'll treat it as though it we reached end of stack. The
|
// frame is invalid, so we'll treat it as though it we reached end of stack. The
|
||||||
|
|
@ -967,29 +967,35 @@ const StackIterator = union(enum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Offset of the saved base pointer (previous frame pointer) wrt the frame pointer.
|
/// Offset of the saved base pointer (previous frame pointer) wrt the frame pointer.
|
||||||
const bp_offset = off: {
|
const fp_to_bp_offset = off: {
|
||||||
// On RISC-V the frame pointer points to the top of the saved register
|
// On LoongArch and RISC-V, the frame pointer points to the top of the saved register area,
|
||||||
// area, on pretty much every other architecture it points to the stack
|
// in which the base pointer is the first word.
|
||||||
// slot where the previous frame pointer is saved.
|
|
||||||
if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
|
if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
|
||||||
// On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
|
// On SPARC, the frame pointer points to the save area which holds 16 slots for the local
|
||||||
|
// and incoming registers. The base pointer (i6) is stored in its customary save slot.
|
||||||
if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);
|
if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);
|
||||||
|
// Everywhere else, the frame pointer points directly to the location of the base pointer.
|
||||||
break :off 0;
|
break :off 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Offset of the saved return address wrt the frame pointer.
|
/// Offset of the saved return address wrt the frame pointer.
|
||||||
const ra_offset = off: {
|
const fp_to_ra_offset = off: {
|
||||||
if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -1 * @sizeOf(usize);
|
// On LoongArch and RISC-V, the frame pointer points to the top of the saved register area,
|
||||||
if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);
|
// in which the return address is the second word.
|
||||||
|
if (native_arch.isRISCV() or native_arch.isLoongArch()) break :off -1 * @sizeOf(usize);
|
||||||
if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);
|
if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);
|
||||||
// On s390x, r14 is the link register and we need to grab it from its customary slot in the
|
// On s390x, r14 is the link register and we need to grab it from its customary slot in the
|
||||||
// register save area (ELF ABI s390x Supplement §1.2.2.2).
|
// register save area (ELF ABI s390x Supplement §1.2.2.2).
|
||||||
if (native_arch == .s390x) break :off 14 * @sizeOf(usize);
|
if (native_arch == .s390x) break :off 14 * @sizeOf(usize);
|
||||||
|
// On SPARC, the frame pointer points to the save area which holds 16 slots for the local
|
||||||
|
// and incoming registers. The return address (i7) is stored in its customary save slot.
|
||||||
|
if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);
|
||||||
break :off @sizeOf(usize);
|
break :off @sizeOf(usize);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Value to add to a base pointer after loading it from the stack. Yes, SPARC really does this.
|
/// Value to add to the stack pointer and frame/base pointers to get the real location being
|
||||||
const bp_bias = bias: {
|
/// pointed to. Yes, SPARC really does this.
|
||||||
|
const stack_bias = bias: {
|
||||||
if (native_arch.isSPARC()) break :bias 2047;
|
if (native_arch.isSPARC()) break :bias 2047;
|
||||||
break :bias 0;
|
break :bias 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue