authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 09:54:48+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-15 13:59:17+02:00
logebc0b90eb709b31e66daddfef26f32e36f169fc0
treee8f11b3b3fca845cffbe6ecf398046031f9107c1
parent62a8cfd5fed1380331b10d20fbb7b08f206cf541
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: rename some constants for clarity


1 files changed, 19 insertions(+), 13 deletions(-)

lib/std/debug.zig+19-13
...@@ -938,8 +938,8 @@ const StackIterator = union(enum) {...@@ -938,8 +938,8 @@ const StackIterator = union(enum) {
938 .fp => |fp| {938 .fp => |fp| {
939 if (fp == 0) return .end; // we reached the "sentinel" base pointer939 if (fp == 0) return .end; // we reached the "sentinel" base pointer
940940
941 const bp_addr = applyOffset(fp, bp_offset) orelse return .end;941 const bp_addr = applyOffset(fp, fp_to_bp_offset) orelse return .end;
942 const ra_addr = applyOffset(fp, ra_offset) orelse return .end;942 const ra_addr = applyOffset(fp, fp_to_ra_offset) orelse return .end;
943943
944 if (bp_addr == 0 or !mem.isAligned(bp_addr, @alignOf(usize)) or944 if (bp_addr == 0 or !mem.isAligned(bp_addr, @alignOf(usize)) or
945 ra_addr == 0 or !mem.isAligned(ra_addr, @alignOf(usize)))945 ra_addr == 0 or !mem.isAligned(ra_addr, @alignOf(usize)))
...@@ -950,7 +950,7 @@ const StackIterator = union(enum) {...@@ -950,7 +950,7 @@ const StackIterator = union(enum) {
950950
951 const bp_ptr: *const usize = @ptrFromInt(bp_addr);951 const bp_ptr: *const usize = @ptrFromInt(bp_addr);
952 const ra_ptr: *const usize = @ptrFromInt(ra_addr);952 const ra_ptr: *const usize = @ptrFromInt(ra_addr);
953 const bp = applyOffset(bp_ptr.*, bp_bias) orelse return .end;953 const bp = applyOffset(bp_ptr.*, stack_bias) orelse return .end;
954954
955 // The stack grows downards, so `bp > fp` should always hold. If it doesn't, this955 // The stack grows downards, so `bp > fp` should always hold. If it doesn't, this
956 // frame is invalid, so we'll treat it as though it we reached end of stack. The956 // 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) {...@@ -967,29 +967,35 @@ const StackIterator = union(enum) {
967 }967 }
968968
969 /// Offset of the saved base pointer (previous frame pointer) wrt the frame pointer.969 /// Offset of the saved base pointer (previous frame pointer) wrt the frame pointer.
970 const bp_offset = off: {970 const fp_to_bp_offset = off: {
971 // On RISC-V the frame pointer points to the top of the saved register971 // On LoongArch and RISC-V, the frame pointer points to the top of the saved register area,
972 // area, on pretty much every other architecture it points to the stack972 // in which the base pointer is the first word.
973 // slot where the previous frame pointer is saved.
974 if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);973 if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
975 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.974 // On SPARC, the frame pointer points to the save area which holds 16 slots for the local
975 // and incoming registers. The base pointer (i6) is stored in its customary save slot.
976 if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);976 if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);
977 // Everywhere else, the frame pointer points directly to the location of the base pointer.
977 break :off 0;978 break :off 0;
978 };979 };
979980
980 /// Offset of the saved return address wrt the frame pointer.981 /// Offset of the saved return address wrt the frame pointer.
981 const ra_offset = off: {982 const fp_to_ra_offset = off: {
982 if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -1 * @sizeOf(usize);983 // On LoongArch and RISC-V, the frame pointer points to the top of the saved register area,
983 if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);984 // in which the return address is the second word.
985 if (native_arch.isRISCV() or native_arch.isLoongArch()) break :off -1 * @sizeOf(usize);
984 if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);986 if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);
985 // On s390x, r14 is the link register and we need to grab it from its customary slot in the987 // On s390x, r14 is the link register and we need to grab it from its customary slot in the
986 // register save area (ELF ABI s390x Supplement §1.2.2.2).988 // register save area (ELF ABI s390x Supplement §1.2.2.2).
987 if (native_arch == .s390x) break :off 14 * @sizeOf(usize);989 if (native_arch == .s390x) break :off 14 * @sizeOf(usize);
990 // On SPARC, the frame pointer points to the save area which holds 16 slots for the local
991 // and incoming registers. The return address (i7) is stored in its customary save slot.
992 if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);
988 break :off @sizeOf(usize);993 break :off @sizeOf(usize);
989 };994 };
990995
991 /// Value to add to a base pointer after loading it from the stack. Yes, SPARC really does this.996 /// Value to add to the stack pointer and frame/base pointers to get the real location being
992 const bp_bias = bias: {997 /// pointed to. Yes, SPARC really does this.
998 const stack_bias = bias: {
993 if (native_arch.isSPARC()) break :bias 2047;999 if (native_arch.isSPARC()) break :bias 2047;
994 break :bias 0;1000 break :bias 0;
995 };1001 };