authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-07 02:20:57+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-07 16:47:57+02:00
log7fdd5704edfe960ec3fafc82e5a724b8882207eb
treec2ab3676f61e4ab9c4e313e1d5a81cd719088030
parentde3b22db4db5e95d3a4a30333784e8d6c2cc3818
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug.cpu_context: map a bunch of known registers as unsupported instead of invalid


1 files changed, 81 insertions(+), 8 deletions(-)

lib/std/debug/cpu_context.zig+81-8
...@@ -341,7 +341,7 @@ pub const X86 = struct {...@@ -341,7 +341,7 @@ pub const X86 = struct {
341 // x86-macos is a deprecated target which is not supported by the Zig Standard Library.341 // x86-macos is a deprecated target which is not supported by the Zig Standard Library.
342 0...8 => return @ptrCast(&ctx.gprs.values[register_num]),342 0...8 => return @ptrCast(&ctx.gprs.values[register_num]),
343343
344 9 => return error.UnsupportedRegister, // rflags344 9 => return error.UnsupportedRegister, // eflags
345 11...18 => return error.UnsupportedRegister, // st0 - st7345 11...18 => return error.UnsupportedRegister, // st0 - st7
346 21...28 => return error.UnsupportedRegister, // xmm0 - xmm7346 21...28 => return error.UnsupportedRegister, // xmm0 - xmm7
347 29...36 => return error.UnsupportedRegister, // mm0 - mm7347 29...36 => return error.UnsupportedRegister, // mm0 - mm7
...@@ -349,7 +349,7 @@ pub const X86 = struct {...@@ -349,7 +349,7 @@ pub const X86 = struct {
349 40...45 => return error.UnsupportedRegister, // es, cs, ss, ds, fs, gs349 40...45 => return error.UnsupportedRegister, // es, cs, ss, ds, fs, gs
350 48 => return error.UnsupportedRegister, // tr350 48 => return error.UnsupportedRegister, // tr
351 49 => return error.UnsupportedRegister, // ldtr351 49 => return error.UnsupportedRegister, // ldtr
352 93...94 => return error.UnsupportedRegister, // fs.base, gs.base352 93...100 => return error.UnsupportedRegister, // k0 - k7 (AVX-512)
353353
354 else => return error.InvalidRegister,354 else => return error.InvalidRegister,
355 }355 }
...@@ -417,6 +417,9 @@ pub const X86_64 = struct {...@@ -417,6 +417,9 @@ pub const X86_64 = struct {
417 64 => return error.UnsupportedRegister, // mxcsr417 64 => return error.UnsupportedRegister, // mxcsr
418 65 => return error.UnsupportedRegister, // fcw418 65 => return error.UnsupportedRegister, // fcw
419 66 => return error.UnsupportedRegister, // fsw419 66 => return error.UnsupportedRegister, // fsw
420 67...82 => return error.UnsupportedRegister, // xmm16 - xmm31 (AVX-512)
421 118...125 => return error.UnsupportedRegister, // k0 - k7 (AVX-512)
422 130...145 => return error.UnsupportedRegister, // r16 - r31 (APX)
420423
421 else => return error.InvalidRegister,424 else => return error.InvalidRegister,
422 }425 }
...@@ -520,13 +523,13 @@ pub const Aarch64 = extern struct {...@@ -520,13 +523,13 @@ pub const Aarch64 = extern struct {
520 31 => return @ptrCast(&ctx.sp),523 31 => return @ptrCast(&ctx.sp),
521 32 => return @ptrCast(&ctx.pc),524 32 => return @ptrCast(&ctx.pc),
522525
523 33 => return error.UnsupportedRegister, // ELF_mode526 33 => return error.UnsupportedRegister, // ELR_mode
524 34 => return error.UnsupportedRegister, // RA_SIGN_STATE527 34 => return error.UnsupportedRegister, // RA_SIGN_STATE
525 35 => return error.UnsupportedRegister, // TPIDRRO_ELO528 35 => return error.UnsupportedRegister, // TPIDRRO_ELO
526 36 => return error.UnsupportedRegister, // RPIDR_ELO529 36 => return error.UnsupportedRegister, // TPIDR_ELO
527 37 => return error.UnsupportedRegister, // RPIDR_EL1530 37 => return error.UnsupportedRegister, // TPIDR_EL1
528 38 => return error.UnsupportedRegister, // RPIDR_EL2531 38 => return error.UnsupportedRegister, // TPIDR_EL2
529 39 => return error.UnsupportedRegister, // RPIDR_EL3532 39 => return error.UnsupportedRegister, // TPIDR_EL3
530 46 => return error.UnsupportedRegister, // VG533 46 => return error.UnsupportedRegister, // VG
531 47 => return error.UnsupportedRegister, // FFR534 47 => return error.UnsupportedRegister, // FFR
532 48...63 => return error.UnsupportedRegister, // P0 - P15535 48...63 => return error.UnsupportedRegister, // P0 - P15
...@@ -701,6 +704,8 @@ pub const LoongArch = extern struct {...@@ -701,6 +704,8 @@ pub const LoongArch = extern struct {
701 0...31 => return @ptrCast(&ctx.r[register_num]),704 0...31 => return @ptrCast(&ctx.r[register_num]),
702 64 => return @ptrCast(&ctx.pc),705 64 => return @ptrCast(&ctx.pc),
703706
707 32...63 => return error.UnsupportedRegister, // f0 - f31
708
704 else => return error.InvalidRegister,709 else => return error.InvalidRegister,
705 }710 }
706 }711 }
...@@ -811,6 +816,18 @@ pub const Mips = extern struct {...@@ -811,6 +816,18 @@ pub const Mips = extern struct {
811 0...31 => return @ptrCast(&ctx.r[register_num]),816 0...31 => return @ptrCast(&ctx.r[register_num]),
812 66 => return @ptrCast(&ctx.pc),817 66 => return @ptrCast(&ctx.pc),
813818
819 // Who the hell knows what numbers exist for this architecture? What's an ABI
820 // specification anyway? We don't need that nonsense.
821 32...63 => return error.UnsupportedRegister, // f0 - f31, w0 - w31
822 64 => return error.UnsupportedRegister, // hi0 (ac0)
823 65 => return error.UnsupportedRegister, // lo0 (ac0)
824 176 => return error.UnsupportedRegister, // hi1 (ac1)
825 177 => return error.UnsupportedRegister, // lo1 (ac1)
826 178 => return error.UnsupportedRegister, // hi2 (ac2)
827 179 => return error.UnsupportedRegister, // lo2 (ac2)
828 180 => return error.UnsupportedRegister, // hi3 (ac3)
829 181 => return error.UnsupportedRegister, // lo3 (ac3)
830
814 else => return error.InvalidRegister,831 else => return error.InvalidRegister,
815 }832 }
816 }833 }
...@@ -914,11 +931,59 @@ pub const Powerpc = extern struct {...@@ -914,11 +931,59 @@ pub const Powerpc = extern struct {
914 }931 }
915932
916 pub fn dwarfRegisterBytes(ctx: *Powerpc, register_num: u16) DwarfRegisterError![]u8 {933 pub fn dwarfRegisterBytes(ctx: *Powerpc, register_num: u16) DwarfRegisterError![]u8 {
934 // References:
935 //
936 // * System V Application Binary Interface - PowerPC Processor Supplement §3-46
937 // * Power Architecture 32-bit Application Binary Interface Supplement 1.0 - Linux & Embedded §3.4
938 // * 64-bit ELF V2 ABI Specification - Power Architecture Revision 1.5 §2.4
939 // * ??? AIX?
940 //
941 // Are we having fun yet?
942
943 if (Gpr == u64) switch (register_num) {
944 65 => return @ptrCast(&ctx.lr), // lr
945
946 66 => return error.UnsupportedRegister, // ctr
947 68...75 => return error.UnsupportedRegister, // cr0 - cr7
948 76 => return error.UnsupportedRegister, // xer
949 77...108 => return error.UnsupportedRegister, // vr0 - vr31
950 109 => return error.UnsupportedRegister, // vrsave (LLVM)
951 110 => return error.UnsupportedRegister, // vscr
952 114 => return error.UnsupportedRegister, // tfhar
953 115 => return error.UnsupportedRegister, // tfiar
954 116 => return error.UnsupportedRegister, // texasr
955
956 else => {},
957 } else switch (register_num) {
958 65 => return @ptrCast(&ctx.lr), // fpscr (SVR4 / EABI), or lr if you ask LLVM
959 108 => return @ptrCast(&ctx.lr),
960
961 64 => return error.UnsupportedRegister, // cr
962 66 => return error.UnsupportedRegister, // msr (SVR4 / EABI), or ctr if you ask LLVM
963 68...75 => return error.UnsupportedRegister, // cr0 - cr7 if you ask LLVM
964 76 => return error.UnsupportedRegister, // xer if you ask LLVM
965 99 => return error.UnsupportedRegister, // acc
966 100 => return error.UnsupportedRegister, // mq
967 101 => return error.UnsupportedRegister, // xer
968 102...107 => return error.UnsupportedRegister, // SPRs
969 109 => return error.UnsupportedRegister, // ctr
970 110...111 => return error.UnsupportedRegister, // SPRs
971 112 => return error.UnsupportedRegister, // spefscr
972 113...1123 => return error.UnsupportedRegister, // SPRs
973 1124...1155 => return error.UnsupportedRegister, // SPE v0 - v31
974 1200...1231 => return error.UnsupportedRegister, // SPE upper r0 - r31
975 3072...4095 => return error.UnsupportedRegister, // DCRs
976 4096...5120 => return error.UnsupportedRegister, // PMRs
977
978 else => {},
979 }
980
917 switch (register_num) {981 switch (register_num) {
918 0...31 => return @ptrCast(&ctx.r[register_num]),982 0...31 => return @ptrCast(&ctx.r[register_num]),
919 65 => return @ptrCast(&ctx.lr),
920 67 => return @ptrCast(&ctx.pc),983 67 => return @ptrCast(&ctx.pc),
921984
985 32...63 => return error.UnsupportedRegister, // f0 - f31
986
922 else => return error.InvalidRegister,987 else => return error.InvalidRegister,
923 }988 }
924 }989 }
...@@ -1019,6 +1084,12 @@ pub const Riscv = extern struct {...@@ -1019,6 +1084,12 @@ pub const Riscv = extern struct {
1019 0...31 => return @ptrCast(&ctx.r[register_num]),1084 0...31 => return @ptrCast(&ctx.r[register_num]),
1020 65 => return @ptrCast(&ctx.pc),1085 65 => return @ptrCast(&ctx.pc),
10211086
1087 32...63 => return error.UnsupportedRegister, // f0 - f31
1088 64 => return error.UnsupportedRegister, // Alternate Frame Return Column
1089 96...127 => return error.UnsupportedRegister, // v0 - v31
1090 3072...4095 => return error.UnsupportedRegister, // Custom extensions
1091 4096...8191 => return error.UnsupportedRegister, // CSRs
1092
1022 else => return error.InvalidRegister,1093 else => return error.InvalidRegister,
1023 }1094 }
1024 }1095 }
...@@ -1057,7 +1128,9 @@ pub const S390x = extern struct {...@@ -1057,7 +1128,9 @@ pub const S390x = extern struct {
1057 65 => return @ptrCast(&ctx.psw.addr),1128 65 => return @ptrCast(&ctx.psw.addr),
10581129
1059 16...31 => return error.UnsupportedRegister, // f0 - f151130 16...31 => return error.UnsupportedRegister, // f0 - f15
1131 32...47 => return error.UnsupportedRegister, // cr0 - cr15
1060 48...63 => return error.UnsupportedRegister, // a0 - a151132 48...63 => return error.UnsupportedRegister, // a0 - a15
1133 66...67 => return error.UnsupportedRegister, // z/OS stuff???
1061 68...83 => return error.UnsupportedRegister, // v16 - v311134 68...83 => return error.UnsupportedRegister, // v16 - v31
10621135
1063 else => return error.InvalidRegister,1136 else => return error.InvalidRegister,