From 9da7abd2ebd07d32484277adac75c45b66f504c1 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 14 Aug 2019 15:04:05 -0400 Subject: [PATCH] debug/dwarf: better handling for DW_FORM_indirect Fix a buglet in abbrev processing related to DW_FORM_indirect. When reading an abbrev entry if we encounter an attribute with form DW_FORM_indirect, leave the class as ClassUnknown, then when the abbrev is walked during the reading of the DIE fill in the class based on the value read at that point (code for handling DW_FORM_indirect seems to be already partially in place in the DIE reader). Updates #33488. Change-Id: I9dc89abf5cc8d7ea96824c0011bef979de0540bf Reviewed-on: https://go-review.googlesource.com/c/go/+/190158 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/debug/dwarf/entry.go | 10 +++++++--- src/debug/dwarf/typeunit.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/debug/dwarf/entry.go b/src/debug/dwarf/entry.go index dfc2f44abc..43043f60dd 100644 --- a/src/debug/dwarf/entry.go +++ b/src/debug/dwarf/entry.go @@ -160,6 +160,9 @@ func formToClass(form format, attr Attr, vers int, b *buf) Class { b.error("cannot determine class of unknown attribute form") return 0 + case formIndirect: + return ClassUnknown + case formAddr, formAddrx, formAddrx1, formAddrx2, formAddrx3, formAddrx4: return ClassAddress @@ -402,7 +405,7 @@ type Offset uint32 // Entry reads a single entry from buf, decoding // according to the given abbreviation table. -func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset) *Entry { +func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset, vers int) *Entry { off := b.off id := uint32(b.uint()) if id == 0 { @@ -425,6 +428,7 @@ func (b *buf) entry(cu *Entry, atab abbrevTable, ubase Offset) *Entry { fmt := a.field[i].fmt if fmt == formIndirect { fmt = format(b.uint()) + e.Field[i].Class = formToClass(fmt, a.field[i].attr, vers, b) } var val interface{} switch fmt { @@ -784,7 +788,7 @@ func (r *Reader) Next() (*Entry, error) { return nil, nil } u := &r.d.unit[r.unit] - e := r.b.entry(r.cu, u.atable, u.base) + e := r.b.entry(r.cu, u.atable, u.base, u.vers) if r.b.err != nil { r.err = r.b.err return nil, r.err @@ -929,7 +933,7 @@ func (d *Data) Ranges(e *Entry) ([][2]uint64, error) { } u := &d.unit[i] b := makeBuf(d, u, "info", u.off, u.data) - cu = b.entry(nil, u.atable, u.base) + cu = b.entry(nil, u.atable, u.base, u.vers) if b.err != nil { return nil, b.err } diff --git a/src/debug/dwarf/typeunit.go b/src/debug/dwarf/typeunit.go index a03dc84c83..27aa0784f0 100644 --- a/src/debug/dwarf/typeunit.go +++ b/src/debug/dwarf/typeunit.go @@ -137,7 +137,7 @@ func (tur *typeUnitReader) Next() (*Entry, error) { if len(tur.tu.data) == 0 { return nil, nil } - e := tur.b.entry(nil, tur.tu.atable, tur.tu.base) + e := tur.b.entry(nil, tur.tu.atable, tur.tu.base, tur.tu.vers) if tur.b.err != nil { tur.err = tur.b.err return nil, tur.err -- 2.50.0