shotizam: Index | Files

package gosym

import ""

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


This is a fork of the Go standard library's debug/gosym package, with some stuff added for use by Shotizam.


Package Files


type DecodingError Uses

type DecodingError struct {
    // contains filtered or unexported fields

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

func (*DecodingError) Error Uses

func (e *DecodingError) Error() string

type Func Uses

type Func struct {
    Entry uint64
    End       uint64
    LineTable *LineTable
    Obj       *Obj

    OffFixedFunc uint64

    ArgSize     int    // in/out args size
    DeferReturn int    // offset of start of a deferreturn call instruction from entry, if any.
    OffPCSP     uint32 // pcsp table (offset from pcvalue table)
    OffPCFile   uint32 // pcfile table (offset from pcvalue table)
    OffPCLn     uint32 // pcln table (offset from pcvalue table)
    NumPCData   int    // number of entries in pcdata list
    NumFuncData int    // number of entries in funcdata list
    FuncID      int    // special runtime func ID (for some runtime funcs)
    // contains filtered or unexported fields

A Func collects information about a single function.

func (*Func) ForeachTableEntry Uses

func (f *Func) ForeachTableEntry(off uint32, fn func(val int64, valBytes int, pc uint64, pcBytes int))

func (*Func) TableSizePCData Uses

func (f *Func) TableSizePCData(tab int) int

tab is 0-based table number.

func (*Func) TableSizePCFile Uses

func (f *Func) TableSizePCFile() int

func (*Func) TableSizePCLn Uses

func (f *Func) TableSizePCLn() int

func (*Func) TableSizePCSP Uses

func (f *Func) TableSizePCSP() int

type LineTable Uses

type LineTable struct {
    Data []byte
    PC   uint64
    // contains filtered or unexported fields

A LineTable is a data structure mapping program counters to line numbers.

In Go 1.1 and earlier, each function (represented by a Func) had its own LineTable, and the line number corresponded to a numbering of all source lines in the program, across all files. That absolute line number would then have to be converted separately to a file name and line number within the file.

In Go 1.2, the format of the data changed so that there is a single LineTable for the entire program, shared by all Funcs, and there are no absolute line numbers, just line numbers within specific files.

For the most part, LineTable's methods should be treated as an internal detail of the package; callers should use the methods on Table instead.

func (*LineTable) File Uses

func (t *LineTable) File(n int) string

File returns filename at index n in the file table.

func (*LineTable) PCToLine Uses

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

PCToLine returns the line number for the given program counter.

Deprecated: Use Table's PCToLine method instead.

func (*LineTable) String Uses

func (t *LineTable) String() string

func (*LineTable) StringAtOffset Uses

func (t *LineTable) StringAtOffset(off uint32) string

func (*LineTable) Uint32AtOffset Uses

func (t *LineTable) Uint32AtOffset(off uint32) uint32

type Obj Uses

type Obj struct {
    // Funcs is a list of functions in the Obj.
    Funcs []Func

An Obj represents a collection of functions in a symbol table.

The exact method of division of a binary into separate Objs is an internal detail of the symbol table format.

In early versions of Go each source file became a different Obj.

In Go 1 and Go 1.1, each package produced one Obj for all Go sources and one Obj per C source file.

In Go 1.2, there is a single Obj for the entire program.

type Sym Uses

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

A Sym represents a single symbol table entry.

func (*Sym) BaseName Uses

func (s *Sym) BaseName() string

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

func (*Sym) PackageName Uses

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 Uses

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 Uses

func (s *Sym) Static() bool

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

type Table Uses

type Table struct {
    Funcs []Func
    Files map[string]*Obj // nil for Go 1.2 and later binaries
    Objs  []Obj           // nil for Go 1.2 and later binaries
    // contains filtered or unexported fields

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.

func NewTable Uses

func NewTable(data []byte, text uint64) (*Table, error)

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

func (*Table) LineToPC Uses

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

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

func (*Table) LookupFunc Uses

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) PCToFunc Uses

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 Uses

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) PtrSize Uses

func (t *Table) PtrSize() int

type UnknownFileError Uses

type UnknownFileError string

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

func (UnknownFileError) Error Uses

func (e UnknownFileError) Error() string

type UnknownLineError Uses

type UnknownLineError struct {
    File string
    Line int

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.

func (*UnknownLineError) Error Uses

func (e *UnknownLineError) Error() string

Package gosym imports 8 packages (graph) and is imported by 1 packages. Updated 2020-07-29. Refresh now. Tools for package owners.