From ff3370e67647fe1109481ef4c005b1f8a20c25ee Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 24 Jun 2022 15:49:43 +0200 Subject: [PATCH] proc: fix arm64SwitchStack for go1.19 (#3038) 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 #2993 --- pkg/proc/arm64_arch.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/proc/arm64_arch.go b/pkg/proc/arm64_arch.go index e6e47f0d..e56a0d6e 100644 --- a/pkg/proc/arm64_arch.go +++ b/pkg/proc/arm64_arch.go @@ -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} @@ -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)