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.
12 // DWARF debug info is split into a sequence of compilation units.
13 // Each unit has its own abbreviation table and address size.
16 base Offset
// byte offset of header within the aggregate info
17 off Offset
// byte offset of data within the aggregate info
22 is64
bool // True for 64-bit DWARF format
25 // Implement the dataFormat interface.
27 func (u
*unit
) version() int {
31 func (u
*unit
) dwarf64() (bool, bool) {
35 func (u
*unit
) addrsize() int {
39 func (d
*Data
) parseUnits() ([]unit
, error
) {
42 b
:= makeBuf(d
, unknownFormat
{}, "info", 0, d
.info
)
44 len, _
:= b
.unitLength()
45 if len != Offset(uint32(len)) {
46 b
.error("unit length overflow")
56 // Again, this time writing them down.
57 b
= makeBuf(d
, unknownFormat
{}, "info", 0, d
.info
)
58 units
:= make([]unit
, nunit
)
59 for i
:= range units
{
63 n
, u
.is64
= b
.unitLength()
66 if vers
!= 2 && vers
!= 3 && vers
!= 4 {
67 b
.error("unsupported DWARF version " + strconv
.Itoa(int(vers
)))
73 abbrevOff
= b
.uint64()
75 abbrevOff
= uint64(b
.uint32())
77 atable
, err
:= d
.parseAbbrev(abbrevOff
, u
.vers
)
85 u
.asize
= int(b
.uint8())
87 u
.data
= b
.bytes(int(n
- (b
.off
- dataOff
)))
95 // offsetToUnit returns the index of the unit containing offset off.
96 // It returns -1 if no unit contains this offset.
97 func (d
*Data
) offsetToUnit(off Offset
) int {
98 // Find the unit after off
99 next
:= sort
.Search(len(d
.unit
), func(i
int) bool {
100 return d
.unit
[i
].off
> off
106 if u
.off
<= off
&& off
< u
.off
+Offset(len(u
.data
)) {