github.com/Rookout/GoSDK@v0.1.48/pkg/services/collection/registers/on_stack_registers_amd64.go (about) 1 //go:build amd64 2 // +build amd64 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 14 15 RDI uintptr 16 RDX uintptr 17 RBX uintptr 18 RAX uintptr 19 RCX uintptr 20 RSI uintptr 21 R8 uintptr 22 R9 uintptr 23 R10 uintptr 24 R11 uintptr 25 R12 uintptr 26 R13 uintptr 27 R14 uintptr 28 R15 uintptr 29 RBP uintptr 30 RIP uintptr 31 TLSVal uintptr 32 RSP uintptr 33 } 34 35 func NewOnStackRegisters(context uintptr) *OnStackRegisters { 36 37 return &OnStackRegisters{ 38 RDI: getRegAtOffset(context, 0x8), 39 RAX: getRegAtOffset(context, 0x10), 40 RBX: getRegAtOffset(context, 0x18), 41 RCX: getRegAtOffset(context, 0x20), 42 RDX: getRegAtOffset(context, 0x28), 43 RSI: getRegAtOffset(context, 0x30), 44 R8: getRegAtOffset(context, 0x38), 45 R9: getRegAtOffset(context, 0x40), 46 R10: getRegAtOffset(context, 0x48), 47 R11: getRegAtOffset(context, 0x50), 48 R14: getRegAtOffset(context, 0x148), 49 R15: getRegAtOffset(context, 0x160), 50 RBP: getRegAtOffset(context, 0x168), 51 RSP: getRegAtOffset(context, 0x170), 52 R12: getRegAtOffset(context, 0x178), 53 R13: getRegAtOffset(context, 0x180), 54 RIP: getRegAtOffset(context, 0x188), 55 } 56 } 57 58 func getRegAtOffset(context uintptr, offset uintptr) uintptr { 59 addr := context + offset 60 return *((*uintptr)(unsafe.Pointer(addr))) 61 } 62 63 func (o OnStackRegisters) PC() uint64 { 64 return uint64(o.RIP) 65 } 66 67 func (o OnStackRegisters) SP() uint64 { 68 return uint64(o.RSP) 69 } 70 71 func (o OnStackRegisters) BP() uint64 { 72 return uint64(o.RBP) 73 } 74 func (o OnStackRegisters) TLS() uint64 { 75 return uint64(o.TLSVal) 76 } 77 78 79 func (o OnStackRegisters) GAddr() (uint64, bool) { 80 return 0, false 81 } 82 func (o OnStackRegisters) Get(int) (uint64, error) { 83 panic("not implemented") 84 } 85 func (o OnStackRegisters) Slice(floatingPoint bool) ([]Register, error) { 86 87 return []Register{ 88 { 89 Name: "Rsp", 90 Reg: op.DwarfRegisterFromUint64(o.SP()), 91 }, 92 { 93 Name: "Rbp", 94 Reg: op.DwarfRegisterFromUint64(o.BP()), 95 }, 96 { 97 Name: "Rip", 98 Reg: op.DwarfRegisterFromUint64(o.PC()), 99 }, 100 101 { 102 Name: "Rax", 103 Reg: op.DwarfRegisterFromUint64(uint64(o.RAX)), 104 }, 105 { 106 Name: "Rdx", 107 Reg: op.DwarfRegisterFromUint64(uint64(o.RDX)), 108 }, 109 { 110 Name: "Rcx", 111 Reg: op.DwarfRegisterFromUint64(uint64(o.RCX)), 112 }, 113 { 114 Name: "Rbx", 115 Reg: op.DwarfRegisterFromUint64(uint64(o.RBX)), 116 }, 117 { 118 Name: "Rsi", 119 Reg: op.DwarfRegisterFromUint64(uint64(o.RSI)), 120 }, 121 { 122 Name: "Rdi", 123 Reg: op.DwarfRegisterFromUint64(uint64(o.RDI)), 124 }, 125 126 { 127 Name: "R8", 128 Reg: op.DwarfRegisterFromUint64(uint64(o.R8)), 129 }, 130 { 131 Name: "R9", 132 Reg: op.DwarfRegisterFromUint64(uint64(o.R9)), 133 }, 134 { 135 Name: "R10", 136 Reg: op.DwarfRegisterFromUint64(uint64(o.R10)), 137 }, 138 { 139 Name: "R11", 140 Reg: op.DwarfRegisterFromUint64(uint64(o.R11)), 141 }, 142 { 143 Name: "R12", 144 Reg: op.DwarfRegisterFromUint64(uint64(o.R12)), 145 }, 146 { 147 Name: "R13", 148 Reg: op.DwarfRegisterFromUint64(uint64(o.R13)), 149 }, 150 { 151 Name: "R14", 152 Reg: op.DwarfRegisterFromUint64(uint64(o.R14)), 153 }, 154 { 155 Name: "R15", 156 Reg: op.DwarfRegisterFromUint64(uint64(o.R15)), 157 }, 158 }, nil 159 } 160 161 162 163 func (o OnStackRegisters) Copy() (Registers, error) { 164 regCopy := o 165 return regCopy, nil 166 }