Overview

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

Index

symtab.go

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

func (*DecodingError)

  1. func (e *) Error() string

type

  1. type Func struct {
  2. Entry
  3. *Sym
  4. End
  5. Params []*Sym // nil for Go 1.3 and later binaries
  6. Locals []* // nil for Go 1.3 and later binaries
  7. FrameSize int
  8. LineTable *
  9. Obj *Obj
  10. }

A Func collects information about a single function.

type

  1. type LineTable struct {
  2. Data []
  3. PC uint64
  4. Line
  5. // contains filtered or unexported fields
  6. }

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 NewLineTable

  1. func NewLineTable(data []byte, text ) *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)

  1. func (t *) LineToPC(line int, maxpc ) uint64

LineToPC returns the program counter for the given line number, considering only
program counters before maxpc. Callers should use Table’s LineToPC method
instead.

func (*LineTable)

  1. func (t *) PCToLine(pc uint64)

PCToLine returns the line number for the given program counter. Callers should
use Table’s PCToLine method instead.

  1. type Obj struct {
  2. // Funcs is a list of functions in the Obj.
  3. Funcs []Func
  4.  
  5. // In Go 1.1 and earlier, Paths is a list of symbols corresponding
  6. // In Go 1.2, Paths is nil.
  7. // Use the keys of Table.Files to obtain a list of source files.
  8. Paths [] // meta
  9. }

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

A Sym represents a single symbol table entry.

func (*Sym) BaseName

  1. func (s *Sym) BaseName()

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

  1. func (s *Sym) PackageName()

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

func (*Sym) ReceiverName

  1. func (s *Sym) ReceiverName()

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

func (*Sym) Static

  1. func (s *Sym) Static()

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

type Table

  1. type Table struct {
  2. Syms []Sym // nil for Go 1.3 and later binaries
  3. Funcs []
  4. Files map[string]* // nil for Go 1.2 and later binaries
  5. Objs []Obj // nil for Go 1.2 and later binaries
  6. // contains filtered or unexported fields
  7. }

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

  1. func NewTable(symtab [], pcln *LineTable) (*, error)

func (*Table)

  1. func (t *) LineToPC(file string, line ) (pc uint64, fn *, 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 returns the text, data, or bss symbol with the given name, or nil if
no such symbol is found.

  1. func (t *) LookupSym(name string) *

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

func (*Table) PCToFunc

  1. func (t *Table) PCToFunc(pc ) *Func

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

func (*Table)

  1. func (t *) PCToLine(pc uint64) (file , line int, fn *)

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

func (*Table) SymByAddr

  1. func (t *Table) SymByAddr(addr ) *Sym

SymByAddr returns the text, data, or bss symbol starting at the given address.

  1. type UnknownFileError

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

func (UnknownFileError) Error

  1. func (e UnknownFileError) Error()

type UnknownLineError

  1. type UnknownLineError struct {
  2. File string
  3. Line

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