github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/gofrontend/libgo/go/debug/dwarf/unit.go (about) 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. 4 5 package dwarf 6 7 import "strconv" 8 9 // DWARF debug info is split into a sequence of compilation units. 10 // Each unit has its own abbreviation table and address size. 11 12 type unit struct { 13 base Offset // byte offset of header within the aggregate info 14 off Offset // byte offset of data within the aggregate info 15 lineoff Offset // byte offset of data within the line info 16 data []byte 17 atable abbrevTable 18 asize int 19 vers int 20 is64 bool // True for 64-bit DWARF format 21 dir string 22 pc []addrRange // PC ranges in this compilation unit 23 lines []mapLineInfo // PC -> line mapping 24 } 25 26 // Implement the dataFormat interface. 27 28 func (u *unit) version() int { 29 return u.vers 30 } 31 32 func (u *unit) dwarf64() (bool, bool) { 33 return u.is64, true 34 } 35 36 func (u *unit) addrsize() int { 37 return u.asize 38 } 39 40 // A range is an address range. 41 type addrRange struct { 42 low uint64 43 high uint64 44 } 45 46 func (d *Data) parseUnits() ([]unit, error) { 47 // Count units. 48 nunit := 0 49 b := makeBuf(d, unknownFormat{}, "info", 0, d.info) 50 for len(b.data) > 0 { 51 len := b.uint32() 52 if len == 0xffffffff { 53 len64 := b.uint64() 54 if len64 != uint64(uint32(len64)) { 55 b.error("unit length overflow") 56 break 57 } 58 len = uint32(len64) 59 } 60 b.skip(int(len)) 61 nunit++ 62 } 63 if b.err != nil { 64 return nil, b.err 65 } 66 67 // Again, this time writing them down. 68 b = makeBuf(d, unknownFormat{}, "info", 0, d.info) 69 units := make([]unit, nunit) 70 for i := range units { 71 u := &units[i] 72 u.base = b.off 73 n := b.uint32() 74 if n == 0xffffffff { 75 u.is64 = true 76 n = uint32(b.uint64()) 77 } 78 vers := b.uint16() 79 if vers != 2 && vers != 3 && vers != 4 { 80 b.error("unsupported DWARF version " + strconv.Itoa(int(vers))) 81 break 82 } 83 u.vers = int(vers) 84 atable, err := d.parseAbbrev(b.uint32()) 85 if err != nil { 86 if b.err == nil { 87 b.err = err 88 } 89 break 90 } 91 u.atable = atable 92 u.asize = int(b.uint8()) 93 u.off = b.off 94 u.data = b.bytes(int(n - (2 + 4 + 1))) 95 } 96 if b.err != nil { 97 return nil, b.err 98 } 99 return units, nil 100 }