proc: remove duplicate Registers.Get implementations (#2415)

Moves the implementation of Registers.Get out of the backends and into
proc where it can be implemented only once per architecture.
This commit is contained in:
Alessandro Arzilli
2021-04-28 19:00:26 +02:00
committed by GitHub
parent 7bf5482b32
commit 35d4f05c4e
26 changed files with 242 additions and 1206 deletions

View File

@ -102,8 +102,8 @@ func uintExprCheck(t *testing.T, scope *proc.EvalScope, expr string, tgt uint64)
}
}
func fakeScope(mem proc.MemoryReadWriter, regs op.DwarfRegisters, bi *proc.BinaryInfo, fn *proc.Function) *proc.EvalScope {
return &proc.EvalScope{Location: proc.Location{PC: 0x40100, Fn: fn}, Regs: regs, Mem: mem, BinInfo: bi}
func fakeScope(mem proc.MemoryReadWriter, regs *op.DwarfRegisters, bi *proc.BinaryInfo, fn *proc.Function) *proc.EvalScope {
return &proc.EvalScope{Location: proc.Location{PC: 0x40100, Fn: fn}, Regs: *regs, Mem: mem, BinInfo: bi}
}
func dwarfExprCheck(t *testing.T, scope *proc.EvalScope, testCases map[string]uint16) {
@ -112,7 +112,7 @@ func dwarfExprCheck(t *testing.T, scope *proc.EvalScope, testCases map[string]ui
}
}
func dwarfRegisters(bi *proc.BinaryInfo, regs *linutil.AMD64Registers) op.DwarfRegisters {
func dwarfRegisters(bi *proc.BinaryInfo, regs *linutil.AMD64Registers) *op.DwarfRegisters {
a := proc.AMD64Arch("linux")
so := bi.PCToImage(regs.PC())
dwarfRegs := a.RegistersToDwarfRegisters(so.StaticBase, regs)
@ -271,7 +271,7 @@ func TestDwarfExprLoclist(t *testing.T) {
const PC = 0x40100
regs := linutil.AMD64Registers{Regs: &linutil.AMD64PtraceRegs{Rip: PC}}
scope := &proc.EvalScope{Location: proc.Location{PC: PC, Fn: mainfn}, Regs: dwarfRegisters(bi, &regs), Mem: mem, BinInfo: bi}
scope := &proc.EvalScope{Location: proc.Location{PC: PC, Fn: mainfn}, Regs: *dwarfRegisters(bi, &regs), Mem: mem, BinInfo: bi}
uintExprCheck(t, scope, "a", before)
scope.PC = 0x40800