diff --git a/pkg/dwarf/godwarf/type.go b/pkg/dwarf/godwarf/type.go index c8d01ab7..c9605ec2 100644 --- a/pkg/dwarf/godwarf/type.go +++ b/pkg/dwarf/godwarf/type.go @@ -513,6 +513,22 @@ func (t *ChanType) stringIntl(recCheck recCheck) 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. 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) @@ -1008,6 +1024,16 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ typ = t typeCache[off] = t 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 { diff --git a/pkg/proc/dwarf_expr_test.go b/pkg/proc/dwarf_expr_test.go index 73abafd8..359a71a0 100644 --- a/pkg/proc/dwarf_expr_test.go +++ b/pkg/proc/dwarf_expr_test.go @@ -323,3 +323,17 @@ func TestIssue1636_InlineWithoutOrigin(t *testing.T) { dwb.TagClose() 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) + } +}