pkg/proc: merge register data before writing to register (#2699)

Right now, if (*compositeMemory).WriteMemory needs to write a value to
a register that's smaller than the full size of the register (say, a
uint32 being passed as an argument), then (*AMD64Registers).SetReg can
later fail a sanity check that ensures the passed DwarfRegister is a
full size register.

Fix this by reading the old value of the register and overwriting just
the relevant parts with the new register. For the purposes of an
argument, it would probably be fine to just pad with zeroes, but merging
with the existing value is what gdb does.

Fixes #2698
This commit is contained in:
Michael Knyszek
2021-09-24 18:27:44 -04:00
committed by GitHub
parent 4b30ba4228
commit 041eedd126
5 changed files with 40 additions and 3 deletions

View File

@ -245,7 +245,7 @@ func TestDwarfExprComposite(t *testing.T) {
if changeCalls[0] != "3 - 2f00000000000000" {
t.Errorf("wrong call to SetReg (Rbx)")
}
if changeCalls[1] != "2 - 0c00" {
if changeCalls[1] != "2 - 0c00000000000000" {
t.Errorf("wrong call to SetReg (Rcx)")
}
if mem.data[0x10] != 13 || mem.data[0x11] != 0x00 {