1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Buffered reading and decoding of DWARF data streams.
15 // Data buffer being decoded.
18 order binary.ByteOrder
26 func makeBuf(d *Data, name string, off Offset, data []byte, addrsize int) buf {
27 return buf{d, d.order, name, off, data, addrsize, nil}
30 func (b *buf) uint8() uint8 {
41 func (b *buf) bytes(n int) []byte {
52 func (b *buf) skip(n int) { b.bytes(n) }
54 func (b *buf) string() string {
55 for i := 0; i < len(b.data); i++ {
57 s := string(b.data[0:i])
59 b.off += Offset(i + 1)
67 func (b *buf) uint16() uint16 {
72 return b.order.Uint16(a)
75 func (b *buf) uint32() uint32 {
80 return b.order.Uint32(a)
83 func (b *buf) uint64() uint64 {
88 return b.order.Uint64(a)
91 // Read a varint, which is 7 bits per byte, little endian.
92 // the 0x80 bit means read another byte.
93 func (b *buf) varint() (c uint64, bits uint) {
94 for i := 0; i < len(b.data); i++ {
96 c |= uint64(byte&0x7F) << bits
99 b.off += Offset(i + 1)
100 b.data = b.data[i+1:]
107 // Unsigned int is just a varint.
108 func (b *buf) uint() uint64 {
113 // Signed int is a sign-extended varint.
114 func (b *buf) int() int64 {
115 ux, bits := b.varint()
117 if x&(1<<(bits-1)) != 0 {
123 // Address-sized uint.
124 func (b *buf) addr() uint64 {
127 return uint64(b.uint8())
129 return uint64(b.uint16())
131 return uint64(b.uint32())
133 return uint64(b.uint64())
135 b.error("unknown address size")
139 func (b *buf) error(s string) {
142 b.err = DecodeError{b.name, b.off, s}
146 type DecodeError struct {
152 func (e DecodeError) String() string {
153 return "decoding dwarf section " + e.Name + " at offset 0x" + strconv.Itob64(int64(e.Offset), 16) + ": " + e.Error