From: Austin Clements Date: Mon, 6 Apr 2015 22:01:45 +0000 (-0400) Subject: debug/dwarf: add Entry.AttrField method to get *Field by Attr X-Git-Tag: go1.5beta1~1165 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=947b6a7ec8e05edbc4fe6fc6b4002fa03efc7329;p=gostls13.git debug/dwarf: add Entry.AttrField method to get *Field by Attr Currently, Entry has a Val method that looks up an attribute and returns its value. Now that Field has more fields than the attribute and its value, it's useful to return the whole Field and let the caller retrieve the parts it needs. This change adds an AttrField method to Entry that does the same lookup at Val, but returns the whole *Field rather than just the value. Change-Id: Ic629744c14c0e09d7528fa1026b0e1857789948c Reviewed-on: https://go-review.googlesource.com/8503 Reviewed-by: Ian Lance Taylor --- diff --git a/src/debug/dwarf/entry.go b/src/debug/dwarf/entry.go index 760ddec5a4..1915d78dc9 100644 --- a/src/debug/dwarf/entry.go +++ b/src/debug/dwarf/entry.go @@ -335,9 +335,18 @@ func (i Class) GoString() string { // v, ok := e.Val(AttrSibling).(int64) // func (e *Entry) Val(a Attr) interface{} { - for _, f := range e.Field { + if f := e.AttrField(a); f != nil { + return f.Val + } + return nil +} + +// AttrField returns the Field associated with attribute Attr in +// Entry, or nil if there is no such attribute. +func (e *Entry) AttrField(a Attr) *Field { + for i, f := range e.Field { if f.Attr == a { - return f.Val + return &e.Field[i] } } return nil