godwarf: handle unsupported types gracefully (#2106)

Backport https://go-review.googlesource.com/c/go/+/158797 from upstream.

Fixes #2101
This commit is contained in:
Alessandro Arzilli
2020-07-15 19:09:28 +02:00
committed by GitHub
parent c63ae072bc
commit 8571fddbc1
2 changed files with 40 additions and 0 deletions

View File

@ -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)
}
}