提交 53957e9f 编写于 作者: A aarzilli 提交者: Derek Parker

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

The fix in 7f53117e for Issue #1416 had a bug, fix it and add a test.

Fixes #1419
上级 dc208bc0
......@@ -5,6 +5,7 @@ import (
"debug/dwarf"
"encoding/binary"
"github.com/derekparker/delve/pkg/dwarf/godwarf"
"github.com/derekparker/delve/pkg/dwarf/util"
)
......@@ -282,3 +283,12 @@ func (b *Builder) AddMember(fieldname string, typ dwarf.Offset, memberLoc []byte
b.TagClose()
return r
}
// AddPointerType adds a new pointer type to debug_info.
func (b *Builder) AddPointerType(typename string, typ dwarf.Offset) dwarf.Offset {
r := b.TagOpen(dwarf.TagPointerType, typename)
b.Attr(dwarf.AttrType, typ)
b.Attr(godwarf.AttrGoKind, uint8(22))
b.TagClose()
return r
}
......@@ -142,10 +142,7 @@ func TestDwarfExprComposite(t *testing.T) {
byteoff := dwb.AddBaseType("uint8", dwarfbuilder.DW_ATE_unsigned, 1)
byteptroff := dwb.TagOpen(dwarf.TagPointerType, "*uint8")
dwb.Attr(godwarf.AttrGoKind, uint8(22))
dwb.Attr(dwarf.AttrType, byteoff)
dwb.TagClose()
byteptroff := dwb.AddPointerType("*uint8", byteoff)
pairoff := dwb.AddStructType("main.pair", 4)
dwb.Attr(godwarf.AttrGoKind, uint8(25))
......@@ -222,3 +219,44 @@ func TestDwarfExprLoclist(t *testing.T) {
scope.PC = 0x40800
uintExprCheck(t, scope, "a", after)
}
func TestIssue1419(t *testing.T) {
// trying to read a slice variable with a location list that tries to read
// from registers we don't have should not cause a panic.
dwb := dwarfbuilder.New()
uint64off := dwb.AddBaseType("uint64", dwarfbuilder.DW_ATE_unsigned, 8)
intoff := dwb.AddBaseType("int", dwarfbuilder.DW_ATE_signed, 8)
intptroff := dwb.AddPointerType("*int", intoff)
sliceoff := dwb.AddStructType("[]int", 24)
dwb.Attr(godwarf.AttrGoKind, uint8(23))
dwb.AddMember("array", intptroff, dwarfbuilder.LocationBlock(op.DW_OP_plus_uconst, uint(0)))
dwb.AddMember("len", uint64off, dwarfbuilder.LocationBlock(op.DW_OP_plus_uconst, uint(8)))
dwb.AddMember("cap", uint64off, dwarfbuilder.LocationBlock(op.DW_OP_plus_uconst, uint(16)))
dwb.TagClose()
dwb.AddSubprogram("main.main", 0x40100, 0x41000)
dwb.AddVariable("a", sliceoff, dwarfbuilder.LocationBlock(op.DW_OP_reg2, op.DW_OP_piece, uint(8), op.DW_OP_reg2, op.DW_OP_piece, uint(8), op.DW_OP_reg2, op.DW_OP_piece, uint(8)))
dwb.TagClose()
bi := fakeBinaryInfo(t, dwb)
mainfn := bi.LookupFunc["main.main"]
mem := newFakeMemory(defaultCFA)
scope := &proc.EvalScope{Location: proc.Location{PC: 0x40100, Fn: mainfn}, Regs: op.DwarfRegisters{}, Mem: mem, Gvar: nil, BinInfo: bi}
va, err := scope.EvalExpression("a", normalLoadConfig)
assertNoError(err, t, "EvalExpression(a)")
t.Logf("%#x\n", va.Addr)
t.Logf("%v", va)
if va.Unreadable == nil {
t.Fatalf("expected 'a' to be unreadable but it wasn't")
}
if va.Unreadable.Error() != "could not read 8 bytes from register 2 (size: 0)" {
t.Fatalf("wrong unreadable reason for variable 'a': %v", va.Unreadable)
}
}
......@@ -908,9 +908,10 @@ func (scope *EvalScope) extractVarInfoFromEntry(varEntry *dwarf.Entry) (*Variabl
mem := scope.Mem
if pieces != nil {
addr = fakeAddress
mem, err = newCompositeMemory(scope.Mem, scope.Regs, pieces)
if mem == nil {
mem = scope.Mem
var cmem *compositeMemory
cmem, err = newCompositeMemory(scope.Mem, scope.Regs, pieces)
if cmem != nil {
mem = cmem
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册