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 utype
uint8 // DWARF 5 unit type
23 is64
bool // True for 64-bit DWARF format
26 // Implement the dataFormat interface.
28 func (u
*unit
) version() int {
32 func (u
*unit
) dwarf64() (bool, bool) {
36 func (u
*unit
) addrsize() int {
40 func (d
*Data
) parseUnits() ([]unit
, error
) {
43 b
:= makeBuf(d
, unknownFormat
{}, "info", 0, d
.info
)
45 len, _
:= b
.unitLength()
46 if len != Offset(uint32(len)) {
47 b
.error("unit length overflow")
59 // Again, this time writing them down.
60 b
= makeBuf(d
, unknownFormat
{}, "info", 0, d
.info
)
61 units
:= make([]unit
, nunit
)
62 for i
:= range units
{
67 n
, u
.is64
= b
.unitLength()
71 if vers
< 2 || vers
> 5 {
72 b
.error("unsupported DWARF version " + strconv
.Itoa(int(vers
)))
78 u
.asize
= int(b
.uint8())
82 abbrevOff
= b
.uint64()
84 abbrevOff
= uint64(b
.uint32())
86 atable
, err
:= d
.parseAbbrev(abbrevOff
, u
.vers
)
95 u
.asize
= int(b
.uint8())
99 case utSkeleton
, utSplitCompile
:
100 b
.uint64() // unit ID
101 case utType
, utSplitType
:
102 b
.uint64() // type signature
103 if u
.is64
{ // type offset
111 u
.data
= b
.bytes(int(n
- (b
.off
- dataOff
)))
119 // offsetToUnit returns the index of the unit containing offset off.
120 // It returns -1 if no unit contains this offset.
121 func (d
*Data
) offsetToUnit(off Offset
) int {
122 // Find the unit after off
123 next
:= sort
.Search(len(d
.unit
), func(i
int) bool {
124 return d
.unit
[i
].off
> off
130 if u
.off
<= off
&& off
< u
.off
+Offset(len(u
.data
)) {