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)...@@ -1335,7 +1335,11 @@ fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque)
1335 .x86,1335 .x86,
1336 .x86_64,1336 .x86_64,
1337 .arm,1337 .arm,
1338 .armeb,
1339 .thumb,
1340 .thumbeb,
1338 .aarch64,1341 .aarch64,
1342 .aarch64_be,
1339 => {1343 => {
1340 const ctx: *posix.ucontext_t = @ptrCast(@alignCast(ctx_ptr));1344 const ctx: *posix.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
1341 dumpStackTraceFromBase(ctx);1345 dumpStackTraceFromBase(ctx);
lib/std/debug/Dwarf/abi.zig+9-9
...@@ -35,8 +35,8 @@ pub fn ipRegNum(arch: Arch) ?u8 {...@@ -35,8 +35,8 @@ pub fn ipRegNum(arch: Arch) ?u8 {
35 return switch (arch) {35 return switch (arch) {
36 .x86 => 8,36 .x86 => 8,
37 .x86_64 => 16,37 .x86_64 => 16,
38 .arm => 15,38 .arm, .armeb, .thumb, .thumbeb => 15,
39 .aarch64 => 32,39 .aarch64, .aarch64_be => 32,
40 else => null,40 else => null,
41 };41 };
42}42}
...@@ -47,8 +47,8 @@ pub fn fpRegNum(arch: Arch, reg_context: RegisterContext) u8 {...@@ -47,8 +47,8 @@ pub fn fpRegNum(arch: Arch, reg_context: RegisterContext) u8 {
47 // (only in .eh_frame), and that is now the convention for MachO47 // (only in .eh_frame), and that is now the convention for MachO
48 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 4 else 5,48 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 4 else 5,
49 .x86_64 => 6,49 .x86_64 => 6,
50 .arm => 11,50 .arm, .armeb, .thumb, .thumbeb => 11,
51 .aarch64 => 29,51 .aarch64, .aarch64_be => 29,
52 else => unreachable,52 else => unreachable,
53 };53 };
54}54}
...@@ -57,8 +57,8 @@ pub fn spRegNum(arch: Arch, reg_context: RegisterContext) u8 {...@@ -57,8 +57,8 @@ pub fn spRegNum(arch: Arch, reg_context: RegisterContext) u8 {
57 return switch (arch) {57 return switch (arch) {
58 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 5 else 4,58 .x86 => if (reg_context.eh_frame and reg_context.is_macho) 5 else 4,
59 .x86_64 => 7,59 .x86_64 => 7,
60 .arm => 13,60 .arm, .armeb, .thumb, .thumbeb => 13,
61 .aarch64 => 31,61 .aarch64, .aarch64_be => 31,
62 else => unreachable,62 else => unreachable,
63 };63 };
64}64}
...@@ -131,7 +131,7 @@ pub fn regBytes(...@@ -131,7 +131,7 @@ pub fn regBytes(
131 16 => mem.asBytes(&thread_context_ptr.Rip),131 16 => mem.asBytes(&thread_context_ptr.Rip),
132 else => error.InvalidRegister,132 else => error.InvalidRegister,
133 },133 },
134 .aarch64 => switch (reg_number) {134 .aarch64, .aarch64_be => switch (reg_number) {
135 0...30 => mem.asBytes(&thread_context_ptr.DUMMYUNIONNAME.X[reg_number]),135 0...30 => mem.asBytes(&thread_context_ptr.DUMMYUNIONNAME.X[reg_number]),
136 31 => mem.asBytes(&thread_context_ptr.Sp),136 31 => mem.asBytes(&thread_context_ptr.Sp),
137 32 => mem.asBytes(&thread_context_ptr.Pc),137 32 => mem.asBytes(&thread_context_ptr.Pc),
...@@ -269,7 +269,7 @@ pub fn regBytes(...@@ -269,7 +269,7 @@ pub fn regBytes(
269 },269 },
270 else => error.UnimplementedOs,270 else => error.UnimplementedOs,
271 },271 },
272 .arm => switch (builtin.os.tag) {272 .arm, .armeb, .thumb, .thumbeb => switch (builtin.os.tag) {
273 .linux => switch (reg_number) {273 .linux => switch (reg_number) {
274 0 => mem.asBytes(&ucontext_ptr.mcontext.arm_r0),274 0 => mem.asBytes(&ucontext_ptr.mcontext.arm_r0),
275 1 => mem.asBytes(&ucontext_ptr.mcontext.arm_r1),275 1 => mem.asBytes(&ucontext_ptr.mcontext.arm_r1),
...@@ -292,7 +292,7 @@ pub fn regBytes(...@@ -292,7 +292,7 @@ pub fn regBytes(
292 },292 },
293 else => error.UnimplementedOs,293 else => error.UnimplementedOs,
294 },294 },
295 .aarch64 => switch (builtin.os.tag) {295 .aarch64, .aarch64_be => switch (builtin.os.tag) {
296 .macos, .ios, .watchos => switch (reg_number) {296 .macos, .ios, .watchos => switch (reg_number) {
297 0...28 => mem.asBytes(&ucontext_ptr.mcontext.ss.regs[reg_number]),297 0...28 => mem.asBytes(&ucontext_ptr.mcontext.ss.regs[reg_number]),
298 29 => mem.asBytes(&ucontext_ptr.mcontext.ss.fp),298 29 => mem.asBytes(&ucontext_ptr.mcontext.ss.fp),
lib/std/debug/SelfInfo.zig+5-5
...@@ -1419,7 +1419,7 @@ pub fn unwindFrameMachO(...@@ -1419,7 +1419,7 @@ pub fn unwindFrameMachO(
1419 return unwindFrameMachODwarf(context, ma, eh_frame orelse return error.MissingEhFrame, @intCast(encoding.value.x86_64.dwarf));1419 return unwindFrameMachODwarf(context, ma, eh_frame orelse return error.MissingEhFrame, @intCast(encoding.value.x86_64.dwarf));
1420 },1420 },
1421 },1421 },
1422 .aarch64 => switch (encoding.mode.arm64) {1422 .aarch64, .aarch64_be => switch (encoding.mode.arm64) {
1423 .OLD => return error.UnimplementedUnwindEncoding,1423 .OLD => return error.UnimplementedUnwindEncoding,
1424 .FRAMELESS => blk: {1424 .FRAMELESS => blk: {
1425 const sp = (try regValueNative(context.thread_context, spRegNum(reg_context), reg_context)).*;1425 const sp = (try regValueNative(context.thread_context, spRegNum(reg_context), reg_context)).*;
...@@ -1535,7 +1535,7 @@ pub const UnwindContext = struct {...@@ -1535,7 +1535,7 @@ pub const UnwindContext = struct {
1535/// Some platforms use pointer authentication - the upper bits of instruction pointers contain a signature.1535/// Some platforms use pointer authentication - the upper bits of instruction pointers contain a signature.
1536/// This function clears these signature bits to make the pointer usable.1536/// This function clears these signature bits to make the pointer usable.
1537pub inline fn stripInstructionPtrAuthCode(ptr: usize) usize {1537pub inline fn stripInstructionPtrAuthCode(ptr: usize) usize {
1538 if (native_arch == .aarch64) {1538 if (native_arch.isAARCH64()) {
1539 // `hint 0x07` maps to `xpaclri` (or `nop` if the hardware doesn't support it)1539 // `hint 0x07` maps to `xpaclri` (or `nop` if the hardware doesn't support it)
1540 // The save / restore is because `xpaclri` operates on x30 (LR)1540 // The save / restore is because `xpaclri` operates on x30 (LR)
1541 return asm (1541 return asm (
...@@ -1787,11 +1787,11 @@ pub fn supportsUnwinding(target: std.Target) bool {...@@ -1787,11 +1787,11 @@ pub fn supportsUnwinding(target: std.Target) bool {
1787 .linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,1787 .linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,
1788 else => false,1788 else => false,
1789 },1789 },
1790 .arm => switch (target.os.tag) {1790 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
1791 .linux => true,1791 .linux => true,
1792 else => false,1792 else => false,
1793 },1793 },
1794 .aarch64 => switch (target.os.tag) {1794 .aarch64, .aarch64_be => switch (target.os.tag) {
1795 .linux, .netbsd, .freebsd, .macos, .ios => true,1795 .linux, .netbsd, .freebsd, .macos, .ios => true,
1796 else => false,1796 else => false,
1797 },1797 },
...@@ -2194,7 +2194,7 @@ pub const VirtualMachine = struct {...@@ -2194,7 +2194,7 @@ pub const VirtualMachine = struct {
2194/// the .undefined rule by default, but allows ABI authors to override that.2194/// the .undefined rule by default, but allows ABI authors to override that.
2195fn getRegDefaultValue(reg_number: u8, context: *UnwindContext, out: []u8) !void {2195fn getRegDefaultValue(reg_number: u8, context: *UnwindContext, out: []u8) !void {
2196 switch (builtin.cpu.arch) {2196 switch (builtin.cpu.arch) {
2197 .aarch64 => {2197 .aarch64, .aarch64_be => {
2198 // Callee-saved registers are initialized as if they had the .same_value rule2198 // Callee-saved registers are initialized as if they had the .same_value rule
2199 if (reg_number >= 19 and reg_number <= 28) {2199 if (reg_number >= 19 and reg_number <= 28) {
2200 const src = try regBytes(context.thread_context, reg_number, context.reg_context);2200 const src = try regBytes(context.thread_context, reg_number, context.reg_context);