OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [debug/] [dwarf/] [open.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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 provides access to DWARF debugging information loaded from
6
// executable files, as defined in the DWARF 2.0 Standard at
7
// http://dwarfstd.org/doc/dwarf-2.0.0.pdf
8
package dwarf
9
 
10
import "encoding/binary"
11
 
12
// Data represents the DWARF debugging information
13
// loaded from an executable file (for example, an ELF or Mach-O executable).
14
type Data struct {
15
        // raw data
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
        // parsed data
26
        abbrevCache map[uint32]abbrevTable
27
        addrsize    int
28
        order       binary.ByteOrder
29
        typeCache   map[Offset]Type
30
        unit        []unit
31
}
32
 
33
// New returns a new Data object initialized from the given parameters.
34
// Clients should typically use [TODO(rsc): method to be named later] instead of calling
35
// New directly.
36
//
37
// The []byte arguments are the data from the corresponding debug section
38
// in the object file; for example, for an ELF object, abbrev is the contents of
39
// the ".debug_abbrev" section.
40
func New(abbrev, aranges, frame, info, line, pubnames, ranges, str []byte) (*Data, error) {
41
        d := &Data{
42
                abbrev:      abbrev,
43
                aranges:     aranges,
44
                frame:       frame,
45
                info:        info,
46
                line:        line,
47
                pubnames:    pubnames,
48
                ranges:      ranges,
49
                str:         str,
50
                abbrevCache: make(map[uint32]abbrevTable),
51
                typeCache:   make(map[Offset]Type),
52
        }
53
 
54
        // Sniff .debug_info to figure out byte order.
55
        // bytes 4:6 are the version, a tiny 16-bit number (1, 2, 3).
56
        if len(d.info) < 6 {
57
                return nil, DecodeError{"info", Offset(len(d.info)), "too short"}
58
        }
59
        x, y := d.info[4], d.info[5]
60
        switch {
61
        case x == 0 && y == 0:
62
                return nil, DecodeError{"info", 4, "unsupported version 0"}
63
        case x == 0:
64
                d.order = binary.BigEndian
65
        case y == 0:
66
                d.order = binary.LittleEndian
67
        default:
68
                return nil, DecodeError{"info", 4, "cannot determine byte order"}
69
        }
70
 
71
        u, err := d.parseUnits()
72
        if err != nil {
73
                return nil, err
74
        }
75
        d.unit = u
76
        return d, nil
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.