Skip to content

Commit

Permalink
proc: fix arm64SwitchStack for go1.19 (go-delve#3038)
Browse files Browse the repository at this point in the history
In commit eee6f9f82 Go changed the order that crosscall2 uses to save
its registers, update arm64SwitchStack to use the new order when the
binary was compiled by go 1.19.

Fixes go-delve#2993
  • Loading branch information
aarzilli authored Jun 24, 2022
1 parent 2d09ea6 commit ff3370e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/proc/arm64_arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/go-delve/delve/pkg/dwarf/frame"
"github.com/go-delve/delve/pkg/dwarf/op"
"github.com/go-delve/delve/pkg/dwarf/regnum"
"github.com/go-delve/delve/pkg/goversion"
)

var arm64BreakInstruction = []byte{0x0, 0x0, 0x20, 0xd4}
Expand Down Expand Up @@ -150,13 +151,20 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
return true
case "crosscall2":
//The offsets get from runtime/cgo/asm_arm64.s:10
bpoff := uint64(14)
lroff := uint64(15)
if producer := it.bi.Producer(); producer != "" && goversion.ProducerAfterOrEqual(producer, 1, 19) {
// In Go 1.19 (specifically eee6f9f82) the order registers are saved was changed.
bpoff = 22
lroff = 23
}
newsp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*24), int64(it.bi.Arch.PtrSize()))
newbp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*14), int64(it.bi.Arch.PtrSize()))
newlr, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*15), int64(it.bi.Arch.PtrSize()))
newbp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*bpoff), int64(it.bi.Arch.PtrSize()))
newlr, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*lroff), int64(it.bi.Arch.PtrSize()))
if it.regs.Reg(it.regs.BPRegNum) != nil {
it.regs.Reg(it.regs.BPRegNum).Uint64Val = uint64(newbp)
} else {
reg, _ := it.readRegisterAt(it.regs.BPRegNum, it.regs.SP()+8*14)
reg, _ := it.readRegisterAt(it.regs.BPRegNum, it.regs.SP()+8*bpoff)
it.regs.AddReg(it.regs.BPRegNum, reg)
}
it.regs.Reg(it.regs.LRRegNum).Uint64Val = uint64(newlr)
Expand Down

0 comments on commit ff3370e

Please sign in to comment.