github.com/Rookout/GoSDK@v0.1.48/pkg/services/collection/registers/on_stack_registers_arm64.go (about) 1 //go:build arm64 2 // +build arm64 3 4 package registers 5 6 import ( 7 "unsafe" 8 9 "github.com/Rookout/GoSDK/pkg/services/instrumentation/dwarf/op" 10 ) 11 12 type OnStackRegisters struct { 13 x0 uintptr 14 x1 uintptr 15 x2 uintptr 16 x3 uintptr 17 x4 uintptr 18 x5 uintptr 19 x6 uintptr 20 x7 uintptr 21 x8 uintptr 22 x9 uintptr 23 x10 uintptr 24 x11 uintptr 25 x12 uintptr 26 x13 uintptr 27 x14 uintptr 28 x15 uintptr 29 x16 uintptr 30 x17 uintptr 31 x18 uintptr 32 x19 uintptr 33 x20 uintptr 34 x21 uintptr 35 x22 uintptr 36 x23 uintptr 37 x24 uintptr 38 x25 uintptr 39 x26 uintptr 40 x27 uintptr 41 x28 uintptr 42 x29 uintptr 43 x30 uintptr 44 pc uintptr 45 sp uintptr 46 } 47 48 func NewOnStackRegisters(context uintptr) *OnStackRegisters { 49 50 return &OnStackRegisters{ 51 x0: getRegAtOffset(context, 0x8), 52 x1: getRegAtOffset(context, 0x10), 53 x2: getRegAtOffset(context, 0x18), 54 x3: getRegAtOffset(context, 0x20), 55 x4: getRegAtOffset(context, 0x28), 56 x5: getRegAtOffset(context, 0x30), 57 x6: getRegAtOffset(context, 0x38), 58 x7: getRegAtOffset(context, 0x40), 59 x8: getRegAtOffset(context, 0x48), 60 x9: getRegAtOffset(context, 0x50), 61 x10: getRegAtOffset(context, 0x58), 62 x11: getRegAtOffset(context, 0x60), 63 x12: getRegAtOffset(context, 0x68), 64 x13: getRegAtOffset(context, 0x70), 65 x14: getRegAtOffset(context, 0x78), 66 x15: getRegAtOffset(context, 0x80), 67 68 x16: getRegAtOffset(context, 0x1a0), 69 x17: getRegAtOffset(context, 0x1a8), 70 x18: getRegAtOffset(context, 0x1b0), 71 x21: getRegAtOffset(context, 0x1b8), 72 x22: getRegAtOffset(context, 0x1c0), 73 x23: getRegAtOffset(context, 0x1c8), 74 x24: getRegAtOffset(context, 0x1d0), 75 x25: getRegAtOffset(context, 0x1d8), 76 x26: getRegAtOffset(context, 0x1e0), 77 x27: getRegAtOffset(context, 0x1e8), 78 x28: getRegAtOffset(context, 0x1f0), 79 80 x19: getRegAtOffset(context, 0x1f0+0x120), 81 x20: getRegAtOffset(context, 0x1f0+0x128), 82 x29: getRegAtOffset(context, 0x1f0+0x130), 83 x30: getRegAtOffset(context, 0x1f0+0x138), 84 sp: getRegAtOffset(context, 0x1f0+0x140), 85 pc: getRegAtOffset(context, 0x1f0+0x148), 86 } 87 } 88 89 func getRegAtOffset(context uintptr, offset uintptr) uintptr { 90 addr := context + offset 91 return *((*uintptr)(unsafe.Pointer(addr))) 92 } 93 94 func (o OnStackRegisters) PC() uint64 { 95 return uint64(o.pc) 96 } 97 98 func (o OnStackRegisters) SP() uint64 { 99 return uint64(o.sp) 100 } 101 102 func (o OnStackRegisters) BP() uint64 { 103 return uint64(o.x29) 104 } 105 func (o OnStackRegisters) TLS() uint64 { 106 return 0 107 } 108 109 110 func (o OnStackRegisters) GAddr() (uint64, bool) { 111 return uint64(o.x28), true 112 } 113 func (o OnStackRegisters) Get(int) (uint64, error) { 114 panic("not implemented") 115 } 116 func (o OnStackRegisters) Slice(floatingPoint bool) ([]Register, error) { 117 118 return []Register{ 119 { 120 Name: "x0", 121 Reg: op.DwarfRegisterFromUint64(uint64(o.x0)), 122 }, 123 { 124 Name: "x1", 125 Reg: op.DwarfRegisterFromUint64(uint64(o.x1)), 126 }, 127 { 128 Name: "x2", 129 Reg: op.DwarfRegisterFromUint64(uint64(o.x2)), 130 }, 131 { 132 Name: "x3", 133 Reg: op.DwarfRegisterFromUint64(uint64(o.x3)), 134 }, 135 { 136 Name: "x4", 137 Reg: op.DwarfRegisterFromUint64(uint64(o.x4)), 138 }, 139 { 140 Name: "x5", 141 Reg: op.DwarfRegisterFromUint64(uint64(o.x5)), 142 }, 143 { 144 Name: "x6", 145 Reg: op.DwarfRegisterFromUint64(uint64(o.x6)), 146 }, 147 { 148 Name: "x7", 149 Reg: op.DwarfRegisterFromUint64(uint64(o.x7)), 150 }, 151 { 152 Name: "x8", 153 Reg: op.DwarfRegisterFromUint64(uint64(o.x8)), 154 }, 155 { 156 Name: "x9", 157 Reg: op.DwarfRegisterFromUint64(uint64(o.x9)), 158 }, 159 { 160 Name: "x10", 161 Reg: op.DwarfRegisterFromUint64(uint64(o.x10)), 162 }, 163 { 164 Name: "x11", 165 Reg: op.DwarfRegisterFromUint64(uint64(o.x11)), 166 }, 167 { 168 Name: "x12", 169 Reg: op.DwarfRegisterFromUint64(uint64(o.x12)), 170 }, 171 { 172 Name: "x13", 173 Reg: op.DwarfRegisterFromUint64(uint64(o.x13)), 174 }, 175 { 176 Name: "x14", 177 Reg: op.DwarfRegisterFromUint64(uint64(o.x14)), 178 }, 179 { 180 Name: "x15", 181 Reg: op.DwarfRegisterFromUint64(uint64(o.x15)), 182 }, 183 { 184 Name: "x16", 185 Reg: op.DwarfRegisterFromUint64(uint64(o.x16)), 186 }, 187 { 188 Name: "x17", 189 Reg: op.DwarfRegisterFromUint64(uint64(o.x17)), 190 }, 191 { 192 Name: "x18", 193 Reg: op.DwarfRegisterFromUint64(uint64(o.x18)), 194 }, 195 { 196 Name: "x19", 197 Reg: op.DwarfRegisterFromUint64(uint64(o.x19)), 198 }, 199 { 200 Name: "x20", 201 Reg: op.DwarfRegisterFromUint64(uint64(o.x20)), 202 }, 203 { 204 Name: "x21", 205 Reg: op.DwarfRegisterFromUint64(uint64(o.x21)), 206 }, 207 { 208 Name: "x22", 209 Reg: op.DwarfRegisterFromUint64(uint64(o.x22)), 210 }, 211 { 212 Name: "x23", 213 Reg: op.DwarfRegisterFromUint64(uint64(o.x23)), 214 }, 215 { 216 Name: "x24", 217 Reg: op.DwarfRegisterFromUint64(uint64(o.x24)), 218 }, 219 { 220 Name: "x25", 221 Reg: op.DwarfRegisterFromUint64(uint64(o.x25)), 222 }, 223 { 224 Name: "x26", 225 Reg: op.DwarfRegisterFromUint64(uint64(o.x26)), 226 }, 227 { 228 Name: "x27", 229 Reg: op.DwarfRegisterFromUint64(uint64(o.x27)), 230 }, 231 { 232 Name: "x28", 233 Reg: op.DwarfRegisterFromUint64(uint64(o.x28)), 234 }, 235 { 236 Name: "x29", 237 Reg: op.DwarfRegisterFromUint64(uint64(o.x29)), 238 }, 239 { 240 Name: "x30", 241 Reg: op.DwarfRegisterFromUint64(uint64(o.x30)), 242 }, 243 { 244 Name: "pc", 245 Reg: op.DwarfRegisterFromUint64(o.PC()), 246 }, 247 { 248 Name: "sp", 249 Reg: op.DwarfRegisterFromUint64(o.SP()), 250 }, 251 { 252 Name: "lr", 253 Reg: op.DwarfRegisterFromUint64(uint64(o.x30)), 254 }, 255 }, nil 256 } 257 258 259 260 func (o OnStackRegisters) Copy() (Registers, error) { 261 regCopy := o 262 return regCopy, nil 263 }