提交 7f53117e 编写于 作者: A aarzilli 提交者: Derek Parker

proc: do not panic if we can't satisfy a composite location

When a location expression requests a register check that we have as
many bytes in the register as requested and if we don't report the
error.

Updates #1416
上级 11accd4d
......@@ -2,6 +2,7 @@ package proc
import (
"errors"
"fmt"
"github.com/derekparker/delve/pkg/dwarf/op"
)
......@@ -93,7 +94,7 @@ type compositeMemory struct {
data []byte
}
func newCompositeMemory(mem MemoryReadWriter, regs op.DwarfRegisters, pieces []op.Piece) *compositeMemory {
func newCompositeMemory(mem MemoryReadWriter, regs op.DwarfRegisters, pieces []op.Piece) (*compositeMemory, error) {
cmem := &compositeMemory{realmem: mem, regs: regs, pieces: pieces, data: []byte{}}
for _, piece := range pieces {
if piece.IsRegister {
......@@ -102,6 +103,9 @@ func newCompositeMemory(mem MemoryReadWriter, regs op.DwarfRegisters, pieces []o
if sz == 0 && len(pieces) == 1 {
sz = len(reg)
}
if sz > len(reg) {
return nil, fmt.Errorf("could not read %d bytes from register %d (size: %d)", sz, piece.RegNum, len(reg))
}
cmem.data = append(cmem.data, reg[:sz]...)
} else {
buf := make([]byte, piece.Size)
......@@ -109,7 +113,7 @@ func newCompositeMemory(mem MemoryReadWriter, regs op.DwarfRegisters, pieces []o
cmem.data = append(cmem.data, buf...)
}
}
return cmem
return cmem, nil
}
func (mem *compositeMemory) ReadMemory(data []byte, addr uintptr) (int, error) {
......
......@@ -908,7 +908,10 @@ func (scope *EvalScope) extractVarInfoFromEntry(varEntry *dwarf.Entry) (*Variabl
mem := scope.Mem
if pieces != nil {
addr = fakeAddress
mem = newCompositeMemory(scope.Mem, scope.Regs, pieces)
mem, err = newCompositeMemory(scope.Mem, scope.Regs, pieces)
if mem == nil {
mem = scope.Mem
}
}
v := scope.newVariable(n, uintptr(addr), t, mem)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册