mirror of
https://github.com/golang/go
synced 2024-11-05 14:46:11 -07:00
debug/dwarf: compute ByteSize for more DWARF types
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>
This commit is contained in:
parent
c3559f1621
commit
d0a05f51f9
@ -522,6 +522,12 @@ func (d *Data) Reader() *Reader {
|
|||||||
return r
|
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.
|
// Seek positions the Reader at offset off in the encoded entry stream.
|
||||||
// Offset 0 can be used to denote the first entry.
|
// Offset 0 can be used to denote the first entry.
|
||||||
func (r *Reader) Seek(off Offset) {
|
func (r *Reader) Seek(off Offset) {
|
||||||
@ -541,6 +547,7 @@ func (r *Reader) Seek(off Offset) {
|
|||||||
i := d.offsetToUnit(off)
|
i := d.offsetToUnit(off)
|
||||||
if i == -1 {
|
if i == -1 {
|
||||||
r.err = errors.New("offset out of range")
|
r.err = errors.New("offset out of range")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
u := &d.unit[i]
|
u := &d.unit[i]
|
||||||
r.unit = i
|
r.unit = i
|
||||||
|
@ -268,6 +268,9 @@ type typeReader interface {
|
|||||||
Next() (*Entry, error)
|
Next() (*Entry, error)
|
||||||
clone() typeReader
|
clone() typeReader
|
||||||
offset() Offset
|
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.
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
addressSize := r.AddressSize()
|
||||||
if e == nil || e.Offset != off {
|
if e == nil || e.Offset != off {
|
||||||
return nil, DecodeError{name, off, "no type at offset"}
|
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)
|
b, ok := e.Val(AttrByteSize).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
b = -1
|
b = -1
|
||||||
|
switch t := typ.(type) {
|
||||||
|
case *TypedefType:
|
||||||
|
b = t.Type.Size()
|
||||||
|
case *PtrType:
|
||||||
|
b = int64(addressSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
typ.Common().ByteSize = b
|
typ.Common().ByteSize = b
|
||||||
}
|
}
|
||||||
|
@ -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:])
|
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.
|
// Next reads the next Entry from the type unit.
|
||||||
func (tur *typeUnitReader) Next() (*Entry, error) {
|
func (tur *typeUnitReader) Next() (*Entry, error) {
|
||||||
if tur.err != nil {
|
if tur.err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user