The Go Programming Language

Source file src/pkg/debug/dwarf/unit.go

     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 (
     8		"os"
     9		"strconv"
    10	)
    11	
    12	// DWARF debug info is split into a sequence of compilation units.
    13	// Each unit has its own abbreviation table and address size.
    14	
    15	type unit struct {
    16		base     Offset // byte offset of header within the aggregate info
    17		off      Offset // byte offset of data within the aggregate info
    18		data     []byte
    19		atable   abbrevTable
    20		addrsize int
    21	}
    22	
    23	func (d *Data) parseUnits() ([]unit, os.Error) {
    24		// Count units.
    25		nunit := 0
    26		b := makeBuf(d, "info", 0, d.info, 0)
    27		for len(b.data) > 0 {
    28			b.skip(int(b.uint32()))
    29			nunit++
    30		}
    31		if b.err != nil {
    32			return nil, b.err
    33		}
    34	
    35		// Again, this time writing them down.
    36		b = makeBuf(d, "info", 0, d.info, 0)
    37		units := make([]unit, nunit)
    38		for i := range units {
    39			u := &units[i]
    40			u.base = b.off
    41			n := b.uint32()
    42			if vers := b.uint16(); vers != 2 {
    43				b.error("unsupported DWARF version " + strconv.Itoa(int(vers)))
    44				break
    45			}
    46			atable, err := d.parseAbbrev(b.uint32())
    47			if err != nil {
    48				if b.err == nil {
    49					b.err = err
    50				}
    51				break
    52			}
    53			u.atable = atable
    54			u.addrsize = int(b.uint8())
    55			u.off = b.off
    56			u.data = b.bytes(int(n - (2 + 4 + 1)))
    57		}
    58		if b.err != nil {
    59			return nil, b.err
    60		}
    61		return units, nil
    62	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.