*: add support for linux/loong64 to native backend (#3892)

* delve: support linux-loong64 native debug

LoongArch is a new RISC ISA, which is independently designed by Loongson Technology.

LoongArch includes a reduced 32-bit version (LA32R), a standard 32-bit version (LA32S)
and a 64-bit version (LA64), and loong64 is the 64-bit version of LoongArch.

LoongArch documentation: https://github.com/loongson/LoongArch-Documentation.git

* *: mark loong64 port as experimental

---------

Co-authored-by: Huang Qiqi <huangqiqi@loongson.cn>
This commit is contained in:
yelvens
2025-01-18 01:41:37 +08:00
committed by GitHub
parent 38af36e942
commit d2f748f1bd
36 changed files with 3803 additions and 25 deletions

View File

@ -41,6 +41,7 @@ const (
_EM_AARCH64 = 183
_EM_X86_64 = 62
_EM_RISCV = 243
_EM_LOONGARCH = 258
_ARM_FP_HEADER_START = 512
)
@ -63,6 +64,9 @@ func linuxThreadsFromNotes(p *process, notes []*note, machineType elf.Machine) p
case _EM_RISCV:
t := note.Desc.(*linuxPrStatusRISCV64)
lastThread = &linuxRISCV64Thread{linutil.RISCV64Registers{Regs: &t.Reg}, t}
case _EM_LOONGARCH:
t := note.Desc.(*linuxPrStatusLOONG64)
lastThread = &linuxLOONG64Thread{linutil.LOONG64Registers{Regs: &t.Reg}, t}
default:
continue
}
@ -76,6 +80,8 @@ func linuxThreadsFromNotes(p *process, notes []*note, machineType elf.Machine) p
th.regs.Fpregs = note.Desc.(*linutil.ARM64PtraceFpRegs).Decode()
case *linuxRISCV64Thread:
th.regs.Fpregs = note.Desc.(*linutil.RISCV64PtraceFpRegs).Decode()
case *linuxLOONG64Thread:
th.regs.Fpregs = note.Desc.(*linutil.LOONG64PtraceFpRegs).Decode()
}
case _NT_X86_XSTATE:
if lastThread != nil {
@ -89,9 +95,10 @@ func linuxThreadsFromNotes(p *process, notes []*note, machineType elf.Machine) p
}
var supportedLinuxMachines = map[elf.Machine]string{
_EM_X86_64: "amd64",
_EM_AARCH64: "arm64",
_EM_RISCV: "riscv64",
_EM_X86_64: "amd64",
_EM_AARCH64: "arm64",
_EM_RISCV: "riscv64",
_EM_LOONGARCH: "loong64",
}
// readLinuxOrPlatformIndependentCore reads a core file from corePath
@ -189,6 +196,11 @@ type linuxRISCV64Thread struct {
t *linuxPrStatusRISCV64
}
type linuxLOONG64Thread struct {
regs linutil.LOONG64Registers
t *linuxPrStatusLOONG64
}
func (t *linuxAMD64Thread) Registers() (proc.Registers, error) {
var r linutil.AMD64Registers
r.Regs = t.regs.Regs
@ -210,6 +222,13 @@ func (t *linuxRISCV64Thread) Registers() (proc.Registers, error) {
return &r, nil
}
func (t *linuxLOONG64Thread) Registers() (proc.Registers, error) {
var r linutil.LOONG64Registers
r.Regs = t.regs.Regs
r.Fpregs = t.regs.Fpregs
return &r, nil
}
func (t *linuxAMD64Thread) ThreadID() int {
return int(t.t.Pid)
}
@ -222,6 +241,10 @@ func (t *linuxRISCV64Thread) ThreadID() int {
return int(t.t.Pid)
}
func (t *linuxLOONG64Thread) ThreadID() int {
return int(t.t.Pid)
}
// Note is a note from the PT_NOTE prog.
// Relevant types:
// - NT_FILE: File mapping information, e.g. program text mappings. Desc is a LinuxNTFile.
@ -307,6 +330,8 @@ func readNote(r io.ReadSeeker, machineType elf.Machine) (*note, error) {
note.Desc = &linuxPrStatusARM64{}
case _EM_RISCV:
note.Desc = &linuxPrStatusRISCV64{}
case _EM_LOONGARCH:
note.Desc = &linuxPrStatusLOONG64{}
default:
return nil, errors.New("unsupported machine type")
}
@ -350,6 +375,8 @@ func readNote(r io.ReadSeeker, machineType elf.Machine) (*note, error) {
err = readFpregsetNote(note, &linutil.ARM64PtraceFpRegs{}, desc[:_ARM_FP_HEADER_START])
} else if machineType == _EM_RISCV {
err = readFpregsetNote(note, &linutil.RISCV64PtraceFpRegs{}, desc)
} else if machineType == _EM_LOONGARCH {
err = readFpregsetNote(note, &linutil.LOONG64PtraceFpRegs{}, desc)
}
if err != nil {
return nil, err
@ -489,6 +516,19 @@ type linuxPrStatusRISCV64 struct {
Fpvalid int32
}
// LinuxPrStatusLOONG64 is a copy of the prstatus kernel struct.
type linuxPrStatusLOONG64 struct {
Siginfo linuxSiginfo
Cursig uint16
_ [2]uint8
Sigpend uint64
Sighold uint64
Pid, Ppid, Pgrp, Sid int32
Utime, Stime, CUtime, CStime linuxCoreTimeval
Reg linutil.LOONG64PtraceRegs
Fpvalid int32
}
// LinuxSiginfo is a copy of the
// siginfo kernel struct.
type linuxSiginfo struct {