The Go Programming Language

Package gosym

import "debug/gosym"

Package gosym implements access to the Go symbol and line number tables embedded in Go binaries generated by the gc compilers.

Package files

pclntab.go symtab.go

type DecodingError

DecodingError represents an error during the decoding of the symbol table.

type DecodingError struct {
    // contains filtered or unexported fields
}

func (*DecodingError) String

func (e *DecodingError) String() string

type Func

A Func collects information about a single function.

type Func struct {
    Entry uint64
    *Sym
    End       uint64
    Params    []*Sym
    Locals    []*Sym
    FrameSize int
    LineTable *LineTable
    Obj       *Obj
}

type LineTable

type LineTable struct {
    Data []byte
    PC   uint64
    Line int
}

func NewLineTable

func NewLineTable(data []byte, text uint64) *LineTable

NewLineTable returns a new PC/line table corresponding to the encoded data. Text must be the start address of the corresponding text segment.

func (*LineTable) LineToPC

func (t *LineTable) LineToPC(line int, maxpc uint64) uint64

func (*LineTable) PCToLine

func (t *LineTable) PCToLine(pc uint64) int

type Obj

An Obj represents a single object file.

type Obj struct {
    Funcs []Func
    Paths []Sym
}

type Sym

A Sym represents a single symbol table entry.

type Sym struct {
    Value  uint64
    Type   byte
    Name   string
    GoType uint64
    // If this symbol if a function symbol, the corresponding Func
    Func *Func
}

func (*Sym) BaseName

func (s *Sym) BaseName() string

BaseName returns the symbol name without the package or receiver name.

func (*Sym) PackageName

func (s *Sym) PackageName() string

PackageName returns the package part of the symbol name, or the empty string if there is none.

func (*Sym) ReceiverName

func (s *Sym) ReceiverName() string

ReceiverName returns the receiver type name of this symbol, or the empty string if there is none.

func (*Sym) Static

func (s *Sym) Static() bool

Static returns whether this symbol is static (not visible outside its file).

type Table

Table represents a Go symbol table. It stores all of the symbols decoded from the program and provides methods to translate between symbols, names, and addresses.

type Table struct {
    Syms  []Sym
    Funcs []Func
    Files map[string]*Obj
    Objs  []Obj
}

func NewTable

func NewTable(symtab []byte, pcln *LineTable) (*Table, os.Error)

NewTable decodes the Go symbol table in data, returning an in-memory representation.

func (*Table) LineToPC

func (t *Table) LineToPC(file string, line int) (pc uint64, fn *Func, err os.Error)

LineToPC looks up the first program counter on the given line in the named file. Returns UnknownPathError or UnknownLineError if there is an error looking up this line.

func (*Table) LookupFunc

func (t *Table) LookupFunc(name string) *Func

LookupFunc returns the text, data, or bss symbol with the given name, or nil if no such symbol is found.

func (*Table) LookupSym

func (t *Table) LookupSym(name string) *Sym

LookupSym returns the text, data, or bss symbol with the given name, or nil if no such symbol is found.

func (*Table) PCToFunc

func (t *Table) PCToFunc(pc uint64) *Func

PCToFunc returns the function containing the program counter pc, or nil if there is no such function.

func (*Table) PCToLine

func (t *Table) PCToLine(pc uint64) (file string, line int, fn *Func)

PCToLine looks up line number information for a program counter. If there is no information, it returns fn == nil.

func (*Table) SymByAddr

func (t *Table) SymByAddr(addr uint64) *Sym

SymByAddr returns the text, data, or bss symbol starting at the given address. TODO(rsc): Allow lookup by any address within the symbol.

type UnknownFileError

UnknownFileError represents a failure to find the specific file in the symbol table.

type UnknownFileError string

func (UnknownFileError) String

func (e UnknownFileError) String() string

type UnknownLineError

UnknownLineError represents a failure to map a line to a program counter, either because the line is beyond the bounds of the file or because there is no code on the given line.

type UnknownLineError struct {
    File string
    Line int
}

func (*UnknownLineError) String

func (e *UnknownLineError) String() string

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