]> Cypherpunks repositories - gostls13.git/commitdiff
debug/dwarf: compute ByteSize for more DWARF types
authorJohn Dethridge <jcd@golang.org>
Sat, 2 May 2015 06:40:21 +0000 (16:40 +1000)
committerJohn Dethridge <jcd@golang.org>
Thu, 7 May 2015 07:28:39 +0000 (07:28 +0000)
When AttrByteSize is not present for a type, we can still determine the
size in two more cases: when the type is a Typedef referring to another
type, and when the type is a pointer and we know the default address
size.

entry.go: return after setting an error if the offset is out of range.

Change-Id: I63a922ca4e4ad2fc9e9be3e5b47f59fae7d0eb5c
Reviewed-on: https://go-review.googlesource.com/9663
Reviewed-by: Austin Clements <austin@google.com>
src/debug/dwarf/entry.go
src/debug/dwarf/type.go
src/debug/dwarf/typeunit.go

index 1915d78dc90ec42b208fc65a3838cbaa7a6f3e44..a94be32a21c37a7001bfbec49bcbbb3599271ecb 100644 (file)
@@ -522,6 +522,12 @@ func (d *Data) Reader() *Reader {
        return r
 }
 
+// AddressSize returns the size in bytes of addresses in the current compilation
+// unit.
+func (r *Reader) AddressSize() int {
+       return r.d.unit[r.unit].asize
+}
+
 // Seek positions the Reader at offset off in the encoded entry stream.
 // Offset 0 can be used to denote the first entry.
 func (r *Reader) Seek(off Offset) {
@@ -541,6 +547,7 @@ func (r *Reader) Seek(off Offset) {
        i := d.offsetToUnit(off)
        if i == -1 {
                r.err = errors.New("offset out of range")
+               return
        }
        u := &d.unit[i]
        r.unit = i
index 6986b19e7221bb4043e2ea7cc819b81f00f0011b..a5daa1d0bb18e6e48b640ef5c4e87568a5f1709c 100644 (file)
@@ -268,6 +268,9 @@ type typeReader interface {
        Next() (*Entry, error)
        clone() typeReader
        offset() Offset
+       // AddressSize returns the size in bytes of addresses in the current
+       // compilation unit.
+       AddressSize() int
 }
 
 // Type reads the type at off in the DWARF ``info'' section.
@@ -286,6 +289,7 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
        if err != nil {
                return nil, err
        }
+       addressSize := r.AddressSize()
        if e == nil || e.Offset != off {
                return nil, DecodeError{name, off, "no type at offset"}
        }
@@ -668,6 +672,12 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
                b, ok := e.Val(AttrByteSize).(int64)
                if !ok {
                        b = -1
+                       switch t := typ.(type) {
+                       case *TypedefType:
+                               b = t.Type.Size()
+                       case *PtrType:
+                               b = int64(addressSize)
+                       }
                }
                typ.Common().ByteSize = b
        }
index 98a46857fa5f2dfa7f0d49d6bd198a325dfe5084..9cfb4a8b256d312da316f6132d4684d3ca849e35 100644 (file)
@@ -129,6 +129,11 @@ func (tur *typeUnitReader) Seek(off Offset) {
        tur.b = makeBuf(tur.d, tur.tu, tur.tu.name, off, tur.tu.data[doff:])
 }
 
+// AddressSize returns the size in bytes of addresses in the current type unit.
+func (tur *typeUnitReader) AddressSize() int {
+       return tur.tu.unit.asize
+}
+
 // Next reads the next Entry from the type unit.
 func (tur *typeUnitReader) Next() (*Entry, error) {
        if tur.err != nil {