2015-06-12 19:49:23 +00:00
|
|
|
package proc
|
2015-04-29 17:07:27 +00:00
|
|
|
|
2017-10-05 07:26:19 +00:00
|
|
|
import (
|
2019-01-04 18:39:25 +00:00
|
|
|
"github.com/go-delve/delve/pkg/dwarf/frame"
|
|
|
|
"github.com/go-delve/delve/pkg/dwarf/op"
|
2017-10-05 07:26:19 +00:00
|
|
|
)
|
|
|
|
|
2020-03-30 18:03:29 +00:00
|
|
|
// Arch represents a CPU architecture.
|
|
|
|
type Arch struct {
|
|
|
|
Name string // architecture name
|
|
|
|
|
2020-11-03 18:28:37 +00:00
|
|
|
ptrSize int
|
|
|
|
maxInstructionLength int
|
|
|
|
prologues []opcodeSeq
|
|
|
|
breakpointInstruction []byte
|
|
|
|
altBreakpointInstruction []byte
|
|
|
|
breakInstrMovesPC bool
|
|
|
|
derefTLS bool
|
|
|
|
usesLR bool // architecture uses a link register, also called RA on some architectures
|
2020-03-30 18:03:29 +00:00
|
|
|
|
|
|
|
// asmDecode decodes the assembly instruction starting at mem[0:] into asmInst.
|
2020-03-28 17:39:32 +00:00
|
|
|
// It assumes that the Loc and AtPC fields of asmInst have already been filled.
|
2020-03-30 18:03:29 +00:00
|
|
|
asmDecode func(asmInst *AsmInstruction, mem []byte, regs Registers, memrw MemoryReadWriter, bi *BinaryInfo) error
|
|
|
|
// fixFrameUnwindContext applies architecture specific rules for unwinding a stack frame
|
2020-03-28 17:39:32 +00:00
|
|
|
// on the given arch.
|
2020-03-30 18:03:29 +00:00
|
|
|
fixFrameUnwindContext func(*frame.FrameContext, uint64, *BinaryInfo) *frame.FrameContext
|
|
|
|
// switchStack will use the current frame to determine if it's time to
|
2020-03-28 17:39:32 +00:00
|
|
|
// switch between the system stack and the goroutine stack or vice versa.
|
2020-03-30 18:03:29 +00:00
|
|
|
switchStack func(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
|
|
|
|
// regSize returns the size (in bytes) of register regnum.
|
|
|
|
regSize func(uint64) int
|
2020-03-28 17:39:32 +00:00
|
|
|
// RegistersToDwarfRegisters maps hardware registers to DWARF registers.
|
2020-03-30 18:03:29 +00:00
|
|
|
RegistersToDwarfRegisters func(uint64, Registers) op.DwarfRegisters
|
|
|
|
// addrAndStackRegsToDwarfRegisters returns DWARF registers from the passed in
|
2020-03-28 17:39:32 +00:00
|
|
|
// PC, SP, and BP registers in the format used by the DWARF expression interpreter.
|
2020-03-30 18:03:29 +00:00
|
|
|
addrAndStackRegsToDwarfRegisters func(uint64, uint64, uint64, uint64, uint64) op.DwarfRegisters
|
2020-03-28 17:39:32 +00:00
|
|
|
// DwarfRegisterToString returns the name and value representation of the given register.
|
2020-03-30 18:03:29 +00:00
|
|
|
DwarfRegisterToString func(int, *op.DwarfRegister) (string, bool, string)
|
|
|
|
// inhibitStepInto returns whether StepBreakpoint can be set at pc.
|
|
|
|
inhibitStepInto func(bi *BinaryInfo, pc uint64) bool
|
|
|
|
|
|
|
|
// crosscall2fn is the DIE of crosscall2, a function used by the go runtime
|
|
|
|
// to call C functions. This function in go 1.9 (and previous versions) had
|
|
|
|
// a bad frame descriptor which needs to be fixed to generate good stack
|
|
|
|
// traces.
|
|
|
|
crosscall2fn *Function
|
|
|
|
|
|
|
|
// sigreturnfn is the DIE of runtime.sigreturn, the return trampoline for
|
|
|
|
// the signal handler. See comment in FixFrameUnwindContext for a
|
|
|
|
// description of why this is needed.
|
|
|
|
sigreturnfn *Function
|
|
|
|
}
|
|
|
|
|
|
|
|
// PtrSize returns the size of a pointer for the architecture.
|
|
|
|
func (a *Arch) PtrSize() int {
|
|
|
|
return a.ptrSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxInstructionLength is the maximum size in bytes of an instruction.
|
|
|
|
func (a *Arch) MaxInstructionLength() int {
|
|
|
|
return a.maxInstructionLength
|
|
|
|
}
|
|
|
|
|
|
|
|
// BreakpointInstruction is the instruction that will trigger a breakpoint trap for
|
|
|
|
// the given architecture.
|
|
|
|
func (a *Arch) BreakpointInstruction() []byte {
|
|
|
|
return a.breakpointInstruction
|
|
|
|
}
|
|
|
|
|
2020-11-03 18:28:37 +00:00
|
|
|
// AltBreakpointInstruction returns an alternate encoding for the breakpoint instruction.
|
|
|
|
func (a *Arch) AltBreakpointInstruction() []byte {
|
|
|
|
return a.altBreakpointInstruction
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:03:29 +00:00
|
|
|
// BreakInstrMovesPC is true if hitting the breakpoint instruction advances the
|
|
|
|
// instruction counter by the size of the breakpoint instruction.
|
|
|
|
func (a *Arch) BreakInstrMovesPC() bool {
|
|
|
|
return a.breakInstrMovesPC
|
|
|
|
}
|
|
|
|
|
|
|
|
// BreakpointSize is the size of the breakpoint instruction for the given architecture.
|
|
|
|
func (a *Arch) BreakpointSize() int {
|
|
|
|
return len(a.breakpointInstruction)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DerefTLS is true if the G struct stored in the TLS section is a pointer
|
|
|
|
// and the address must be dereferenced to find to actual G struct.
|
|
|
|
func (a *Arch) DerefTLS() bool {
|
|
|
|
return a.derefTLS
|
2015-04-29 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 16:34:40 +00:00
|
|
|
// crosscall2 is defined in $GOROOT/src/runtime/cgo/asm_amd64.s.
|
2017-09-01 13:34:13 +00:00
|
|
|
const (
|
|
|
|
crosscall2SPOffsetBad = 0x8
|
|
|
|
crosscall2SPOffsetWindows = 0x118
|
|
|
|
crosscall2SPOffsetNonWindows = 0x58
|
|
|
|
)
|