| ... | ... | @@ -25,21 +25,6 @@ pub fn fpRegNum(reg_ctx: RegisterContext) u8 { |
| 25 | 25 | .x86_64 => 6, |
| 26 | 26 | .arm => 11, |
| 27 | 27 | .aarch64 => 29, |
| 28 | | |
| 29 | | // const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)); |
| 30 | | // const ip = switch (native_os) { |
| 31 | | // .macos => @intCast(usize, ctx.mcontext.ss.pc), |
| 32 | | // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]), |
| 33 | | // .freebsd => @intCast(usize, ctx.mcontext.gpregs.elr), |
| 34 | | // else => @intCast(usize, ctx.mcontext.pc), |
| 35 | | // }; |
| 36 | | // // x29 is the ABI-designated frame pointer |
| 37 | | // const bp = switch (native_os) { |
| 38 | | // .macos => @intCast(usize, ctx.mcontext.ss.fp), |
| 39 | | // .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]), |
| 40 | | // .freebsd => @intCast(usize, ctx.mcontext.gpregs.x[os.REG.FP]), |
| 41 | | // else => @intCast(usize, ctx.mcontext.regs[29]), |
| 42 | | // }; |
| 43 | 28 | else => unreachable, |
| 44 | 29 | }; |
| 45 | 30 | } |
| ... | ... | @@ -231,7 +216,10 @@ pub fn regBytes(ucontext_ptr: anytype, reg_number: u8, reg_ctx: ?RegisterContext |
| 231 | 216 | 0...29 => mem.asBytes(&ucontext_ptr.mcontext.gpregs.x[reg_number]), |
| 232 | 217 | 30 => mem.asBytes(&ucontext_ptr.mcontext.gpregs.lr), |
| 233 | 218 | 31 => mem.asBytes(&ucontext_ptr.mcontext.gpregs.sp), |
| 234 | | 32 => mem.asBytes(&ucontext_ptr.mcontext.gpregs.elr), // TODO: This seems wrong, but it was in the old debug.zig code for PC, check this |
| 219 | |
| 220 | // TODO: This seems wrong, but it was in the previous debug.zig code for mapping PC, check this |
| 221 | 32 => mem.asBytes(&ucontext_ptr.mcontext.gpregs.elr), |
| 222 | |
| 235 | 223 | else => error.InvalidRegister, |
| 236 | 224 | }, |
| 237 | 225 | else => switch (reg_number) { |
| ... | ... | @@ -252,76 +240,3 @@ pub fn getRegDefaultValue(reg_number: u8, out: []u8) void { |
| 252 | 240 | _ = reg_number; |
| 253 | 241 | @memset(out, undefined); |
| 254 | 242 | } |
| 255 | | |
| 256 | | fn writeUnknownReg(writer: anytype, reg_number: u8) !void { |
| 257 | | try writer.print("reg{}", .{reg_number}); |
| 258 | | } |
| 259 | | |
| 260 | | pub fn writeRegisterName(writer: anytype, arch: ?std.Target.Cpu.Arch, reg_number: u8) !void { |
| 261 | | if (arch) |a| { |
| 262 | | switch (a) { |
| 263 | | .x86_64 => { |
| 264 | | switch (reg_number) { |
| 265 | | 0 => try writer.writeAll("RAX"), |
| 266 | | 1 => try writer.writeAll("RDX"), |
| 267 | | 2 => try writer.writeAll("RCX"), |
| 268 | | 3 => try writer.writeAll("RBX"), |
| 269 | | 4 => try writer.writeAll("RSI"), |
| 270 | | 5 => try writer.writeAll("RDI"), |
| 271 | | 6 => try writer.writeAll("RBP"), |
| 272 | | 7 => try writer.writeAll("RSP"), |
| 273 | | 8...15 => try writer.print("R{}", .{reg_number}), |
| 274 | | 16 => try writer.writeAll("RIP"), |
| 275 | | 17...32 => try writer.print("XMM{}", .{reg_number - 17}), |
| 276 | | 33...40 => try writer.print("ST{}", .{reg_number - 33}), |
| 277 | | 41...48 => try writer.print("MM{}", .{reg_number - 41}), |
| 278 | | 49 => try writer.writeAll("RFLAGS"), |
| 279 | | 50 => try writer.writeAll("ES"), |
| 280 | | 51 => try writer.writeAll("CS"), |
| 281 | | 52 => try writer.writeAll("SS"), |
| 282 | | 53 => try writer.writeAll("DS"), |
| 283 | | 54 => try writer.writeAll("FS"), |
| 284 | | 55 => try writer.writeAll("GS"), |
| 285 | | // 56-57 Reserved |
| 286 | | 58 => try writer.writeAll("FS.BASE"), |
| 287 | | 59 => try writer.writeAll("GS.BASE"), |
| 288 | | // 60-61 Reserved |
| 289 | | 62 => try writer.writeAll("TR"), |
| 290 | | 63 => try writer.writeAll("LDTR"), |
| 291 | | 64 => try writer.writeAll("MXCSR"), |
| 292 | | 65 => try writer.writeAll("FCW"), |
| 293 | | 66 => try writer.writeAll("FSW"), |
| 294 | | 67...82 => try writer.print("XMM{}", .{reg_number - 51}), |
| 295 | | // 83-117 Reserved |
| 296 | | 118...125 => try writer.print("K{}", .{reg_number - 118}), |
| 297 | | // 126-129 Reserved |
| 298 | | else => try writeUnknownReg(writer, reg_number), |
| 299 | | } |
| 300 | | }, |
| 301 | | |
| 302 | | // TODO: Add x86, aarch64 |
| 303 | | |
| 304 | | else => try writeUnknownReg(writer, reg_number), |
| 305 | | } |
| 306 | | } else try writeUnknownReg(writer, reg_number); |
| 307 | | } |
| 308 | | |
| 309 | | const FormatRegisterData = struct { |
| 310 | | reg_number: u8, |
| 311 | | arch: ?std.Target.Cpu.Arch, |
| 312 | | }; |
| 313 | | |
| 314 | | pub fn formatRegister( |
| 315 | | data: FormatRegisterData, |
| 316 | | comptime fmt: []const u8, |
| 317 | | options: std.fmt.FormatOptions, |
| 318 | | writer: anytype, |
| 319 | | ) !void { |
| 320 | | _ = fmt; |
| 321 | | _ = options; |
| 322 | | try writeRegisterName(writer, data.arch, data.reg_number); |
| 323 | | } |
| 324 | | |
| 325 | | pub fn fmtRegister(reg_number: u8, arch: ?std.Target.Cpu.Arch) std.fmt.Formatter(formatRegister) { |
| 326 | | return .{ .data = .{ .reg_number = reg_number, .arch = arch } }; |
| 327 | | } |