...
Source file src/pkg/debug/dwarf/open.go
1
2
3
4
5
6
7
8 package dwarf
9
10 import "encoding/binary"
11
12
13
14 type Data struct {
15
16 abbrev []byte
17 aranges []byte
18 frame []byte
19 info []byte
20 line []byte
21 pubnames []byte
22 ranges []byte
23 str []byte
24
25
26 abbrevCache map[uint64]abbrevTable
27 order binary.ByteOrder
28 typeCache map[Offset]Type
29 typeSigs map[uint64]*typeUnit
30 unit []unit
31 }
32
33
34
35
36
37
38
39
40
41 func New(abbrev, aranges, frame, info, line, pubnames, ranges, str []byte) (*Data, error) {
42 d := &Data{
43 abbrev: abbrev,
44 aranges: aranges,
45 frame: frame,
46 info: info,
47 line: line,
48 pubnames: pubnames,
49 ranges: ranges,
50 str: str,
51 abbrevCache: make(map[uint64]abbrevTable),
52 typeCache: make(map[Offset]Type),
53 typeSigs: make(map[uint64]*typeUnit),
54 }
55
56
57
58
59 if len(d.info) < 6 {
60 return nil, DecodeError{"info", Offset(len(d.info)), "too short"}
61 }
62 offset := 4
63 if d.info[0] == 0xff && d.info[1] == 0xff && d.info[2] == 0xff && d.info[3] == 0xff {
64 if len(d.info) < 14 {
65 return nil, DecodeError{"info", Offset(len(d.info)), "too short"}
66 }
67 offset = 12
68 }
69
70 x, y := d.info[offset], d.info[offset+1]
71 switch {
72 case x == 0 && y == 0:
73 return nil, DecodeError{"info", 4, "unsupported version 0"}
74 case x == 0:
75 d.order = binary.BigEndian
76 case y == 0:
77 d.order = binary.LittleEndian
78 default:
79 return nil, DecodeError{"info", 4, "cannot determine byte order"}
80 }
81
82 u, err := d.parseUnits()
83 if err != nil {
84 return nil, err
85 }
86 d.unit = u
87 return d, nil
88 }
89
90
91
92
93
94 func (d *Data) AddTypes(name string, types []byte) error {
95 return d.parseTypes(name, types)
96 }
97
View as plain text