mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 09:46:56 +08:00
godwarf: handle unsupported types gracefully (#2106)
Backport https://go-review.googlesource.com/c/go/+/158797 from upstream. Fixes #2101
This commit is contained in:
committed by
GitHub
parent
c63ae072bc
commit
8571fddbc1
@ -513,6 +513,22 @@ func (t *ChanType) stringIntl(recCheck recCheck) string {
|
|||||||
return "chan " + t.ElemType.String()
|
return "chan " + t.ElemType.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An UnsupportedType is a placeholder returned in situations where we
|
||||||
|
// encounter a type that isn't supported.
|
||||||
|
type UnsupportedType struct {
|
||||||
|
CommonType
|
||||||
|
Tag dwarf.Tag
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *UnsupportedType) stringIntl(recCheck) string {
|
||||||
|
if t.Name != "" {
|
||||||
|
return t.Name
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("(unsupported type %s)", t.Tag.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *UnsupportedType) String() string { return t.stringIntl(nil) }
|
||||||
|
|
||||||
// Type reads the type at off in the DWARF ``info'' section.
|
// Type reads the type at off in the DWARF ``info'' section.
|
||||||
func ReadType(d *dwarf.Data, index int, off dwarf.Offset, typeCache map[dwarf.Offset]Type) (Type, error) {
|
func ReadType(d *dwarf.Data, index int, off dwarf.Offset, typeCache map[dwarf.Offset]Type) (Type, error) {
|
||||||
typ, err := readType(d, "info", d.Reader(), off, typeCache, nil)
|
typ, err := readType(d, "info", d.Reader(), off, typeCache, nil)
|
||||||
@ -1008,6 +1024,16 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ
|
|||||||
typ = t
|
typ = t
|
||||||
typeCache[off] = t
|
typeCache[off] = t
|
||||||
t.Name, _ = e.Val(dwarf.AttrName).(string)
|
t.Name, _ = e.Val(dwarf.AttrName).(string)
|
||||||
|
|
||||||
|
default:
|
||||||
|
// This is some other type DIE that we're currently not
|
||||||
|
// equipped to handle. Return an abstract "unsupported type"
|
||||||
|
// object in such cases.
|
||||||
|
t := new(UnsupportedType)
|
||||||
|
typ = t
|
||||||
|
typeCache[off] = t
|
||||||
|
t.Tag = e.Tag
|
||||||
|
t.Name, _ = e.Val(dwarf.AttrName).(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -323,3 +323,17 @@ func TestIssue1636_InlineWithoutOrigin(t *testing.T) {
|
|||||||
dwb.TagClose()
|
dwb.TagClose()
|
||||||
fakeBinaryInfo(t, dwb)
|
fakeBinaryInfo(t, dwb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnsupportedType(t *testing.T) {
|
||||||
|
// Tests that reading an unsupported type does not cause an error
|
||||||
|
dwb := dwarfbuilder.New()
|
||||||
|
dwb.AddCompileUnit("main", 0x0)
|
||||||
|
off := dwb.TagOpen(dwarf.TagReferenceType, "blah")
|
||||||
|
dwb.TagClose()
|
||||||
|
dwb.TagClose()
|
||||||
|
_, dw := fakeBinaryInfo(t, dwb)
|
||||||
|
_, err := godwarf.ReadType(dw, 0, off, make(map[dwarf.Offset]godwarf.Type))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error reading unsupported type: %#v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user