gosym

Imports

Imports #

"bytes"
"encoding/binary"
"fmt"
"strconv"
"strings"
"bytes"
"encoding/binary"
"sort"
"sync"

Constants & Variables

bigEndianSymtab var #

var bigEndianSymtab = []byte{...}

disableRecover const #

disableRecover causes this package not to swallow panics. This is useful when making changes.

const disableRecover = false

go116magic const #

const go116magic = 0xfffffffa

go118magic const #

const go118magic = 0xfffffff0

go120magic const #

const go120magic = 0xfffffff1

go12magic const #

const go12magic = 0xfffffffb

littleEndianSymtab var #

var littleEndianSymtab = []byte{...}

oldLittleEndianSymtab var #

var oldLittleEndianSymtab = []byte{...}

oldQuantum const #

NOTE(rsc): This is wrong for GOARCH=arm, which uses a quantum of 4, but we have no idea whether we're using arm or not. This only matters in the old (pre-Go 1.2) symbol table format, so it's not worth fixing.

const oldQuantum = 1

ver11 const #

const ver11

ver116 const #

const ver116

ver118 const #

const ver118

ver12 const #

const ver12

ver120 const #

const ver120

verUnknown const #

const verUnknown version = iota

Type Aliases

UnknownFileError type #

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

type UnknownFileError string

version type #

version of the pclntab

type version int

Structs

DecodingError struct #

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

type DecodingError struct {
off int
msg string
val any
}

Func struct #

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
}

LineTable struct #

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.

type LineTable struct {
Data []byte
PC uint64
Line int
mu sync.Mutex
version version
binary binary.ByteOrder
quantum uint32
ptrsize uint32
textStart uint64
funcnametab []byte
cutab []byte
funcdata []byte
functab []byte
nfunctab uint32
filetab []byte
pctab []byte
nfiletab uint32
funcNames map[uint32]string
strings map[uint32]string
fileMap map[string]uint32
}

Obj struct #

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 Obj struct {
Funcs []Func
Paths []Sym
}

Sym struct #

A Sym represents a single symbol table entry.

type Sym struct {
Value uint64
Type byte
Name string
GoType uint64
Func *Func
goVersion version
}

Table struct #

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
go12line *LineTable
}

UnknownLineError struct #

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
}

funcData struct #

funcData is memory corresponding to an _func struct.

type funcData struct {
t *LineTable
data []byte
}

funcTab struct #

funcTab is memory corresponding to a slice of functab structs, followed by an invalid PC. A functab struct is a PC and a func offset.

type funcTab struct {
*LineTable
sz int
}

sym struct #

type sym struct {
value uint64
gotype uint64
typ byte
name []byte
}

Functions

BaseName method #

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

func (s *Sym) BaseName() string

Count method #

Count returns the number of func entries in f.

func (f funcTab) Count() int

Error method #

func (e *DecodingError) Error() string

Error method #

func (e *UnknownLineError) Error() string

Error method #

func (e UnknownFileError) Error() string

IsZero method #

IsZero reports whether f is the zero value.

func (f funcData) IsZero() bool

LineToPC method #

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

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

LineToPC method #

LineToPC returns the program counter for the given line number, considering only program counters before maxpc. Deprecated: Use Table's LineToPC method instead.

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

LookupFunc method #

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

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

LookupSym method #

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

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

NewLineTable function #

NewLineTable returns a new PC/line table corresponding to the encoded data. Text must be the start address of the corresponding text segment, with the exact value stored in the 'runtime.text' symbol. This value may differ from the start address of the text segment if binary was built with cgo enabled.

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

NewTable function #

NewTable decodes the Go symbol table (the ".gosymtab" section in ELF), returning an in-memory representation. Starting with Go 1.3, the Go symbol table no longer includes symbol data.

func NewTable(symtab []byte, pcln *LineTable) (*Table, error)

PCToFunc method #

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

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

PCToLine method #

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

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

PCToLine method #

PCToLine returns the line number for the given program counter. Deprecated: Use Table's PCToLine method instead.

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

PackageName method #

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

func (s *Sym) PackageName() string

ReceiverName method #

ReceiverName returns the receiver type name of this symbol, or the empty string if there is none. A receiver name is only detected in the case that s.Name is fully-specified with a package name.

func (s *Sym) ReceiverName() string

Static method #

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

func (s *Sym) Static() bool

SymByAddr method #

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

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

alineFromLine method #

func (o *Obj) alineFromLine(path string, line int) (int, error)

cuOffset method #

func (f funcData) cuOffset() uint32

deferreturn method #

func (f funcData) deferreturn() uint32

entryPC method #

entryPC returns the func's entry PC.

func (f *funcData) entryPC() uint64

field method #

field returns the nth field of the _func struct. It panics if n == 0 or n > 9; for n == 0, call f.entryPC. Most callers should use a named field accessor (just above).

func (f funcData) field(n uint32) uint32

findFileLine method #

findFileLine scans one function in the binary looking for a program counter in the given file on the given line. It does so by running the pc-value tables mapping program counter to file number. Since most functions come from a single file, these are usually short and quick to scan. If a file match is found, then the code goes to the expense of looking for a simultaneous line number match.

func (t *LineTable) findFileLine(entry uint64, filetab uint32, linetab uint32, filenum int32, line int32, cutab []byte) uint64

findFunc method #

findFunc returns the funcData corresponding to the given program counter.

func (t *LineTable) findFunc(pc uint64) funcData

funcData method #

funcData returns the ith funcData in t.functab.

func (t *LineTable) funcData(i uint32) funcData

funcName method #

funcName returns the name of the function found at off.

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

funcOff method #

funcOff returns the funcdata offset of the i'th func in f.

func (f funcTab) funcOff(i int) uint64

funcTab method #

funcTab returns t's funcTab.

func (t *LineTable) funcTab() funcTab

functabFieldSize method #

functabFieldSize returns the size in bytes of a single functab field.

func (t *LineTable) functabFieldSize() int

go12Funcs method #

go12Funcs returns a slice of Funcs derived from the Go 1.2+ pcln table.

func (t *LineTable) go12Funcs() []Func

go12LineToPC method #

go12LineToPC maps a (file, line) pair to a program counter for the Go 1.2+ pcln table.

func (t *LineTable) go12LineToPC(file string, line int) (pc uint64)

go12MapFiles method #

go12MapFiles adds to m a key for every file in the Go 1.2 LineTable. Every key maps to obj. That's not a very interesting map, but it provides a way for callers to obtain the list of files in the program.

func (t *LineTable) go12MapFiles(m map[string]*Obj, obj *Obj)

go12PCToFile method #

go12PCToFile maps program counter to file name for the Go 1.2+ pcln table.

func (t *LineTable) go12PCToFile(pc uint64) (file string)

go12PCToLine method #

go12PCToLine maps program counter to line number for the Go 1.2+ pcln table.

func (t *LineTable) go12PCToLine(pc uint64) (line int)

initFileMap method #

initFileMap initializes the map from file name to file number.

func (t *LineTable) initFileMap()

isGo12 method #

isGo12 reports whether this is a Go 1.2 (or later) symbol table.

func (t *LineTable) isGo12() bool

lineFromAline method #

func (o *Obj) lineFromAline(aline int) (string, int)

nameOff method #

func (f funcData) nameOff() uint32

nameWithoutInst method #

nameWithoutInst returns s.Name if s.Name has no brackets (does not reference an instantiated type, function, or method). If s.Name contains brackets, then it returns s.Name with all the contents between (and including) the outermost left and right bracket removed. This is useful to ignore any extra slashes or dots inside the brackets from the string searches below, where needed.

func (s *Sym) nameWithoutInst() string

parse method #

func (t *LineTable) parse(targetPC uint64, targetLine int) (b []byte, pc uint64, line int)

parsePclnTab method #

parsePclnTab parses the pclntab, setting the version.

func (t *LineTable) parsePclnTab()

pc method #

pc returns the PC of the i'th func in f.

func (f funcTab) pc(i int) uint64

pcfile method #

func (f funcData) pcfile() uint32

pcln method #

func (f funcData) pcln() uint32

pcvalue method #

pcvalue reports the value associated with the target pc. off is the offset to the beginning of the pc-value table, and entry is the start PC for the corresponding function.

func (t *LineTable) pcvalue(off uint32, entry uint64, targetpc uint64) int32

readvarint method #

readvarint reads, removes, and returns a varint from *pp.

func (t *LineTable) readvarint(pp *[]byte) uint32

slice method #

func (t *LineTable) slice(pc uint64) *LineTable

step method #

step advances to the next pc, value pair in the encoded table.

func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool

string method #

string returns a Go string found at off.

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

stringFrom method #

stringFrom returns a Go string found at off from a position.

func (t *LineTable) stringFrom(arr []byte, off uint32) string

uint method #

uint returns the uint stored at b.

func (f funcTab) uint(b []byte) uint64

uintptr method #

uintptr returns the pointer-sized value encoded at b. The pointer size is dictated by the table being read.

func (t *LineTable) uintptr(b []byte) uint64

walksymtab function #

func walksymtab(data []byte, fn func(sym) error) error

Generated with Arrow