mirror of https://github.com/golang/go.git
debug/dwarf: expose CU byte order
Currently, dwarf.Reader exposes the current compilation unit's address size, but doesn't expose its byte order. Both are important for decoding many attributes. For example, location descriptions include addresses that are encoded in native form for the CU. This CL exposes the byte order of the compilation unit in the same way we already expose its address size, which makes it possible to decode attributes containing native addresses. Change-Id: I92f156818fe92b049d1dfc1613816bb1689cfadf Reviewed-on: https://go-review.googlesource.com/c/go/+/192698 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
582d5194fa
commit
bc40294d47
|
|
@ -11,6 +11,7 @@
|
|||
package dwarf
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"strconv"
|
||||
)
|
||||
|
|
@ -735,6 +736,11 @@ func (r *Reader) AddressSize() int {
|
|||
return r.d.unit[r.unit].asize
|
||||
}
|
||||
|
||||
// ByteOrder returns the byte order in the current compilation unit.
|
||||
func (r *Reader) ByteOrder() binary.ByteOrder {
|
||||
return r.b.order
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package dwarf_test
|
|||
|
||||
import (
|
||||
. "debug/dwarf"
|
||||
"encoding/binary"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -141,8 +142,10 @@ func Test64Bit(t *testing.T) {
|
|||
// compilation unit except by using XCOFF, so this is
|
||||
// hand-written.
|
||||
tests := []struct {
|
||||
name string
|
||||
info []byte
|
||||
name string
|
||||
info []byte
|
||||
addrSize int
|
||||
byteOrder binary.ByteOrder
|
||||
}{
|
||||
{
|
||||
"32-bit little",
|
||||
|
|
@ -157,6 +160,7 @@ func Test64Bit(t *testing.T) {
|
|||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
},
|
||||
8, binary.LittleEndian,
|
||||
},
|
||||
{
|
||||
"64-bit little",
|
||||
|
|
@ -171,6 +175,7 @@ func Test64Bit(t *testing.T) {
|
|||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
},
|
||||
8, binary.LittleEndian,
|
||||
},
|
||||
{
|
||||
"64-bit big",
|
||||
|
|
@ -185,13 +190,22 @@ func Test64Bit(t *testing.T) {
|
|||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
},
|
||||
8, binary.BigEndian,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
_, err := New(nil, nil, nil, test.info, nil, nil, nil, nil)
|
||||
data, err := New(nil, nil, nil, test.info, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", test.name, err)
|
||||
}
|
||||
|
||||
r := data.Reader()
|
||||
if r.AddressSize() != test.addrSize {
|
||||
t.Errorf("%s: got address size %d, want %d", test.name, r.AddressSize(), test.addrSize)
|
||||
}
|
||||
if r.ByteOrder() != test.byteOrder {
|
||||
t.Errorf("%s: got byte order %s, want %s", test.name, r.ByteOrder(), test.byteOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue