2015-06-12 19:49:23 +00:00
|
|
|
package proc
|
2015-04-29 17:07:27 +00:00
|
|
|
|
2015-06-11 20:17:56 +00:00
|
|
|
import "runtime"
|
|
|
|
|
2015-04-29 17:07:27 +00:00
|
|
|
type Arch interface {
|
2015-07-23 17:08:28 +00:00
|
|
|
SetCurGInstructions(ver GoVersion, iscgo bool)
|
2015-04-29 17:07:27 +00:00
|
|
|
PtrSize() int
|
|
|
|
BreakpointInstruction() []byte
|
|
|
|
BreakpointSize() int
|
2015-06-11 20:17:56 +00:00
|
|
|
CurgInstructions() []byte
|
2015-06-17 18:09:55 +00:00
|
|
|
HardwareBreakpointUsage() []bool
|
|
|
|
SetHardwareBreakpointUsage(int, bool)
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AMD64 struct {
|
2015-06-17 18:09:55 +00:00
|
|
|
ptrSize int
|
|
|
|
breakInstruction []byte
|
|
|
|
breakInstructionLen int
|
|
|
|
curgInstructions []byte
|
|
|
|
hardwareBreakpointUsage []bool
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func AMD64Arch() *AMD64 {
|
2015-07-23 17:08:28 +00:00
|
|
|
var breakInstr = []byte{0xCC}
|
|
|
|
|
|
|
|
return &AMD64{
|
|
|
|
ptrSize: 8,
|
|
|
|
breakInstruction: breakInstr,
|
|
|
|
breakInstructionLen: len(breakInstr),
|
|
|
|
hardwareBreakpointUsage: make([]bool, 4),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AMD64) SetCurGInstructions(ver GoVersion, isextld bool) {
|
|
|
|
var curg []byte
|
2015-06-11 20:17:56 +00:00
|
|
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "darwin":
|
|
|
|
curg = []byte{
|
|
|
|
0x65, 0x48, 0x8b, 0x0C, 0x25, 0xA0, 0x08, // mov %gs:0x8a0,%rcx
|
|
|
|
0x0, 0x0,
|
|
|
|
}
|
|
|
|
case "linux":
|
2015-07-23 17:08:28 +00:00
|
|
|
if isextld || ver.After(GoVersion{1, 5, 0}) {
|
|
|
|
curg = []byte{
|
|
|
|
0x64, 0x48, 0x8b, 0x0c, 0x25, 0xf8, 0xff, 0xff, 0xff, // mov %fs:0xfffffffffffffff8,%rcx
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
curg = []byte{
|
|
|
|
0x64, 0x48, 0x8b, 0x0c, 0x25, 0xf0, 0xff, 0xff, 0xff, // mov %fs:0xfffffffffffffff0,%rcx
|
|
|
|
}
|
2015-06-11 20:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-23 17:08:28 +00:00
|
|
|
curg = append(curg, a.breakInstruction...)
|
2015-06-11 20:17:56 +00:00
|
|
|
|
2015-07-23 17:08:28 +00:00
|
|
|
a.curgInstructions = curg
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AMD64) PtrSize() int {
|
|
|
|
return a.ptrSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AMD64) BreakpointInstruction() []byte {
|
|
|
|
return a.breakInstruction
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AMD64) BreakpointSize() int {
|
|
|
|
return a.breakInstructionLen
|
|
|
|
}
|
2015-06-11 20:17:56 +00:00
|
|
|
|
|
|
|
func (a *AMD64) CurgInstructions() []byte {
|
|
|
|
return a.curgInstructions
|
|
|
|
}
|
2015-06-12 19:30:59 +00:00
|
|
|
|
2015-06-17 18:09:55 +00:00
|
|
|
func (a *AMD64) HardwareBreakpointUsage() []bool {
|
|
|
|
return a.hardwareBreakpointUsage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AMD64) SetHardwareBreakpointUsage(reg int, set bool) {
|
|
|
|
a.hardwareBreakpointUsage[reg] = set
|
2015-06-12 19:30:59 +00:00
|
|
|
}
|