authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-04 08:29:18+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-04 08:29:42+01:00
logaf71694dd946a88bf0db55e4513223e344bfde40
treee3605ef12a6fb989ccdeb0a6d2e2c8c2bfb31cc0
parent4049be90de6a557c1ab522363fddbb71d3ccdb18
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: Add handling for armeb, thumb, thumbeb, and aarch64_be.


3 files changed, 18 insertions(+), 14 deletions(-)

lib/std/debug.zig+4
......@@ -1335,7 +1335,11 @@ fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque)
13351335 .x86,
13361336 .x86_64,
13371337 .arm,
1338 .armeb,
1339 .thumb,
1340 .thumbeb,
13381341 .aarch64,
1342 .aarch64_be,
13391343 => {
13401344 const ctx: *posix.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
13411345 dumpStackTraceFromBase(ctx);
lib/std/debug/Dwarf/abi.zig+9-9
......@@ -35,8 +35,8 @@ pub fn ipRegNum(arch: Arch) ?u8 {
3535 return switch (arch) {
3636 .x86 => 8,
3737 .x86_64 => 16,
38 .arm => 15,
39 .aarch64 => 32,
38 .arm, .armeb, .thumb, .thumbeb => 15,
39 .aarch64, .aarch64_be => 32,
4040 else => null,
4141 };
4242}
......@@ -47,8 +47,8 @@ pub fn fpRegNum(arch: Arch, reg_context: RegisterContext) u8 {
4747 // (only in .eh_frame), and that is now the convention for MachO
4848 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 4 else 5,
4949 .x86_64 => 6,
50 .arm => 11,
51 .aarch64 => 29,
50 .arm, .armeb, .thumb, .thumbeb => 11,
51 .aarch64, .aarch64_be => 29,
5252 else => unreachable,
5353 };
5454}
......@@ -57,8 +57,8 @@ pub fn spRegNum(arch: Arch, reg_context: RegisterContext) u8 {
5757 return switch (arch) {
5858 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 5 else 4,
5959 .x86_64 => 7,
60 .arm => 13,
61 .aarch64 => 31,
60 .arm, .armeb, .thumb, .thumbeb => 13,
61 .aarch64, .aarch64_be => 31,
6262 else => unreachable,
6363 };
6464}
......@@ -131,7 +131,7 @@ pub fn regBytes(
131131 16 => mem.asBytes(&thread_context_ptr.Rip),
132132 else => error.InvalidRegister,
133133 },
134 .aarch64 => switch (reg_number) {
134 .aarch64, .aarch64_be => switch (reg_number) {
135135 0...30 => mem.asBytes(&thread_context_ptr.DUMMYUNIONNAME.X[reg_number]),
136136 31 => mem.asBytes(&thread_context_ptr.Sp),
137137 32 => mem.asBytes(&thread_context_ptr.Pc),
......@@ -269,7 +269,7 @@ pub fn regBytes(
269269 },
270270 else => error.UnimplementedOs,
271271 },
272 .arm => switch (builtin.os.tag) {
272 .arm, .armeb, .thumb, .thumbeb => switch (builtin.os.tag) {
273273 .linux => switch (reg_number) {
274274 0 => mem.asBytes(&ucontext_ptr.mcontext.arm_r0),
275275 1 => mem.asBytes(&ucontext_ptr.mcontext.arm_r1),
......@@ -292,7 +292,7 @@ pub fn regBytes(
292292 },
293293 else => error.UnimplementedOs,
294294 },
295 .aarch64 => switch (builtin.os.tag) {
295 .aarch64, .aarch64_be => switch (builtin.os.tag) {
296296 .macos, .ios, .watchos => switch (reg_number) {
297297 0...28 => mem.asBytes(&ucontext_ptr.mcontext.ss.regs[reg_number]),
298298 29 => mem.asBytes(&ucontext_ptr.mcontext.ss.fp),
lib/std/debug/SelfInfo.zig+5-5
......@@ -1419,7 +1419,7 @@ pub fn unwindFrameMachO(
14191419 return unwindFrameMachODwarf(context, ma, eh_frame orelse return error.MissingEhFrame, @intCast(encoding.value.x86_64.dwarf));
14201420 },
14211421 },
1422 .aarch64 => switch (encoding.mode.arm64) {
1422 .aarch64, .aarch64_be => switch (encoding.mode.arm64) {
14231423 .OLD => return error.UnimplementedUnwindEncoding,
14241424 .FRAMELESS => blk: {
14251425 const sp = (try regValueNative(context.thread_context, spRegNum(reg_context), reg_context)).*;
......@@ -1535,7 +1535,7 @@ pub const UnwindContext = struct {
15351535/// Some platforms use pointer authentication - the upper bits of instruction pointers contain a signature.
15361536/// This function clears these signature bits to make the pointer usable.
15371537pub inline fn stripInstructionPtrAuthCode(ptr: usize) usize {
1538 if (native_arch == .aarch64) {
1538 if (native_arch.isAARCH64()) {
15391539 // `hint 0x07` maps to `xpaclri` (or `nop` if the hardware doesn't support it)
15401540 // The save / restore is because `xpaclri` operates on x30 (LR)
15411541 return asm (
......@@ -1787,11 +1787,11 @@ pub fn supportsUnwinding(target: std.Target) bool {
17871787 .linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,
17881788 else => false,
17891789 },
1790 .arm => switch (target.os.tag) {
1790 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
17911791 .linux => true,
17921792 else => false,
17931793 },
1794 .aarch64 => switch (target.os.tag) {
1794 .aarch64, .aarch64_be => switch (target.os.tag) {
17951795 .linux, .netbsd, .freebsd, .macos, .ios => true,
17961796 else => false,
17971797 },
......@@ -2194,7 +2194,7 @@ pub const VirtualMachine = struct {
21942194/// the .undefined rule by default, but allows ABI authors to override that.
21952195fn getRegDefaultValue(reg_number: u8, context: *UnwindContext, out: []u8) !void {
21962196 switch (builtin.cpu.arch) {
2197 .aarch64 => {
2197 .aarch64, .aarch64_be => {
21982198 // Callee-saved registers are initialized as if they had the .same_value rule
21992199 if (reg_number >= 19 and reg_number <= 28) {
22002200 const src = try regBytes(context.thread_context, reg_number, context.reg_context);